Example #1
0
        public void Test_Centroid_TriangleFace()
        {
            Vertex a = new Vertex(new Vector3(1, 2, 3));
            Vertex b = new Vertex(new Vector3(3, 9, -1));
            Vertex c = new Vertex(new Vector3(4, 4, -7));

            HalfEdge ab = new HalfEdge(a);
            HalfEdge ac = new HalfEdge(a);

            HalfEdge ba = new HalfEdge(b);
            HalfEdge bc = new HalfEdge(b);

            HalfEdge ca = new HalfEdge(c);
            HalfEdge cb = new HalfEdge(c);

            ab.Twin = ba;
            ac.Twin = ca;

            ba.Twin = ab;
            bc.Twin = cb;

            ca.Twin = ac;
            cb.Twin = bc;

            Face face = new Face(0, Auxilaries.RandomNormal());

            face.AddOuterComponent(ac);
            face.AddOuterComponent(cb);
            face.AddOuterComponent(ba);

            Vector3 actual   = face.Centroid;
            Vector3 expected = new Vector3(8, 15, -5) * (1.0f / 3.0f);

            Assert.IsTrue(expected == actual);
        }
Example #2
0
        public void TestEquals_EqualsDifferentOrder()
        {
            HalfEdge a = Auxilaries.RandomHalfEdge();
            HalfEdge b = Auxilaries.RandomHalfEdge();
            HalfEdge c = Auxilaries.RandomHalfEdge();
            HalfEdge d = Auxilaries.RandomHalfEdge();

            Vector3 normal = Auxilaries.RandomNormal();

            Face thisFace = new Face(0, normal);

            thisFace.AddOuterComponent(a);
            thisFace.AddOuterComponent(b);
            thisFace.AddOuterComponent(c);
            thisFace.AddOuterComponent(d);

            Face otherFace = new Face(0, normal);

            otherFace.AddOuterComponent(b);
            otherFace.AddOuterComponent(a);
            otherFace.AddOuterComponent(d);
            otherFace.AddOuterComponent(c);

            Assert.IsTrue(thisFace.Equals(otherFace));
            Assert.IsTrue(otherFace.Equals(thisFace));
            Assert.AreEqual(thisFace.GetHashCode(), otherFace.GetHashCode());
        }
Example #3
0
        public void TestEquals_IdxEqualNotEqualSameSizeDifferentEdges()
        {
            HalfEdge a = Auxilaries.RandomHalfEdge();
            HalfEdge b = Auxilaries.RandomHalfEdge();
            HalfEdge c = Auxilaries.RandomHalfEdge();
            HalfEdge d = Auxilaries.RandomHalfEdge();
            HalfEdge e = Auxilaries.RandomHalfEdge();

            Vector3 normal = Auxilaries.RandomNormal();

            Face thisFace = new Face(0, normal);

            thisFace.AddOuterComponent(a);
            thisFace.AddOuterComponent(b);
            thisFace.AddOuterComponent(c);
            thisFace.AddOuterComponent(d);

            Face otherFace = new Face(0, normal);

            otherFace.AddOuterComponent(a);
            otherFace.AddOuterComponent(b);
            otherFace.AddOuterComponent(e);
            otherFace.AddOuterComponent(d);

            Assert.IsFalse(thisFace.Equals(otherFace));
            Assert.IsFalse(otherFace.Equals(thisFace));
            Assert.AreNotEqual(thisFace.GetHashCode(), otherFace.GetHashCode());
        }
Example #4
0
        public void TestIsTriangular_Triangle()
        {
            Vertex a = new Vertex(new Vector3(1, 2, 3));
            Vertex b = new Vertex(new Vector3(3, 9, -1));
            Vertex c = new Vertex(new Vector3(4, 4, -7));

            HalfEdge ab = new HalfEdge(a);
            HalfEdge ac = new HalfEdge(a);

            HalfEdge ba = new HalfEdge(b);
            HalfEdge bc = new HalfEdge(b);

            HalfEdge ca = new HalfEdge(c);
            HalfEdge cb = new HalfEdge(c);

            ab.Twin = ba;
            ac.Twin = ca;

            ba.Twin = ab;
            bc.Twin = cb;

            ca.Twin = ac;
            cb.Twin = bc;

            Face triangle = new Face(0, Auxilaries.RandomNormal());

            triangle.AddOuterComponent(ac);
            triangle.AddOuterComponent(cb);
            triangle.AddOuterComponent(ba);

            Assert.IsTrue(triangle.IsTriangular());
        }
