Ejemplo n.º 1
0
        public void TestOverlapsWith()
        {
            // polygon to intersect with
            Polygon3D s = new Polygon3D(new List <Point3D> {
                s1_1, s1_2, s1_3, s1_4
            }, "s");

            // triangle in xy-plane which will be moving and testing overlapping
            Point3D p1 = new Point3D(0, -1, 0);
            Point3D p2 = new Point3D(3, -1, 0);
            Point3D p3 = new Point3D(0, -4, 0);

            List <Point3D> l = new List <Point3D> {
                p1, p2, p3
            };
            Polygon3D t = new Polygon3D(l, "s");

            // polygon overlaps with itself
            Assert.IsTrue(t.OverlapsWith(t));
            Assert.IsTrue(s.OverlapsWith(s));

            // we must get the same result call the method the other way round => testing two calls
            Assert.IsFalse(t.OverlapsWith(s));
            Assert.IsFalse(s.OverlapsWith(t));

            // move up - borders touch on the edge but do not overlap
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsFalse(t.OverlapsWith(s));
            Assert.IsFalse(s.OverlapsWith(t));

            // move up
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsTrue(t.OverlapsWith(s));
            Assert.IsTrue(s.OverlapsWith(t));

            // move up
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsTrue(t.OverlapsWith(s));
            Assert.IsTrue(s.OverlapsWith(t));

            // move up
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsTrue(t.OverlapsWith(s));
            Assert.IsTrue(s.OverlapsWith(t));

            // move up
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsTrue(t.OverlapsWith(s));
            Assert.IsTrue(s.OverlapsWith(t));

            // move up
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsTrue(t.OverlapsWith(s));
            Assert.IsTrue(s.OverlapsWith(t));

            // move up - touch on the bottom vertice of triangle => not counted
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsFalse(t.OverlapsWith(s));
            Assert.IsFalse(s.OverlapsWith(t));

            // move up
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsFalse(t.OverlapsWith(s));
            Assert.IsFalse(s.OverlapsWith(t));

            // now we move triangle two units left and start moving upwards again
            l = new List <Point3D> {
                p1 - (2 * uX), p2 - (2 * uX), p3 - (2 * uX)
            };

            Assert.IsFalse(t.OverlapsWith(s));
            Assert.IsFalse(s.OverlapsWith(t));

            // move up - borders touch on the edge but do not overlap
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsFalse(t.OverlapsWith(s));
            Assert.IsFalse(s.OverlapsWith(t));

            // move up
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsTrue(t.OverlapsWith(s));
            Assert.IsTrue(s.OverlapsWith(t));

            // move up
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsTrue(t.OverlapsWith(s));
            Assert.IsTrue(s.OverlapsWith(t));

            // move up
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsTrue(t.OverlapsWith(s));
            Assert.IsTrue(s.OverlapsWith(t));

            // move up = touch in one point = false
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsFalse(t.OverlapsWith(s));
            Assert.IsFalse(s.OverlapsWith(t));

            // move up
            for (int i = 0; i < l.Count; i++)
            {
                l[i] += uY;
            }
            t = new Polygon3D(l, "s");
            Assert.IsFalse(t.OverlapsWith(s));
            Assert.IsFalse(s.OverlapsWith(t));

            // now we put triangle over square but z axis equals 1 => no overlap
            l = new List <Point3D> {
                p1 + (2 * uY) + uZ, p2 + (2 * uY) + uZ, p3 + (2 * uY) + uZ
            };

            Assert.IsFalse(t.OverlapsWith(s));
            Assert.IsFalse(s.OverlapsWith(t));
        }