Beispiel #1
0
        /**
         * Crossing number test for a point in a polygon.
         */
        public bool PointInPolyEvenOdd(Point2d p, bool extendedAlgorithm, double epsilon = MathUtils.EPSILON)
        {
            if (!this.BoundingBox.IsInterior(p, epsilon))
            {
                return(false);
            }

            return(PolygonUtils.PointInPolyEvenOdd(this.vertices, p, extendedAlgorithm, this.robust, epsilon) != Essence.Geometry.Geom2D.PointInPoly.Outside);
        }
Beispiel #2
0
        public void TestPointInPolyEvenOdd_Default_Robust()
        {
            IList <Point2d> points1 = DuplicatePoints(AsList(new Point2d(0, 0), new Point2d(10, 10), new Point2d(0, 10)));
            IList <Point2d> points2 = DuplicatePoints(AsList(new Point2d(0, 0), new Point2d(10, 0), new Point2d(10, 10)));

            Assert.AreEqual(PointInPoly.Outside, PolygonUtils.PointInPolyEvenOdd(points1, new Point2d(5, 10), false, true, MathUtils.EPSILON));
            Assert.AreEqual(PointInPoly.Inside, PolygonUtils.PointInPolyEvenOdd(points1, new Point2d(0, 5), false, true, MathUtils.EPSILON));
            Assert.AreEqual(PointInPoly.Outside, PolygonUtils.PointInPolyEvenOdd(points1, new Point2d(5, 5), false, true, MathUtils.EPSILON));

            Assert.AreEqual(PointInPoly.Inside, PolygonUtils.PointInPolyEvenOdd(points2, new Point2d(5, 0), false, true, MathUtils.EPSILON));
            Assert.AreEqual(PointInPoly.Outside, PolygonUtils.PointInPolyEvenOdd(points2, new Point2d(10, 5), false, true, MathUtils.EPSILON));
            Assert.AreEqual(PointInPoly.Inside, PolygonUtils.PointInPolyEvenOdd(points2, new Point2d(5, 5), false, true, MathUtils.EPSILON));

            IList <Point2d> points3 = DuplicatePoints(AsList(new Point2d(0, 0), new Point2d(10, 0), new Point2d(10, 10), new Point2d(0, 10)));
            IList <Point2d> points4 = DuplicatePoints(AsList(new Point2d(0, 10), new Point2d(10, 10), new Point2d(10, 20), new Point2d(0, 20)));
            IList <Point2d> points5 = DuplicatePoints(AsList(new Point2d(10, 0), new Point2d(20, 0), new Point2d(20, 10), new Point2d(10, 10)));
            IList <Point2d> points6 = DuplicatePoints(AsList(new Point2d(10, 10), new Point2d(20, 10), new Point2d(20, 20), new Point2d(10, 20)));

            Assert.AreEqual(PointInPoly.Outside, PolygonUtils.PointInPolyEvenOdd(points3, new Point2d(5, 10), false, true, MathUtils.EPSILON));
            Assert.AreEqual(PointInPoly.Inside, PolygonUtils.PointInPolyEvenOdd(points4, new Point2d(5, 10), false, true, MathUtils.EPSILON));

            Assert.AreEqual(PointInPoly.Outside, PolygonUtils.PointInPolyEvenOdd(points5, new Point2d(15, 10), false, true, MathUtils.EPSILON));
            Assert.AreEqual(PointInPoly.Inside, PolygonUtils.PointInPolyEvenOdd(points6, new Point2d(15, 10), false, true, MathUtils.EPSILON));

            Assert.AreEqual(PointInPoly.Outside, PolygonUtils.PointInPolyEvenOdd(points3, new Point2d(10, 5), false, true, MathUtils.EPSILON));
            Assert.AreEqual(PointInPoly.Inside, PolygonUtils.PointInPolyEvenOdd(points5, new Point2d(10, 5), false, true, MathUtils.EPSILON));

            Assert.AreEqual(PointInPoly.Outside, PolygonUtils.PointInPolyEvenOdd(points4, new Point2d(10, 15), false, true, MathUtils.EPSILON));
            Assert.AreEqual(PointInPoly.Inside, PolygonUtils.PointInPolyEvenOdd(points6, new Point2d(10, 15), false, true, MathUtils.EPSILON));

            Assert.AreEqual(PointInPoly.Outside, PolygonUtils.PointInPolyEvenOdd(points3, new Point2d(10, 10), false, true, MathUtils.EPSILON));
            Assert.AreEqual(PointInPoly.Outside, PolygonUtils.PointInPolyEvenOdd(points5, new Point2d(10, 10), false, true, MathUtils.EPSILON));

            Assert.AreEqual(PointInPoly.Outside, PolygonUtils.PointInPolyEvenOdd(points4, new Point2d(10, 10), false, true, MathUtils.EPSILON));
            Assert.AreEqual(PointInPoly.Inside, PolygonUtils.PointInPolyEvenOdd(points6, new Point2d(10, 10), false, true, MathUtils.EPSILON));
        }
