Ejemplo n.º 1
0
        public void TestSidePoint()
        {
            // polygons to intersect with
            Polygon3D s1 = new Polygon3D(new List <Point3D> {
                s1_1, s1_2, s1_3, s1_4
            }, "s2");
            Polygon3D s2 = new Polygon3D(new List <Point3D> {
                s1_1, s1_4, s1_3, s1_2
            }, "s2");                                                                         // reverse order => swap surfaces

            // point "on surface" of the square
            Point3D p1 = new Point3D(1, 1, 0);
            double  z  = p1.Z + (MSystem.SideDist * s1.Normal.Z); // calculate Z for assert purposes

            Point3D res_s1_a = s1.SidePoint(p1, Tile.SideType.inside);
            Point3D res_s1_b = s1.SidePoint(p1, Tile.SideType.outside);

            Assert.AreEqual(res_s1_a.X, p1.X);
            Assert.AreEqual(res_s1_a.Y, p1.Y);
            Assert.AreEqual(res_s1_a.Z, z);
            Assert.AreEqual(res_s1_a.X, res_s1_b.X);
            Assert.AreEqual(res_s1_a.Y, res_s1_b.Y);
            Assert.AreEqual(res_s1_a.Z, -(res_s1_b.Z)); // a bit nasty as we started with Z=0 => test is OK, if Z <> 0 the this would fail

            Point3D res_s2_a = s2.SidePoint(p1, Tile.SideType.inside);
            Point3D res_s2_b = s2.SidePoint(p1, Tile.SideType.outside);

            Assert.AreEqual(res_s2_a, res_s1_b);
            Assert.AreEqual(res_s2_b, res_s1_a);

            // point "on edge" of the square
            p1 = new Point3D(1, 0, 0);
            z  = p1.Z + (MSystem.SideDist * s1.Normal.Z); // calculate Z for assert purposes

            res_s1_a = s1.SidePoint(p1, Tile.SideType.inside);
            res_s1_b = s1.SidePoint(p1, Tile.SideType.outside);
            Assert.AreEqual(res_s1_a.X, p1.X);
            Assert.AreEqual(res_s1_a.Y, p1.Y);
            Assert.AreEqual(res_s1_a.Z, z);
            Assert.AreEqual(res_s1_a.X, res_s1_b.X);
            Assert.AreEqual(res_s1_a.Y, res_s1_b.Y);
            Assert.AreEqual(res_s1_a.Z, -(res_s1_b.Z));

            res_s2_a = s2.SidePoint(p1, Tile.SideType.inside);
            res_s2_b = s2.SidePoint(p1, Tile.SideType.outside);
            Assert.AreEqual(res_s2_a, res_s1_b);
            Assert.AreEqual(res_s2_b, res_s1_a);

            // point "not on the surface square" of the square but this is valid
            p1 = new Point3D(1, 1, 1);
            z  = p1.Z + (MSystem.SideDist * s1.Normal.Z); // calculate Z for assert purposes

            res_s1_a = s1.SidePoint(p1, Tile.SideType.inside);
            res_s1_b = s1.SidePoint(p1, Tile.SideType.outside);
            Assert.AreEqual(res_s1_a.X, p1.X);
            Assert.AreEqual(res_s1_a.Y, p1.Y);
            Assert.AreEqual(res_s1_a.Z, z);
            Assert.AreEqual(res_s1_a.X, res_s1_b.X);
            Assert.AreEqual(res_s1_a.Y, res_s1_b.Y);
            // z-coordinates shall not be apart more than this calculation
            z = 2 * (MSystem.SideDist * Math.Abs(s1.Normal.Z));
            Assert.AreEqual(z, res_s1_b.Z - res_s1_a.Z, MSystem.Tolerance);

            res_s2_a = s2.SidePoint(p1, Tile.SideType.inside);
            res_s2_b = s2.SidePoint(p1, Tile.SideType.outside);
            Assert.AreEqual(res_s2_a, res_s1_b);
            Assert.AreEqual(res_s2_b, res_s1_a);
        }