Пример #1
0
        public void FindNearestEdge()
        {
            var division = SubdivisionFromLines.CreateSquareStar(false);
            var edges    = division.Edges.Values;
            var faces    = division.Faces.Values;

            double distance;

            Assert.AreEqual(edges[0], division.FindNearestEdge(new PointD(-1.1, 0), out distance));
            Assert.AreEqual(edges[1], division.FindNearestEdge(new PointD(-0.9, 0), out distance));
            Assert.AreEqual(edges[2], division.FindNearestEdge(new PointD(0, 2.1), out distance));
            Assert.AreEqual(edges[3], division.FindNearestEdge(new PointD(0, 1.9), out distance));
            Assert.AreEqual(edges[4], division.FindNearestEdge(new PointD(0.9, 0), out distance));
            Assert.AreEqual(edges[5], division.FindNearestEdge(new PointD(1.1, 0), out distance));
            Assert.AreEqual(edges[6], division.FindNearestEdge(new PointD(0, -1.9), out distance));
            Assert.AreEqual(edges[7], division.FindNearestEdge(new PointD(0, -2.1), out distance));

            Assert.AreEqual(edges[8], division.FindNearestEdge(new PointD(-0.5, -1.1), out distance));
            Assert.AreEqual(edges[9], division.FindNearestEdge(new PointD(-0.5, -0.9), out distance));
            Assert.AreEqual(edges[10], division.FindNearestEdge(new PointD(-0.5, 0.9), out distance));
            Assert.AreEqual(edges[11], division.FindNearestEdge(new PointD(-0.5, 1.1), out distance));
            Assert.AreEqual(edges[12], division.FindNearestEdge(new PointD(0.5, 1.1), out distance));
            Assert.AreEqual(edges[13], division.FindNearestEdge(new PointD(0.5, 0.9), out distance));
            Assert.AreEqual(edges[14], division.FindNearestEdge(new PointD(0.5, -0.9), out distance));
            Assert.AreEqual(edges[15], division.FindNearestEdge(new PointD(0.5, -1.1), out distance));
        }
Пример #2
0
        public void StructureEquals()
        {
            var division = SubdivisionFromLines.CreateTriforce(false);

            division.Validate();

            // check overall structural equality
            var clone = (Subdivision)division.Clone();

            clone.Validate();
            Assert.IsTrue(division.StructureEquals(clone));

            // check individual edges
            Assert.AreEqual(division.Edges.Count, clone.Edges.Count);
            for (int i = 0; i < division.Edges.Count; i++)
            {
                var edge      = division.Edges.GetByIndex(i);
                var cloneEdge = clone.Edges.GetByIndex(i);

                Assert.AreNotEqual(edge, cloneEdge);
                Assert.IsTrue(edge.StructureEquals(cloneEdge));
            }

            // check individual faces
            var faces      = division.Faces.Values;
            var cloneFaces = clone.Faces.Values;

            Assert.AreEqual(faces.Count, cloneFaces.Count);

            for (int i = 0; i < faces.Count; i++)
            {
                Assert.AreNotEqual(faces[i], cloneFaces[i]);
                Assert.IsTrue(faces[i].StructureEquals(cloneFaces[i]));
            }
        }
Пример #3
0
        public void FindFacePoint()
        {
            var division = SubdivisionFromLines.CreateSquareStar(false);
            var faces    = division.Faces.Values;

            Assert.AreEqual(faces[0], division.FindFace(new PointD(-2, 0)));
            Assert.AreEqual(faces[1], division.FindFace(new PointD(-0.5, 0)));
            Assert.AreEqual(faces[2], division.FindFace(new PointD(0, 0.5)));
            Assert.AreEqual(faces[3], division.FindFace(new PointD(0.5, 0)));
            Assert.AreEqual(faces[4], division.FindFace(new PointD(0, -0.5)));

            // four nested triangles
            PointD[][] polygons =
            {
                new[] { new PointD(-8, -8), new PointD(0, 8), new PointD(8, -8) },
                new[] { new PointD(-6, -6), new PointD(0, 6), new PointD(6, -6) },
                new[] { new PointD(-4, -4), new PointD(0, 4), new PointD(4, -4) },
                new[] { new PointD(-2, -2), new PointD(0, 2), new PointD(2, -2) }
            };
            division = Subdivision.FromPolygons(polygons);
            division.Validate();
            faces = division.Faces.Values;

            Assert.AreEqual(faces[0], division.FindFace(new PointD(0, 10)));
            Assert.AreEqual(faces[1], division.FindFace(new PointD(0, 7)));
            Assert.AreEqual(faces[2], division.FindFace(new PointD(0, 5)));
            Assert.AreEqual(faces[3], division.FindFace(new PointD(0, 3)));
            Assert.AreEqual(faces[4], division.FindFace(new PointD(0, 1)));
        }
        public void FromLines()
        {
            Subdivision division = SubdivisionFromLines.CreateSquareStar(false);

            CheckSearch(division);

            division = SubdivisionFromLines.CreateTriforce(false);
            CheckSearch(division);
        }