Example #1
0
        public void TestContainsInside()
        {
            // polygons to test with
            Polygon3D s = new Polygon3D(new List <Point3D> {
                s1_1, s1_2, s1_3, s1_4
            }, "s");

            // parameters for the test
            double delta_1 = 3e-11; // under system tolerance
            double delta_2 = 1e-9;  // over system tolerance

            // ---
            // point on vertex of the square
            // ---
            Point3D p = new Point3D(0, 0, 0);

            Assert.IsTrue(s.ContainsPoint(p));

            // no borderTolerance
            Assert.IsTrue(s.ContainsPoint(p + (delta_1 * uX) + (delta_1 * uY)));
            Assert.IsTrue(s.ContainsPoint(p + (delta_1 * uX) - (delta_1 * uY)));
            Assert.IsTrue(s.ContainsPoint(p - (delta_1 * uX) - (delta_1 * uY)));
            Assert.IsTrue(s.ContainsPoint(p - (delta_1 * uX) + (delta_1 * uY)));

            // under border tolerance equal to MSystem.Tolerance (square gets smaller by MSystem.Tolerance)
            Assert.IsFalse(s.ContainsPoint(p + (delta_1 * uX) + (delta_1 * uY), MSystem.Tolerance));
            Assert.IsFalse(s.ContainsPoint(p + (delta_1 * uX) - (delta_1 * uY), MSystem.Tolerance));
            Assert.IsFalse(s.ContainsPoint(p - (delta_1 * uX) - (delta_1 * uY), MSystem.Tolerance));
            Assert.IsFalse(s.ContainsPoint(p - (delta_1 * uX) + (delta_1 * uY), MSystem.Tolerance));

            // over border tolerance equal to MSystem.Tolerance
            Assert.IsTrue(s.ContainsPoint(p + (delta_2 * uX) + (delta_2 * uY), MSystem.Tolerance));
            Assert.IsFalse(s.ContainsPoint(p + (delta_2 * uX) - (delta_2 * uY), MSystem.Tolerance));
            Assert.IsFalse(s.ContainsPoint(p - (delta_2 * uX) - (delta_2 * uY), MSystem.Tolerance));
            Assert.IsFalse(s.ContainsPoint(p - (delta_2 * uX) + (delta_2 * uY), MSystem.Tolerance));

            // ---
            // point on edge of the square
            // ---
            p = new Point3D(2, 0, 0);
            Assert.IsTrue(s.ContainsPoint(p));

            // no borderTolerance
            Assert.IsTrue(s.ContainsPoint(p + (delta_1 * uX) + (delta_1 * uY)));
            Assert.IsTrue(s.ContainsPoint(p + (delta_1 * uX) - (delta_1 * uY)));
            Assert.IsTrue(s.ContainsPoint(p - (delta_1 * uX) - (delta_1 * uY)));
            Assert.IsTrue(s.ContainsPoint(p - (delta_1 * uX) + (delta_1 * uY)));

            // under border tolerance equal to MSystem.Tolerance (square gets smaller by MSystem.Tolerance)
            Assert.IsFalse(s.ContainsPoint(p + (delta_1 * uX) + (delta_1 * uY), MSystem.Tolerance));
            Assert.IsFalse(s.ContainsPoint(p + (delta_1 * uX) - (delta_1 * uY), MSystem.Tolerance));
            Assert.IsFalse(s.ContainsPoint(p - (delta_1 * uX) - (delta_1 * uY), MSystem.Tolerance));
            Assert.IsFalse(s.ContainsPoint(p - (delta_1 * uX) + (delta_1 * uY), MSystem.Tolerance));

            // over border tolerance equal to MSystem.Tolerance
            Assert.IsTrue(s.ContainsPoint(p + (delta_2 * uX) + (delta_2 * uY), MSystem.Tolerance));
            Assert.IsFalse(s.ContainsPoint(p + (delta_2 * uX) - (delta_2 * uY), MSystem.Tolerance));
            Assert.IsFalse(s.ContainsPoint(p - (delta_2 * uX) - (delta_2 * uY), MSystem.Tolerance));
            Assert.IsTrue(s.ContainsPoint(p - (delta_2 * uX) + (delta_2 * uY), MSystem.Tolerance));

            // ---
            // point in the square
            // ---
            p = new Point3D(2, 2, 0);
            Assert.IsTrue(s.ContainsPoint(p));

            // no borderTolerance
            Assert.IsTrue(s.ContainsPoint(p + (delta_1 * uX) + (delta_1 * uY)));
            Assert.IsTrue(s.ContainsPoint(p + (delta_1 * uX) - (delta_1 * uY)));
            Assert.IsTrue(s.ContainsPoint(p - (delta_1 * uX) - (delta_1 * uY)));
            Assert.IsTrue(s.ContainsPoint(p - (delta_1 * uX) + (delta_1 * uY)));

            // under border tolerance equal to MSystem.Tolerance
            Assert.IsTrue(s.ContainsPoint(p + (delta_1 * uX) + (delta_1 * uY), MSystem.Tolerance));
            Assert.IsTrue(s.ContainsPoint(p + (delta_1 * uX) - (delta_1 * uY), MSystem.Tolerance));
            Assert.IsTrue(s.ContainsPoint(p - (delta_1 * uX) - (delta_1 * uY), MSystem.Tolerance));
            Assert.IsTrue(s.ContainsPoint(p - (delta_1 * uX) + (delta_1 * uY), MSystem.Tolerance));

            // over border tolerance equal to MSystem.Tolerance
            Assert.IsTrue(s.ContainsPoint(p + (delta_2 * uX) + (delta_2 * uY), MSystem.Tolerance));
            Assert.IsTrue(s.ContainsPoint(p + (delta_2 * uX) - (delta_2 * uY), MSystem.Tolerance));
            Assert.IsTrue(s.ContainsPoint(p - (delta_2 * uX) - (delta_2 * uY), MSystem.Tolerance));
            Assert.IsTrue(s.ContainsPoint(p - (delta_2 * uX) + (delta_2 * uY), MSystem.Tolerance));

            // ---
            // point "above" and below the square
            // ---
            p = new Point3D(0, 0, 0);
            // point above the edge or vertex is not on surfice
            Assert.IsTrue(s.ContainsPoint(p + (delta_1 * uZ)));
            Assert.IsTrue(s.ContainsPoint(p - (delta_1 * uZ)));
            Assert.IsFalse(s.ContainsPoint(p + (delta_2 * uZ)));
            Assert.IsFalse(s.ContainsPoint(p - (delta_2 * uZ)));

            p = new Point3D(2, 0, 0);
            // point above the edge or vertex is not on surfice
            Assert.IsTrue(s.ContainsPoint(p + (delta_1 * uZ)));
            Assert.IsTrue(s.ContainsPoint(p - (delta_1 * uZ)));
            Assert.IsFalse(s.ContainsPoint(p + (delta_2 * uZ)));
            Assert.IsFalse(s.ContainsPoint(p - (delta_2 * uZ)));

            p = new Point3D(2, 2, 0);
            Assert.IsTrue(s.ContainsPoint(p + (delta_1 * uZ)));
            Assert.IsTrue(s.ContainsPoint(p - (delta_1 * uZ)));
            Assert.IsFalse(s.ContainsPoint(p + (delta_2 * uZ)));
            Assert.IsFalse(s.ContainsPoint(p - (delta_2 * uZ)));
        }