Example #5
0
        public void TestEquals_EqualBothIncidentFacesSet()
        {
            Vertex a = Auxilaries.RandomVertex();
            Vertex b = Auxilaries.RandomVertex();
            Vertex c = Auxilaries.RandomVertex();

            HalfEdge abOther = new HalfEdge(a);
            HalfEdge abThis  = new HalfEdge(a);
            HalfEdge ac      = new HalfEdge(a);

            HalfEdge ba = new HalfEdge(b);
            HalfEdge bc = new HalfEdge(b);

            HalfEdge ca = new HalfEdge(c);
            HalfEdge cb = new HalfEdge(c);

            Face face = new Face(2, Auxilaries.RandomNormal());

            face.AddOuterComponent(abThis);
            face.AddOuterComponent(bc);
            face.AddOuterComponent(ca);

            abThis.IncidentFace  = face;
            abOther.IncidentFace = face;

            abThis.Twin  = ba;
            abOther.Twin = ba;
            ac.Twin      = ca;

            ba.Twin = abThis;
            bc.Twin = bc;

            ca.Twin = ac;
            cb.Twin = bc;

            abThis.Next  = bc;
            abOther.Next = bc;
            ac.Next      = cb;

            ba.Next = ac;
            bc.Next = ca;

            ca.Next = abThis;
            cb.Next = ba;

            abThis.Previous  = ca;
            abOther.Previous = ca;
            ac.Previous      = ba;

            ba.Previous = cb;
            bc.Previous = abThis;

            ca.Previous = bc;
            cb.Previous = ac;

            Assert.AreEqual(abThis.GetHashCode(), abOther.GetHashCode());

            Assert.IsTrue(abThis.Equals(abOther));
            Assert.IsTrue(abOther.Equals(abThis));
        }
Example #6
0
        public void TestHasIncidentFace_HasIncidentFace()
        {
            HalfEdge edge = Auxilaries.RandomHalfEdge();

            edge.IncidentFace = new Face(0, Auxilaries.RandomNormal());

            Assert.IsTrue(edge.HasIncidentFace);
        }
Example #7
0
        public void TestAddIncidentEdges_ReplicateSegmentationFault()
        {
            Vertex v1 = Auxilaries.RandomVertex();
            Vertex v2 = Auxilaries.RandomVertex();
            Vertex v3 = Auxilaries.RandomVertex();

            HalfEdge e11 = new HalfEdge(v1);
            HalfEdge e12 = new HalfEdge(v2);
            HalfEdge e31 = new HalfEdge(v3);
            HalfEdge e32 = new HalfEdge(v1);
            HalfEdge e41 = new HalfEdge(v3);
            HalfEdge e42 = new HalfEdge(v2);

            e11.Twin = e12;
            e12.Twin = e11;
            e31.Twin = e32;
            e32.Twin = e31;
            e41.Twin = e42;
            e42.Twin = e41;

            e12.Next = e32;
            e32.Next = e41;
            e41.Next = e12;

            e12.Previous = e41;
            e32.Previous = e12;
            e41.Previous = e32;

            Face f2 = new Face(2, Auxilaries.RandomNormal());

            f2.AddOuterComponent(e32);
            f2.AddOuterComponent(e41);
            f2.AddOuterComponent(e12);

            e32.IncidentFace = f2;
            e41.IncidentFace = f2;
            e12.IncidentFace = f2;

            v1.AddIncidentEdge(e11);
            v1.AddIncidentEdge(e32);

            v2.AddIncidentEdge(e42);
            v2.AddIncidentEdge(e12);

            v3.AddIncidentEdge(e31);
            v3.AddIncidentEdge(e41);

            Assert.Contains(e11, v1.IncidentEdges);
            Assert.Contains(e32, v1.IncidentEdges);

            Assert.Contains(e42, v2.IncidentEdges);
            Assert.Contains(e12, v2.IncidentEdges);

            Assert.Contains(e31, v3.IncidentEdges);
            Assert.Contains(e41, v3.IncidentEdges);
        }
Example #8
0
        public void XAndyAreNotEqual_IdxDifferent()
        {
            Vector3 normal = Auxilaries.RandomNormal();

            Face x = new Face(1, normal);
            Face y = new Face(2, normal);

            Assert.IsFalse(comparer.Equals(x, y));
            Assert.AreNotEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));
        }
Example #9
0
        public void XAndyAreEqual()
        {
            int     idx                = 3;
            Vector3 normal             = Auxilaries.RandomNormal();
            KeyValuePair <int, Face> x = new KeyValuePair <int, Face>(idx, new Face(idx, normal));
            KeyValuePair <int, Face> y = new KeyValuePair <int, Face>(idx, new Face(idx, normal));

            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));
        }