Beispiel #3
0
        public void TestPointInPolyEvenOdd_Extended_Robust()
        {
            Circle2 c    = new Circle2(new Point2d(0, 0), 5);
            double  tmin = c.TMin;
            double  tmax = c.TMax;
            double  tinc = (tmax - tmin) / 5;
            Point2d p0   = c.GetPosition(tmin);
            Point2d p1   = c.GetPosition(tmin + tinc);
            Point2d p2   = c.GetPosition(tmin + 2 * tinc);
            Point2d p3   = c.GetPosition(tmin + 3 * tinc);
            Point2d p4   = c.GetPosition(tmin + 4 * tinc);

            IList <Point2d> points = DuplicatePoints(AsList(p0, p2, p4, p1, p3));

            PointInPoly pip1 = PolygonUtils.PointInPolyEvenOdd(points, new Point2d(4, 0), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.Inside, pip1);

            PointInPoly pip2 = PolygonUtils.PointInPolyEvenOdd(points, new Point2d(-2, 2), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.Inside, pip2);

            PointInPoly pip3 = PolygonUtils.PointInPolyEvenOdd(points, new Point2d(-2, -2), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.Inside, pip3);

            PointInPoly pip4 = PolygonUtils.PointInPolyEvenOdd(points, new Point2d(0, 0), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.Outside, pip4);

            PointInPoly pip5 = PolygonUtils.PointInPolyEvenOdd(points, new Point2d(10, 0), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.Outside, pip5);

            PointInPoly pip6 = PolygonUtils.PointInPolyEvenOdd(points, new Point2d(4, 3), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.Outside, pip6);

            PointInPoly pip7 = PolygonUtils.PointInPolyEvenOdd(points, new Point2d(4, -3), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.Outside, pip7);

            PointInPoly pip8 = PolygonUtils.PointInPolyEvenOdd(points, new Point2d(1, 1), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.Outside, pip8);

            PointInPoly pip9 = PolygonUtils.PointInPolyEvenOdd(points, new Point2d(1, -1), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.Outside, pip9);

            PointInPoly pip10 = PolygonUtils.PointInPolyEvenOdd(points, p4.Add(p1.Sub(p4).Unit.Mul(0.7)), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.On, pip10);

            PointInPoly pip11 = PolygonUtils.PointInPolyEvenOdd(points, p4.Add(p1.Sub(p4).Unit.Mul(0.3)), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.On, pip11);

            PointInPoly pip12 = PolygonUtils.PointInPolyEvenOdd(points, p1.Add(p3.Sub(p1).Unit.Mul(0.7)), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.On, pip12);

            PointInPoly pip13 = PolygonUtils.PointInPolyEvenOdd(points, p1.Add(p3.Sub(p1).Unit.Mul(0.3)), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.On, pip13);
        }