Exemple #1
0
        static void Main(string[] args)
        {
            //Point p1 = new Point() { X = 0, Y = 1 };
            //Point p2 = new Point() { X = 1, Y = 0 };
            Point p3 = new Point() { X = 0, Y = -1 };
            Point p4 = new Point() { X = 1, Y = -1 };
            Point p5 = new Point() { X = 2, Y = -1 };
            //Point p6 = new Point() { X = 2, Y = 0 };
            //Point p7 = new Point() { X = 2, Y = 1 };


            //Point p1 = new Point() { X = 0, Y = 1 };
            //Point p2 = new Point() { X = 1, Y = 0 };
            //Point p3 = new Point() { X = 0, Y = -1 };
            //Point p4 = new Point() { X = -1, Y = -1 };
            //Point p5 = new Point() { X = -2, Y = -1 };
            //Point p6 = new Point() { X = -2, Y = 0 };
            //Point p7 = new Point() { X = -2, Y = 1 };
            List<Point> points = new List<Point>();

            //double result = cal(p3, p2, p1);
            //points.Add(p1);
            //points.Add(p2);
            points.Add(p3);
            points.Add(p4);
            points.Add(p5);
            //points.Add(p6);
            //points.Add(p7);
            ClockDirection vDirection = Polygon.CalculateClockDirection(points, false);
            PolygonType type = Polygon.CalculatePolygonType(points, false);
            bool flag = Polygon.IsPolyClockwise(points);

        }
Exemple #2
0
 public GetNodeSegmentIdsEnumerable(ushort nodeId, ushort initialSegmentId, ClockDirection clockDirection, NetSegment[] segmentBuffer)
 {
     this.nodeId           = nodeId;
     this.initialSegmentId = initialSegmentId;
     this.clockDirection   = clockDirection;
     this.segmentBuffer    = segmentBuffer;
 }
Exemple #3
0
 public static Direction rotate(this Direction dir, ClockDirection cd)
 {
     if (cd == ClockDirection.clockwise) {
         switch (dir) {
         case Direction.down:
             return Direction.left;
         case Direction.left:
             return Direction.up;
         case Direction.up:
             return Direction.right;
         case Direction.right:
             return Direction.down;
         default:
             break;
         }
     } else if (cd == ClockDirection.counterclockwise) {
         switch (dir) {
         case Direction.down:
             return Direction.right;
         case Direction.right:
             return Direction.up;
         case Direction.up:
             return Direction.left;
         case Direction.left:
             return Direction.down;
         default:
             break;
         }
     }
     return Direction.none;
 }
Exemple #4
0
//--------------------------------------------------------------------------------------------------
    public bool SearchCircle( 
        Map                 map, 
        int                 radius, 
        ClockDirection      clockDirection,
        Tour                tour 
        )
    {
        SearchSet           ss = m_SearchSets[radius];

        SortedList<double,CircleEntry> entries = ss.Entries;

        if( entries == null ) return false;

        IList<CircleEntry> values;

        if( clockDirection == ClockDirection.Clockwise )
        {
            List<CircleEntry> list = new List<CircleEntry>( entries.Values );
            list.Reverse();
            values = list;
        }
        else 
            values = entries.Values;

        foreach( CircleEntry entry in values )
        {
            if( tour( map, entry.X, entry.Y ) ) return true;
        }

        return false;
    }
Exemple #5
0
 public static bool Circle(
     Map map,
     int radius,
     ClockDirection clockDirection,
     Tour tour
     )
 {
     return(m_CircleSearch.SearchCircle(map, radius, clockDirection, tour));
 }
Exemple #6
0
 public static bool Circle( 
     Map                 map, 
     int                 radius, 
     ClockDirection      clockDirection,
     Tour                tour 
     )
 {
     return m_CircleSearch.SearchCircle( map, radius, clockDirection, tour );
 }
