예제 #1
0
        public override void Recalculate()
        {
            // first assume we exist
            Exists = true;

            // if any of our dependencies don't exist, return
            UpdateExistence();
            if (!Exists)
            {
                return;
            }

            var figure1 = Dependencies.ElementAt(0);
            var figure2 = Dependencies.ElementAt(1);

            if (Algorithm == null)
            {
                Exists = false;
                return;
            }

            Point p = Algorithm(figure1, figure2);

            if (!p.Exists() || figure1.HitTest(p) == null || figure2.HitTest(p) == null)
            {
                Exists = false;
                return;
            }

            Exists      = true;
            Coordinates = p;
        }
예제 #2
0
        public static bool IsPointInPolygon(this IList <Point> polygon, Point start)
        {
            var outsidePoint = new Point(polygon.Max(p => p.X) + 100, 0);
            var segment      = new PointPair(start, outsidePoint);

            int n = polygon.Count;
            int intersectionsCount = 0;

            for (int i = 0; i < n; i++)
            {
                PointPair side = new PointPair(polygon[i], polygon[i.RotateNext(n)]);

                Point intersectionPoint = GetIntersectionOfLines(segment, side);
                if (!intersectionPoint.Exists())
                {
                    continue;
                }
                if (IsPointInSegmentBoundingRect(side, intersectionPoint) &&
                    IsPointInSegmentBoundingRect(segment, intersectionPoint) &&
                    intersectionPoint != side.P2)
                {
                    if (intersectionPoint == side.P1 &&
                        Math.VectorProduct(start, side.P1, polygon[i.RotatePrevious(n)]).Sign()
                        == Math.VectorProduct(start, side.P1, side.P2).Sign())
                    {
                        continue;
                    }
                    intersectionsCount++;
                }
            }

            return(intersectionsCount % 2 == 1);
        }
예제 #3
0
        public static Func <IFigure, IFigure, Point> PickCloserIntersectionPoint(
            Func <IFigure, IFigure, Point> algorithm1,
            Func <IFigure, IFigure, Point> algorithm2,
            IFigure figure1,
            IFigure figure2,
            Point hintPoint)
        {
            Point p1 = algorithm1(figure1, figure2);
            Point p2 = algorithm2(figure1, figure2);

            if (!p1.Exists())
            {
                if (p2.Exists())
                {
                    return(algorithm2);
                }
                else
                {
                    return(algorithm1);
                }
            }
            else
            {
                if (!p2.Exists())
                {
                    return(algorithm1);
                }
                else
                {
                    var d1 = p1.Distance(hintPoint);
                    var d2 = p2.Distance(hintPoint);
                    if (d1 < d2)
                    {
                        return(algorithm1);
                    }
                    else
                    {
                        return(algorithm2);
                    }
                }
            }
        }
예제 #4
0
        public static Point GetIntersectionOfSegments(PointPair segment1, PointPair segment2)
        {
            Point result = GetIntersectionOfLines(segment1, segment2);

            if (!result.Exists())
            {
                return(result);
            }
            if (IsPointInSegmentInnerBoundingRect(segment1, result) &&
                IsPointInSegmentInnerBoundingRect(segment2, result))
            {
                return(result);
            }
            return(Math.InfinitePoint);
        }
예제 #5
0
        public static List <Point> GetIntersections(IList <Point> polygon, PointPair segment)
        {
            List <Point> result = new List <Point>();
            int          n      = polygon.Count;

            for (int i = 0; i < n; i++)
            {
                PointPair side         = new PointPair(polygon[i], polygon[i.RotateNext(n)]);
                Point     intersection = GetIntersectionOfSegments(side, segment);
                if (intersection.Exists() && intersection != polygon[i.RotateNext(n)])
                {
                    result.Add(intersection);
                }
            }
            return(result);
        }
예제 #6
0
        public override void Recalculate()
        {
            if (!Dependencies.Exists())
            {
                Exists = false;
                return;
            }

            var   figure1       = LinearFigure;
            Point p             = figure1.GetPointFromParameter(Parameter);
            bool  HitTestFailed = (UseHitTestingForExistence) ? LinearFigure.HitTest(p) == null : false;

            if (!p.Exists() || HitTestFailed)
            {
                Exists = false;
                return;
            }

            Exists      = true;
            Coordinates = p;
        }