示例#1
0
        private static void CheckPolygonsDiamond(PointD[][] polygons, Subdivision division)
        {
            var edges = division.Edges.Values;
            var faces = division.Faces.Values;

            CollectionAssert.AreEqual(new[] {
                new VertexPair(polygons[0][0], edges[0]),
                new VertexPair(polygons[0][1], edges[1]),
                new VertexPair(polygons[0][3], edges[5]),
                new VertexPair(polygons[1][3], edges[9]),
                new VertexPair(polygons[2][3], edges[13]),
                new VertexPair(polygons[0][2], edges[3]),
            }, division.Vertices);

            CollectionAssert.AreEqual(new[] {
                new SubdivisionEdge(0, polygons[0][0], edges[1], faces[0], edges[2], edges[14]),
                new SubdivisionEdge(1, polygons[0][1], edges[0], faces[1], edges[7], edges[3]),
                new SubdivisionEdge(2, polygons[0][1], edges[3], faces[0], edges[12], edges[0]),
                new SubdivisionEdge(3, polygons[0][2], edges[2], faces[1], edges[1], edges[5]),
                new SubdivisionEdge(4, polygons[0][2], edges[5], faces[2], edges[6], edges[9]),
                new SubdivisionEdge(5, polygons[0][3], edges[4], faces[1], edges[3], edges[7]),
                new SubdivisionEdge(6, polygons[0][3], edges[7], faces[2], edges[11], edges[4]),
                new SubdivisionEdge(7, polygons[0][0], edges[6], faces[1], edges[5], edges[1]),
                new SubdivisionEdge(8, polygons[0][2], edges[9], faces[3], edges[10], edges[13]),
                new SubdivisionEdge(9, polygons[1][3], edges[8], faces[2], edges[4], edges[11]),
                new SubdivisionEdge(10, polygons[1][3], edges[11], faces[3], edges[15], edges[8]),
                new SubdivisionEdge(11, polygons[0][0], edges[10], faces[2], edges[9], edges[6]),
                new SubdivisionEdge(12, polygons[0][2], edges[13], faces[0], edges[14], edges[2]),
                new SubdivisionEdge(13, polygons[2][3], edges[12], faces[3], edges[8], edges[15]),
                new SubdivisionEdge(14, polygons[2][3], edges[15], faces[0], edges[0], edges[12]),
                new SubdivisionEdge(15, polygons[0][0], edges[14], faces[3], edges[13], edges[10]),
            }, edges);

            CollectionAssert.AreEqual(new[] {
                new SubdivisionFace(division, 0, null, new[] { edges[0] }),
                new SubdivisionFace(division, 1, edges[1], null),
                new SubdivisionFace(division, 2, edges[4], null),
                new SubdivisionFace(division, 3, edges[8], null),
            }, faces);

            CheckFace(edges[0], new[] {
                polygons[0][0], polygons[0][1], polygons[0][2], polygons[2][3]
            }, -48, PointD.Empty);
            CheckFace(edges[1], new[] {
                polygons[0][1], polygons[0][0], polygons[0][3], polygons[0][2]
            }, +12, new PointD(-3, 0));
            CheckFace(edges[6], new[] {
                polygons[0][3], polygons[0][0], polygons[1][3], polygons[0][2]
            }, +24, PointD.Empty);
            CheckFace(edges[10], new[] {
                polygons[1][3], polygons[0][0], polygons[2][3], polygons[0][2]
            }, +12, new PointD(3, 0));

            var cycles = division.GetZeroAreaCycles();

            Assert.AreEqual(0, cycles.Count);
        }
        private static void CheckLinesStar(PointD[] points, Subdivision division)
        {
            var edges = division.Edges.Values;
            var faces = division.Faces.Values;

            CollectionAssert.AreEqual(new[] {
                new VertexPair(points[0], edges[0]),
                new VertexPair(points[4], edges[6]),
                new VertexPair(points[1], edges[1]),
                new VertexPair(points[2], edges[3]),
                new VertexPair(points[3], edges[5]),
            }, division.Vertices);

            CollectionAssert.AreEqual(new[] {
                new SubdivisionEdge(0, points[0], edges[1], faces[0], edges[2], edges[1]),
                new SubdivisionEdge(1, points[1], edges[0], faces[0], edges[0], edges[6]),
                new SubdivisionEdge(2, points[1], edges[3], faces[0], edges[3], edges[0]),
                new SubdivisionEdge(3, points[2], edges[2], faces[0], edges[4], edges[2]),
                new SubdivisionEdge(4, points[1], edges[5], faces[0], edges[5], edges[3]),
                new SubdivisionEdge(5, points[3], edges[4], faces[0], edges[7], edges[4]),
                new SubdivisionEdge(6, points[4], edges[7], faces[0], edges[1], edges[7]),
                new SubdivisionEdge(7, points[1], edges[6], faces[0], edges[6], edges[5]),
            }, edges);

            CollectionAssert.AreEqual(new[] {
                new SubdivisionFace(division, 0, null, new[] { edges[0] }),
            }, faces);

            CheckFace(edges[0], new[] {
                points[0], points[1], points[2], points[1],
                points[3], points[1], points[4], points[1]
            }, 0, PointD.Empty);

            var cycles = division.GetZeroAreaCycles();

            Assert.AreEqual(1, cycles.Count);
            Assert.AreEqual(edges[0], cycles[0]);
        }
        public static Subdivision CreateTriforce(bool test)
        {
            PointD[] points =
            {
                new PointD(-5, -4), new PointD(0,  6), new PointD(5, -4),
                new PointD(0,   0), new PointD(-1, 2), new PointD(1, 2)
            };
            LineD[] lines =
            {
                new LineD(points[0], points[1]), new LineD(points[2], points[1]),
                new LineD(points[0], points[2]), new LineD(points[3], points[4]),
                new LineD(points[3], points[5]), new LineD(points[4], points[5])
            };

            Subdivision division = Subdivision.FromLines(lines);

            division.Validate();
            if (!test)
            {
                return(division);
            }

            CollectionAssert.AreEquivalent(lines, division.ToLines());
            var edges = division.Edges.Values;
            var faces = division.Faces.Values;

            CollectionAssert.AreEqual(new[] {
                new VertexPair(points[0], edges[0]),
                new VertexPair(points[2], edges[2]),
                new VertexPair(points[3], edges[6]),
                new VertexPair(points[4], edges[7]),
                new VertexPair(points[5], edges[9]),
                new VertexPair(points[1], edges[1]),
            }, division.Vertices);

            CollectionAssert.AreEqual(new[] {
                new SubdivisionEdge(0, points[0], edges[1], faces[0], edges[3], edges[5]),
                new SubdivisionEdge(1, points[1], edges[0], faces[1], edges[4], edges[2]),
                new SubdivisionEdge(2, points[2], edges[3], faces[1], edges[1], edges[4]),
                new SubdivisionEdge(3, points[1], edges[2], faces[0], edges[5], edges[0]),
                new SubdivisionEdge(4, points[0], edges[5], faces[1], edges[2], edges[1]),
                new SubdivisionEdge(5, points[2], edges[4], faces[0], edges[0], edges[3]),
                new SubdivisionEdge(6, points[3], edges[7], faces[1], edges[10], edges[9]),
                new SubdivisionEdge(7, points[4], edges[6], faces[2], edges[8], edges[11]),
                new SubdivisionEdge(8, points[3], edges[9], faces[2], edges[11], edges[7]),
                new SubdivisionEdge(9, points[5], edges[8], faces[1], edges[6], edges[10]),
                new SubdivisionEdge(10, points[4], edges[11], faces[1], edges[9], edges[6]),
                new SubdivisionEdge(11, points[5], edges[10], faces[2], edges[7], edges[8]),
            }, edges);

            CollectionAssert.AreEqual(new[] {
                new SubdivisionFace(division, 0, null, new[] { edges[0] }),
                new SubdivisionFace(division, 1, edges[1], new[] { edges[6] }),
                new SubdivisionFace(division, 2, edges[7], null),
            }, faces);

            PointD centroid = new PointD(0, -2 / 3.0);

            CheckFace(edges[0], new[] { points[0], points[1], points[2] }, -50, centroid);
            CheckFace(edges[1], new[] { points[1], points[0], points[2] }, +50, centroid);

            centroid = new PointD(0, 4 / 3.0);
            CheckFace(edges[6], new[] { points[3], points[4], points[5] }, -2, centroid);
            CheckFace(edges[7], new[] { points[4], points[3], points[5] }, +2, centroid);

            var cycles = division.GetZeroAreaCycles();

            Assert.AreEqual(0, cycles.Count);
            return(division);
        }