Example #10
0
        public void XAndyAreNotEqual_NormalDifferent()
        {
            int idx = 0;

            Face x = new Face(idx, Auxilaries.RandomNormal());
            Face y = new Face(idx, Auxilaries.RandomNormal());

            Assert.IsFalse(comparer.Equals(x, y));
            Assert.AreNotEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));
        }
Example #11
0
        public void XAndyAreEqual()
        {
            int     idx    = 3;
            Vector3 normal = Auxilaries.RandomNormal();

            Face x = new Face(idx, normal);
            Face y = new Face(idx, normal);

            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));
        }
Example #12
0
        public void TestCompareTo_MeshIdxLarger()
        {
            Vector3 normal = Auxilaries.RandomNormal();

            Face thisFace  = new Face(5, normal);
            Face otherFace = new Face(1, normal);

            int expected = 1;
            int actual   = thisFace.CompareTo(otherFace);

            Assert.AreEqual(expected, actual);
        }
Example #13
0
        public void XAndyAreNotEqual_OuterComponentsDifferent()
        {
            int     idx    = 3;
            Vector3 normal = Auxilaries.RandomNormal();
            Face    x      = new Face(idx, normal);
            Face    y      = new Face(idx, normal);

            x.AddOuterComponent(Auxilaries.RandomHalfEdge());
            y.AddOuterComponent(Auxilaries.RandomHalfEdge());

            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));
        }
Example #14
0
        public void Test_Vertices_Rectangle()
        {
            Vertex a = Auxilaries.RandomVertex();
            Vertex b = Auxilaries.RandomVertex();
            Vertex c = Auxilaries.RandomVertex();
            Vertex d = Auxilaries.RandomVertex();

            HalfEdge ab = new HalfEdge(a);
            HalfEdge ba = new HalfEdge(b);

            HalfEdge bc = new HalfEdge(b);
            HalfEdge cb = new HalfEdge(c);

            HalfEdge cd = new HalfEdge(c);
            HalfEdge dc = new HalfEdge(d);

            HalfEdge da = new HalfEdge(d);
            HalfEdge ad = new HalfEdge(a);

            ab.Twin     = ba;
            ab.Next     = bc;
            ab.Previous = da;

            bc.Twin     = cb;
            bc.Next     = cd;
            bc.Previous = ab;

            cd.Twin     = dc;
            cd.Next     = da;
            cd.Previous = bc;

            da.Twin     = ad;
            da.Next     = ab;
            da.Previous = cd;

            Face face = new Face(0, Auxilaries.RandomNormal());

            face.AddOuterComponent(bc);
            face.AddOuterComponent(cd);
            face.AddOuterComponent(da);
            face.AddOuterComponent(ab);

            ReadOnlyCollection <Vertex> expected = new List <Vertex> {
                a, b, c, d
            }.AsReadOnly();
            ReadOnlyCollection <Vertex> actual = face.Vertices;

            Assert.That(actual, Is.EquivalentTo(expected));
        }
Example #15
0
        public void Test_Centroid_RectangularFace()
        {
            Vertex a = new Vertex(new Vector3(1, 2, 3));
            Vertex b = new Vertex(new Vector3(3, 9, -1));
            Vertex c = new Vertex(new Vector3(4, 4, -7));
            Vertex d = new Vertex(new Vector3(5, 7, 5));

            HalfEdge ab = new HalfEdge(a);
            HalfEdge ba = new HalfEdge(b);

            HalfEdge bc = new HalfEdge(b);
            HalfEdge cb = new HalfEdge(c);

            HalfEdge cd = new HalfEdge(c);
            HalfEdge dc = new HalfEdge(d);

            HalfEdge da = new HalfEdge(d);
            HalfEdge ad = new HalfEdge(a);

            ab.Twin     = ba;
            ab.Next     = bc;
            ab.Previous = da;

            bc.Twin     = cb;
            bc.Next     = cd;
            bc.Previous = ab;

            cd.Twin     = dc;
            cd.Next     = da;
            cd.Previous = bc;

            da.Twin     = ad;
            da.Next     = ab;
            da.Previous = cd;

            Face face = new Face(0, Auxilaries.RandomNormal());

            face.AddOuterComponent(bc);
            face.AddOuterComponent(cd);
            face.AddOuterComponent(da);
            face.AddOuterComponent(ab);

            Vector3 actual   = face.Centroid;
            Vector3 expected = new Vector3(13, 22, 0) * (1.0f / 4.0f);

            Assert.IsTrue(expected == actual);
        }