Exemple #7
0
        public GetNodeSegmentIdsEnumerator(ushort nodeId, ushort initialSegmentId, ClockDirection clockDirection, NetSegment[] segmentBuffer)
        {
            this.nodeId         = nodeId;
            this.initialSegment = initialSegmentId;
            this.clockDirection = clockDirection;
            this.segmentBuffer  = segmentBuffer ?? throw new ArgumentNullException(nameof(segmentBuffer));

            this.firstRun         = true;
            this.currentSegmentId = default;
        }
        public void IterateNodeSegments(ushort nodeId, ClockDirection dir, NetSegmentHandler handler)
        {
            NetManager netManager = Singleton <NetManager> .instance;

            ProcessNode(nodeId, delegate(ushort nId, ref NetNode node) {
                if (dir == ClockDirection.None)
                {
                    for (int i = 0; i < 8; ++i)
                    {
                        ushort segmentId = node.GetSegment(i);
                        if (segmentId != 0)
                        {
                            if (!handler(segmentId, ref netManager.m_segments.m_buffer[segmentId]))
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    ushort segmentId = node.GetSegment(0);
                    ushort initSegId = segmentId;

                    while (true)
                    {
                        if (segmentId != 0)
                        {
                            if (!handler(segmentId, ref netManager.m_segments.m_buffer[segmentId]))
                            {
                                break;
                            }
                        }

                        switch (dir)
                        {
                        case ClockDirection.Clockwise:
                        default:
                            segmentId = netManager.m_segments.m_buffer[segmentId].GetLeftSegment(nodeId);
                            break;

                        case ClockDirection.CounterClockwise:
                            segmentId = netManager.m_segments.m_buffer[segmentId].GetRightSegment(nodeId);
                            break;
                        }

                        if (segmentId == initSegId || segmentId == 0)
                        {
                            break;
                        }
                    }
                }
                return(true);
            });
        }
Exemple #9
0
//--------------------------------------------------------------------------------------------------
        public bool SearchConcentricCircles(
            Map map,
            int start,
            ClockDirection clockDirection,
            SearchDirection searchDirection,
            Tour tour
            )
        {
            int incr = (searchDirection == SearchDirection.Outwards ? 1 : -1);

            for (int i = start;; i += incr)
            {
                if (i < 0 || i > m_Radius)
                {
                    return(false);
                }

                SearchSet ss = m_SearchSets[i];

                SortedList <double, CircleEntry> entries = ss.Entries;

                if (entries == null)
                {
                    continue;
                }

                IList <CircleEntry> values;

                if (clockDirection == ClockDirection.Clockwise)
                {
                    List <CircleEntry> list = new List <CircleEntry>(entries.Values);
                    list.Reverse();
                    values = list;
                }
                else
                {
                    values = entries.Values;
                }

                foreach (CircleEntry entry in values)
                {
                    if (tour(map, entry.X, entry.Y))
                    {
                        return(true);
                    }
                }

                return(false);
            }
        }
Exemple #10
0
    /* The next two methods are overrides from IPGameObject. In addition to the
     * base class methods, we save and restore variables specific to this class. */
    public override void SaveCheckpointState()
    {
        base.SaveCheckpointState();

        savedAttachPlayer = attachPlayer;
        savedDirection = direction;
        savedRotationAxis = rotationAxis;
        savedStepDegrees = stepDegrees;
        savedStepDelay = stepDelay;
        savedSpeed = speed;

        savedAxis = axis;
        savedAngle = angle;
        savedDelayed = delayed;
    }
        /// <summary>
        /// creats a sorted list of segmetns connected to nodeId.
        /// roads without outgoing lanes are excluded as they do not need traffic lights
        /// the segments are arranged in a clockwise direction (Counter clock wise for LHT).
        /// </summary>
        /// <param name="nodeId">the junction</param>
        /// <returns>a list of segments aranged in counter clockwise direction.</returns>
        private static List <ushort> ArrangedSegments(ushort nodeId)
        {
            ClockDirection clockDir = RHT ? ClockDirection.Clockwise : ClockDirection.CounterClockwise;
            List <ushort>  segList  = new List <ushort>();

            netService.IterateNodeSegments(
                nodeId,
                clockDir,
                (ushort segId, ref NetSegment _) => {
                if (CountOutgoingLanes(segId, nodeId) > 0)
                {
                    segList.Add(segId);
                }
                return(true);
            });
            ;
            return(segList);
        }
Exemple #12
0
        /// <summary>
        /// creats a sorted list of segmetns connected to nodeId.
        /// roads without outgoing lanes are excluded as they do not need traffic lights
        /// the segments are arranged in a clockwise direction (Counter clock wise for LHT).
        /// </summary>
        /// <param name="nodeId">the junction</param>
        /// <returns>a list of segments aranged in counter clockwise direction.</returns>
        private static List <ushort> ArrangedSegments(ushort nodeId)
        {
            ClockDirection clockDirection = RHT
                ? ClockDirection.Clockwise
                : ClockDirection.CounterClockwise;

            List <ushort> segList = new List <ushort>();

            foreach (var segmentId in netService.GetNodeSegmentIds(nodeId, clockDirection))
            {
                if (CountOutgoingLanes(segmentId, nodeId) > 0)
                {
                    segList.Add(segmentId);
                }
            }

            return(segList);
        }
Exemple #13
0
        /// <summary>
        /// creats a sorted list of segmetns connected to nodeId.
        /// roads without outgoing lanes are excluded as they do not need traffic lights
        /// the segments are arranged in a clockwise direction (Counter clock wise for LHT).
        /// </summary>
        /// <param name="nodeId">the junction</param>
        /// <returns>a list of segments aranged in counter clockwise direction.</returns>
        private static List <ushort> ArrangedSegments(ushort nodeId)
        {
            ClockDirection clockDirection = Shortcuts.LHT
                ? ClockDirection.CounterClockwise
                : ClockDirection.Clockwise;

            List <ushort> segList = new List <ushort>();

            ExtNodeManager extNodeManager = ExtNodeManager.Instance;

            foreach (var segmentId in extNodeManager.GetNodeSegmentIds(nodeId, clockDirection))
            {
                if (CountOutgoingLanes(segmentId, nodeId) > 0)
                {
                    segList.Add(segmentId);
                }
            }

            return(segList);
        }
Exemple #14
0
        private static Direction UpdateDirection(Direction current, int degrees, ClockDirection clockDirection)
        {
            int steps = degrees / 90;
            int cur   = (int)current;

            for (int i = 0; i < steps; i++)
            {
                cur += clockDirection == ClockDirection.Clockwise ? 1 : -1;
                if (cur < 0)
                {
                    cur = 3;
                }
                if (cur > 3)
                {
                    cur = 0;
                }
            }

            return((Direction)(cur));
        }
Exemple #15
0
    public override void RestoreCheckpointState()
    {
        StopCoroutine("WaitForDelay");
        base.RestoreCheckpointState();

        attachPlayer = savedAttachPlayer;
        direction = savedDirection;
        rotationAxis = savedRotationAxis;
        stepDegrees = savedStepDegrees;
        stepDelay = savedStepDelay;
        speed = savedSpeed;

        delayed = savedDelayed;
        angle = savedAngle;
        axis = savedAxis;

        Debug.Log("Angle = " + angle + "Rot Angle = " + transform.eulerAngles.y);

        if (delayed)
            StartCoroutine("WaitForDelay");
    }
Exemple #16
0
//--------------------------------------------------------------------------------------------------
        public bool SearchCircle(
            Map map,
            int radius,
            ClockDirection clockDirection,
            Tour tour
            )
        {
            SearchSet ss = m_SearchSets[radius];

            SortedList <double, CircleEntry> entries = ss.Entries;

            if (entries == null)
            {
                return(false);
            }

            IList <CircleEntry> values;

            if (clockDirection == ClockDirection.Clockwise)
            {
                List <CircleEntry> list = new List <CircleEntry>(entries.Values);
                list.Reverse();
                values = list;
            }
            else
            {
                values = entries.Values;
            }

            foreach (CircleEntry entry in values)
            {
                if (tour(map, entry.X, entry.Y))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #17
0
        private void Gen(List <Polyline> pls, double t, out List <Polyline> outPls, out List <double> areaLis)
        {
            List <Polyline> nextGen  = new List <Polyline>();
            List <double>   nextArea = new List <double>();

            foreach (Polyline pl in pls)
            {
                Point3d[] pts       = pl.ToArray();
                double[]  ptsLength = new double[pts.Length - 1];
                for (int i = 0; i < pts.Length; i++)
                {
                    if (i > 0)
                    {
                        Point3d prev = pts[i - 1];
                        ptsLength[i - 1] = pts[i].DistanceTo(prev);
                    }
                }
                int  maxIdx      = Array.IndexOf(ptsLength, ptsLength.Max());
                Line longestLine = new Line(pts[maxIdx], pts[maxIdx + 1]);


                Vector3d normal       = new Vector3d(longestLine.Direction);
                Point3d  basePoint    = longestLine.PointAt(t);
                Plane    basePlane    = new Plane(basePoint, normal);
                var      intersection = Intersection.CurvePlane(pl.ToPolylineCurve(), basePlane, 0);
                Line     divider      = new Line(intersection[0].PointA, intersection[1].PointA);
                dividers.Add(divider);
                Vector3d dividerDir = divider.Direction;
                Polyline leftPl     = new Polyline();
                Polyline rightPl    = new Polyline();
                for (int i = 0; i < pl.Count; i++)
                {
                    if (X2D(divider, pts[i]) == LineSide.Right)
                    {
                        rightPl.Add(pts[i]);
                    }
                    else if (X2D(divider, pts[i]) == LineSide.Left)
                    {
                        leftPl.Add(pts[i]);
                    }
                }

                ClockDirection cDir  = CalculateClockDirection(pl.ToList());
                LineSide       cSide = X2D(divider, pl.First);
                if (cDir == ClockDirection.Clockwise &&
                    cSide == LineSide.Left)
                {
                    rightPl.Add(divider.From);
                    rightPl.Add(divider.To);
                    rightPl.Add(rightPl[0]);

                    int index = pl.IndexOf(rightPl[0]);
                    leftPl.Insert(index, divider.To);
                    leftPl.Insert(index + 1, divider.From);
                }
                else
                if (cDir == ClockDirection.Counterclockwise &&
                    cSide == LineSide.Left)
                {
                    rightPl.Add(divider.To);
                    rightPl.Add(divider.From);
                    rightPl.Add(rightPl[0]);

                    int index = pl.IndexOf(rightPl[0]);
                    leftPl.Insert(index, divider.From);
                    leftPl.Insert(index + 1, divider.To);
                }
                else
                if (cDir == ClockDirection.Clockwise &&
                    cSide == LineSide.Right)
                {
                    leftPl.Add(divider.To);
                    leftPl.Add(divider.From);
                    leftPl.Add(leftPl[0]);

                    int index = pl.IndexOf(leftPl[0]);
                    rightPl.Insert(index, divider.From);
                    rightPl.Insert(index + 1, divider.To);
                }
                else
                if (cDir == ClockDirection.Counterclockwise &&
                    cSide == LineSide.Right)
                {
                    leftPl.Add(divider.From);
                    leftPl.Add(divider.To);
                    leftPl.Add(leftPl[0]);

                    int index = pl.IndexOf(leftPl[0]);
                    rightPl.Insert(index, divider.To);
                    rightPl.Insert(index + 1, divider.From);
                }
                nextGen.Add(leftPl);
                nextGen.Add(rightPl);

                double areaL = AreaMassProperties.Compute(leftPl.ToPolylineCurve()).Area;
                double areaR = AreaMassProperties.Compute(leftPl.ToPolylineCurve()).Area;
                nextArea.Add(areaL);
                nextArea.Add(areaR);
            }
            areaLis = nextArea;
            outPls  = nextGen;
        }
Exemple #18
0
//--------------------------------------------------------------------------------------------------
    public bool SearchConcentricCircles( 
        Map                 map, 
        int                 start, 
        ClockDirection      clockDirection,
        SearchDirection     searchDirection,
        Tour                tour 
        )
    {
        int                 incr = ( searchDirection == SearchDirection.Outwards ? 1 : -1 );

        for( int i=start;;i+=incr)
        {
            if( i < 0 || i > m_Radius ) return false;

            SearchSet           ss = m_SearchSets[i];

            SortedList<double,CircleEntry> entries = ss.Entries;

            if( entries == null ) continue;

            IList<CircleEntry> values;

            if( clockDirection == ClockDirection.Clockwise )
            {
                List<CircleEntry> list = new List<CircleEntry>( entries.Values );
                list.Reverse();
                values = list;
            }
            else 
                values = entries.Values;

            foreach( CircleEntry entry in values )
            {
                if( tour( map, entry.X, entry.Y ) )
                    return true;
            }

            return false;
        }
    }
 public GetNodeSegmentIdsEnumerable GetNodeSegmentIds(ushort nodeId, ClockDirection clockDirection)
 {
     ref NetNode netNode          = ref nodeId.ToNode();