Example #1
0
        private bool IsPolylineRectangle()
        {
            if (this.PaddedPolyline.PolylinePoints.Count() != 4)
            {
                return(false);
            }

            var ppt     = this.PaddedPolyline.StartPoint;
            var nextPpt = ppt.NextOnPolyline;
            var dir     = CompassVector.DirectionsFromPointToPoint(ppt.Point, nextPpt.Point);

            if (!CompassVector.IsPureDirection(dir))
            {
                return(false);
            }
            do
            {
                ppt     = nextPpt;
                nextPpt = ppt.NextOnPolyline;
                var nextDir = CompassVector.DirectionsFromPointToPoint(ppt.Point, nextPpt.Point);

                // We know the polyline is clockwise.
                if (nextDir != CompassVector.RotateRight(dir))
                {
                    return(false);
                }
                dir = nextDir;
            } while (ppt != this.PaddedPolyline.StartPoint);
            return(true);
        }
Example #2
0
        internal static Directions GetPureDirection(Point a, Point b)
        {
            Assert_Rounded(a);
            Assert_Rounded(b);
            Directions dir = GetDirections(a, b);

            Debug.Assert(CompassVector.IsPureDirection(dir), "Impure direction found");
            return(dir);
        }
Example #3
0
        internal void SetNewNext(Point p)
        {
            var nv  = new LinkedPoint(p);
            var tmp = Next;

            Next    = nv;
            nv.Next = tmp;
            Debug.Assert(CompassVector.IsPureDirection(Point, Next.Point));
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="direction"></param>
        /// <param name="obstacles"></param>
        /// <param name="axisEdgesToObstaclesTheyOriginatedFrom"></param>
        /// <param name="pathOrders"></param>
        /// <param name="axisEdges">edges to find the empty space around</param>
        internal FreeSpaceFinder(Directions direction, IEnumerable <Polyline> obstacles, Dictionary <AxisEdge, Polyline> axisEdgesToObstaclesTheyOriginatedFrom, Dictionary <AxisEdge, List <PathEdge> > pathOrders,
                                 IEnumerable <AxisEdge> axisEdges) : base(obstacles, new CompassVector(direction).ToPoint())
        {
            DirectionPerp = new CompassVector(direction).Right.ToPoint();
            PathOrders    = pathOrders;
            xProjection   = direction == Directions.North ? (PointProjection)X : MinusY;
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=301
            edgeContainersTree = new RbTree <AxisEdgesContainer>(new FreeSpaceFinderComparer(this));
#else
            edgeContainersTree = new RbTree <AxisEdgesContainer>(this);
#endif
            SweepPole = CompassVector.VectorDirection(SweepDirection);
            Debug.Assert(CompassVector.IsPureDirection(SweepPole));
            AxisEdges = axisEdges;
            AxisEdgesToObstaclesTheyOriginatedFrom = axisEdgesToObstaclesTheyOriginatedFrom;
        }
        internal void ExtendEdgeChain(VisibilityVertex startVertex, Rectangle limitRect, LineSegment maxVisibilitySegment,
                                      PointAndCrossingsList pacList, bool isOverlapped)
        {
            var dir = PointComparer.GetDirections(maxVisibilitySegment.Start, maxVisibilitySegment.End);

            if (dir == Directions.None)
            {
                return;
            }

            Debug.Assert(CompassVector.IsPureDirection(dir), "impure max visibility segment");

            // Shoot the edge chain out to the shorter of max visibility or intersection with the limitrect.
            StaticGraphUtility.Assert(PointComparer.Equal(maxVisibilitySegment.Start, startVertex.Point) ||
                                      (PointComparer.GetPureDirection(maxVisibilitySegment.Start, startVertex.Point) == dir)
                                      , "Inconsistent direction found", ObstacleTree, VisGraph);
            double oppositeFarBound      = StaticGraphUtility.GetRectangleBound(limitRect, dir);
            Point  maxDesiredSplicePoint = StaticGraphUtility.IsVertical(dir)
                                    ? ApproximateComparer.Round(new Point(startVertex.Point.X, oppositeFarBound))
                                    : ApproximateComparer.Round(new Point(oppositeFarBound, startVertex.Point.Y));

            if (PointComparer.Equal(maxDesiredSplicePoint, startVertex.Point))
            {
                // Nothing to do.
                return;
            }
            if (PointComparer.GetPureDirection(startVertex.Point, maxDesiredSplicePoint) != dir)
            {
                // It's in the opposite direction, so no need to do anything.
                return;
            }

            // If maxDesiredSplicePoint is shorter, create a new shorter segment.  We have to pass both segments
            // through to the worker function so it knows whether it can go past maxDesiredSegment (which may be limited
            // by limitRect).
            var maxDesiredSegment = maxVisibilitySegment;

            if (PointComparer.GetDirections(maxDesiredSplicePoint, maxDesiredSegment.End) == dir)
            {
                maxDesiredSegment = new LineSegment(maxDesiredSegment.Start, maxDesiredSplicePoint);
            }

            ExtendEdgeChain(startVertex, dir, maxDesiredSegment, maxVisibilitySegment, pacList, isOverlapped);
        }
 internal GroupBoundaryCrossing(Obstacle group, Directions dirToInside)
 {
     Debug.Assert(CompassVector.IsPureDirection(dirToInside), "Impure direction");
     this.Group             = group;
     this.DirectionToInside = dirToInside;
 }
Example #7
0
 internal static bool IsPureDirection(Directions dir)
 {
     return(CompassVector.IsPureDirection(dir));
 }
Example #8
0
 internal static bool IsPureDirection(Point a, Point b)
 {
     Assert_Rounded(a);
     Assert_Rounded(b);
     return(CompassVector.IsPureDirection(GetDirections(a, b)));
 }
Example #9
0
 private int GetNumberOfBends(Directions entryDirToVertex, Directions dirToTarget)
 {
     return(CompassVector.IsPureDirection(dirToTarget)
                             ? GetNumberOfBendsForPureDirection(entryDirToVertex, dirToTarget)
                             : GetBendsForNotPureDirection(dirToTarget, entryDirToVertex, EntryDirectionsToTarget));
 }