Example #16
0
        public void TestIsTriangular_Rectangle()
        {
            Vertex a = Auxilaries.RandomVertex();
            Vertex b = Auxilaries.RandomVertex();
            Vertex c = Auxilaries.RandomVertex();
            Vertex d = Auxilaries.RandomVertex();

            HalfEdge ab = new HalfEdge(a);
            HalfEdge ba = new HalfEdge(b);

            HalfEdge bc = new HalfEdge(b);
            HalfEdge cb = new HalfEdge(c);

            HalfEdge cd = new HalfEdge(c);
            HalfEdge dc = new HalfEdge(d);

            HalfEdge da = new HalfEdge(d);
            HalfEdge ad = new HalfEdge(a);

            ab.Twin     = ba;
            ab.Next     = bc;
            ab.Previous = da;

            bc.Twin     = cb;
            bc.Next     = cd;
            bc.Previous = ab;

            cd.Twin     = dc;
            cd.Next     = da;
            cd.Previous = bc;

            da.Twin     = ad;
            da.Next     = ab;
            da.Previous = cd;

            Face rectangle = new Face(0, Auxilaries.RandomNormal());

            rectangle.AddOuterComponent(bc);
            rectangle.AddOuterComponent(cd);
            rectangle.AddOuterComponent(da);
            rectangle.AddOuterComponent(ab);

            Assert.IsFalse(rectangle.IsTriangular());
        }
Example #17
0
        public void TestArea_NotTriangle_Helper()
        {
            Vertex a = Auxilaries.RandomVertex();
            Vertex b = Auxilaries.RandomVertex();
            Vertex c = Auxilaries.RandomVertex();
            Vertex d = Auxilaries.RandomVertex();

            HalfEdge ab = new HalfEdge(a);
            HalfEdge ba = new HalfEdge(b);

            HalfEdge bc = new HalfEdge(b);
            HalfEdge cb = new HalfEdge(c);

            HalfEdge cd = new HalfEdge(c);
            HalfEdge dc = new HalfEdge(d);

            HalfEdge da = new HalfEdge(d);
            HalfEdge ad = new HalfEdge(a);

            ab.Twin     = ba;
            ab.Next     = bc;
            ab.Previous = da;

            bc.Twin     = cb;
            bc.Next     = cd;
            bc.Previous = ab;

            cd.Twin     = dc;
            cd.Next     = da;
            cd.Previous = bc;

            da.Twin     = ad;
            da.Next     = ab;
            da.Previous = cd;

            Face rectangle = new Face(0, Auxilaries.RandomNormal());

            rectangle.AddOuterComponent(bc);
            rectangle.AddOuterComponent(cd);
            rectangle.AddOuterComponent(da);
            rectangle.AddOuterComponent(ab);

            float area = rectangle.Area;
        }
Example #18
0
        public void TestEquals_NotEqualDifferentNormals()
        {
            HalfEdge a = Auxilaries.RandomHalfEdge();
            HalfEdge b = Auxilaries.RandomHalfEdge();

            Face thisFace = new Face(0, Auxilaries.RandomNormal());

            thisFace.AddOuterComponent(a);
            thisFace.AddOuterComponent(b);

            Face otherFace = new Face(0, Auxilaries.RandomNormal());

            thisFace.AddOuterComponent(a);
            thisFace.AddOuterComponent(b);

            Assert.IsFalse(thisFace.Equals(otherFace));
            Assert.IsFalse(otherFace.Equals(thisFace));
            Assert.AreNotEqual(thisFace.GetHashCode(), otherFace.GetHashCode());
        }
Example #19
0
        public void TestAddIncidentEdges_TwinsAndNextAndPreviousOuterComponentSet()
        {
            Vertex v1 = Auxilaries.RandomVertex();
            Vertex v2 = Auxilaries.RandomVertex();
            Vertex v3 = Auxilaries.RandomVertex();

            HalfEdge e11 = new HalfEdge(v1);
            HalfEdge e12 = new HalfEdge(v2);
            HalfEdge e31 = new HalfEdge(v3);
            HalfEdge e32 = new HalfEdge(v1);
            HalfEdge e41 = new HalfEdge(v3);
            HalfEdge e42 = new HalfEdge(v2);

            e11.Twin = e12;
            e12.Twin = e11;
            e31.Twin = e32;
            e32.Twin = e31;
            e41.Twin = e42;
            e42.Twin = e41;


            e12.Next = e32;
            e32.Next = e41;
            e41.Next = e12;

            e12.Previous = e41;
            e32.Previous = e12;
            e41.Previous = e32;

            Face f2 = new Face(2, Auxilaries.RandomNormal());

            f2.AddOuterComponent(e32);
            f2.AddOuterComponent(e41);
            f2.AddOuterComponent(e12);

            v1.AddIncidentEdge(e32);

            Assert.Contains(e32, v1.IncidentEdges);
        }
