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

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

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

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

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

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

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

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

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

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

            Assert.AreEqual(PointInPoly.Outside, PolygonUtils.PointInPolyNonZero(points4, new Point2d(10, 10), false, true, MathUtils.EPSILON));
            Assert.AreEqual(PointInPoly.Inside, PolygonUtils.PointInPolyNonZero(points6, new Point2d(10, 10), false, true, MathUtils.EPSILON));
        }
Beispiel #3
0
        public void TestPointInPolyNonZero_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.PointInPolyNonZero(points, new Point2d(4, 0), true, true, MathUtils.EPSILON);

            Assert.AreEqual(PointInPoly.Inside, pip1);

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

            Assert.AreEqual(PointInPoly.Inside, pip2);

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

            Assert.AreEqual(PointInPoly.Inside, pip3);

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

            Assert.AreEqual(PointInPoly.Inside, pip4);

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

            Assert.AreEqual(PointInPoly.Outside, pip5);

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

            Assert.AreEqual(PointInPoly.Outside, pip6);

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

            Assert.AreEqual(PointInPoly.Outside, pip7);

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

            Assert.AreEqual(PointInPoly.Inside, pip8);

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

            Assert.AreEqual(PointInPoly.Inside, pip9);

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

            Assert.AreEqual(PointInPoly.On, pip10);

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

            Assert.AreEqual(PointInPoly.On, pip11);

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

            Assert.AreEqual(PointInPoly.On, pip12);

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

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