Exemplo n.º 1
0
        private bool CheckLocalConstraint(RoadSegment segment)
        {
            foreach (RoadSegment road in segments)
            {
                //If the new segment end is close to another segments Node, Fix it's end to it
                if (IsClose(segment.NodeTo, road.NodeTo))
                {
                    segment.NodeTo     = road.NodeTo;
                    segment.EndSegment = true;
                }

                if (segment.IsCrossing(road))
                {
                    return(false);                          //Check if segment is crossing an other road
                }
            }

            //Check if segment is out of border
            if (segment.NodeFrom.X > border || segment.NodeFrom.X < -border ||
                segment.NodeFrom.Y > border || segment.NodeFrom.Y < -border)
            {
                return(false);
            }

            //Check if segment would come into itself
            if (segment.NodeFrom.X == segment.NodeTo.X && segment.NodeFrom.Y == segment.NodeTo.Y)
            {
                return(false);
            }

            //nodeTo or nodeFrom has more than 4 edges
            if (segment.NodeTo.Edges.Count >= 4 || segment.NodeFrom.Edges.Count >= 4)
            {
                return(false);
            }

            foreach (Edge edge in segment.NodeTo.Edges)
            {
                //NodeTo already connected to NodeFrom
                if (edge.NodeA == segment.NodeFrom || edge.NodeB == segment.NodeFrom)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private bool CheckLocalConstraint(RoadSegment segment)
        {
            //TRANSFORMATION
            bool stretched = false;

            foreach (RoadSegment road in hwSegments) //first check majorNodes
            {
                if (IsClose(segment.NodeTo, road.NodeTo))
                {
                    segment.NodeTo     = road.NodeTo;
                    segment.EndSegment = true;
                    stretched          = true;
                    break;
                }
            }

            if (!stretched)
            {
                foreach (RoadSegment road in segments) //then check minorNodes
                {
                    if (IsClose(segment.NodeTo, road.NodeTo))
                    {
                        segment.NodeTo     = road.NodeTo;
                        segment.EndSegment = true;
                        break;
                    }
                }
            }

            //CHECKING CROSSING
            foreach (RoadSegment road in hwSegments) //first check majorNodes
            {
                if (segment.IsCrossing(road))
                {
                    return(false);
                }
            }

            foreach (RoadSegment road in segments) //then check minorNodes
            {
                if (segment.IsCrossing(road))
                {
                    return(false);
                }
            }

            //CHECKING OTHER CONSTRAINTS
            //Check if segment is out of border
            if (segment.NodeFrom.X > border || segment.NodeFrom.X < -border ||
                segment.NodeFrom.Y > border || segment.NodeFrom.Y < -border)
            {
                return(false);
            }

            //Check if segment would come into itself
            if (segment.NodeFrom.X == segment.NodeTo.X && segment.NodeFrom.Y == segment.NodeTo.Y)
            {
                return(false);
            }

            //nodeTo or nodeFrom has more than 4 edges
            if (segment.NodeTo.Edges.Count >= 4 || segment.NodeFrom.Edges.Count >= 4)
            {
                return(false);
            }

            if (!segment.NodeFrom.IsFree(
                    Mathf.Atan2(segment.NodeTo.Y - segment.NodeFrom.Y, segment.NodeTo.X - segment.NodeFrom.X)
                    ))
            {
                return(false); //direction is not free from NodeFrom
            }
            if (!segment.NodeTo.IsFree(
                    Mathf.Atan2(segment.NodeFrom.Y - segment.NodeTo.Y, segment.NodeFrom.X - segment.NodeTo.X)
                    ))
            {
                return(false); //direction is not free from NodeTo
            }
            return(true);
        }