Example #20
0
        public void TestArea_Triangle()
        {
            Vertex a = new Vertex(new Vector3(1, 2, 3));
            Vertex b = new Vertex(new Vector3(3, 9, -1));
            Vertex c = new Vertex(new Vector3(4, 4, -7));

            HalfEdge ab = new HalfEdge(a);
            HalfEdge ac = new HalfEdge(a);

            HalfEdge ba = new HalfEdge(b);
            HalfEdge bc = new HalfEdge(b);

            HalfEdge ca = new HalfEdge(c);
            HalfEdge cb = new HalfEdge(c);

            ab.Twin = ba;
            ac.Twin = ca;

            ba.Twin = ab;
            bc.Twin = cb;

            ca.Twin = ac;
            cb.Twin = bc;

            Face triangle = new Face(0, Auxilaries.RandomNormal());

            triangle.AddOuterComponent(ac);
            triangle.AddOuterComponent(cb);
            triangle.AddOuterComponent(ba);

            float expected = 13.405389f;
            float actual   = triangle.Area;

            Assert.That(actual, Is.EqualTo(expected).Within(0.0001f));

            //Check the lazy evaluation, sort of
            Assert.That(triangle.Area, Is.EqualTo(expected).Within(0.0001f));
        }
Example #21
0
        public void Test_Vertices_Triangle()
        {
            Vertex a = new Vertex(new Vector3(1, 2, 3));
            Vertex b = new Vertex(new Vector3(3, 9, -1));
            Vertex c = new Vertex(new Vector3(4, 4, -7));

            HalfEdge ab = new HalfEdge(a);
            HalfEdge ac = new HalfEdge(a);

            HalfEdge ba = new HalfEdge(b);
            HalfEdge bc = new HalfEdge(b);

            HalfEdge ca = new HalfEdge(c);
            HalfEdge cb = new HalfEdge(c);

            ab.Twin = ba;
            ac.Twin = ca;

            ba.Twin = ab;
            bc.Twin = cb;

            ca.Twin = ac;
            cb.Twin = bc;

            Face face = new Face(0, Auxilaries.RandomNormal());

            face.AddOuterComponent(ac);
            face.AddOuterComponent(cb);
            face.AddOuterComponent(ba);

            ReadOnlyCollection <Vertex> expected = new List <Vertex> {
                a, b, c
            }.AsReadOnly();
            ReadOnlyCollection <Vertex> actual = face.Vertices;

            Assert.That(actual, Is.EquivalentTo(expected));
        }
Example #22
0
        public void TestEquals_NotEqualsDifferentIncidentFaces()
        {
            Vertex a = Auxilaries.RandomVertex();
            Vertex b = Auxilaries.RandomVertex();
            Vertex c = Auxilaries.RandomVertex();

            HalfEdge abOther = new HalfEdge(a);
            HalfEdge abThis  = new HalfEdge(a);
            HalfEdge ac      = new HalfEdge(a);

            HalfEdge ba = new HalfEdge(b);
            HalfEdge bc = new HalfEdge(b);

            HalfEdge ca = new HalfEdge(c);
            HalfEdge cb = new HalfEdge(c);

            Vector3 normal = Auxilaries.RandomNormal();

            Face thisFace = new Face(0, normal);

            thisFace.AddOuterComponent(abThis);
            thisFace.AddOuterComponent(bc);
            thisFace.AddOuterComponent(ca);

            Face otherFace = new Face(1, normal);

            otherFace.AddOuterComponent(abOther);

            abThis.IncidentFace  = thisFace;
            abOther.IncidentFace = otherFace;

            abThis.Twin  = ba;
            abOther.Twin = ba;
            ac.Twin      = ca;

            ba.Twin = abThis;
            bc.Twin = bc;

            ca.Twin = ac;
            cb.Twin = bc;

            abThis.Next  = bc;
            abOther.Next = bc;
            ac.Next      = cb;

            ba.Next = ac;
            bc.Next = ca;

            ca.Next = abThis;
            cb.Next = ba;

            abThis.Previous  = ca;
            abOther.Previous = ca;
            ac.Previous      = ba;

            ba.Previous = cb;
            bc.Previous = abThis;

            ca.Previous = bc;
            cb.Previous = ac;

            Assert.AreNotEqual(abThis.GetHashCode(), abOther.GetHashCode());

            Assert.IsFalse(abThis.Equals(abOther));
            Assert.IsFalse(abOther.Equals(abThis));
        }