Пример #1
0
        public static List MakeCentroidNet(this PlainShape self, Allocator allocator, IntGeom intGeom, float maxEdge, float maxArea = 0, float minArea = 0, bool onlyConvex = false)
        {
            long  iEdge    = intGeom.Int(maxEdge);
            var   delaunay = self.Delaunay(iEdge, Allocator.Temp);
            float aMaxArea;

            if (maxArea > 0)
            {
                aMaxArea = maxArea;
            }
            else
            {
                aMaxArea = 0.4f * maxEdge * maxEdge;
            }

            delaunay.Tessellate(intGeom, aMaxArea);

            var iMinArea = intGeom.SqrInt(minArea);
            var shape    = delaunay.MakeCentroidNet(Allocator.Temp, iMinArea, onlyConvex);

            delaunay.Dispose();

            int n           = shape.layouts.Length;
            var dynamicList = new DynamicList(8 * n, n, allocator);

            for (int i = 0; i < n; ++i)
            {
                var iPath   = shape.Get(i);
                var path    = intGeom.Float(iPath, Allocator.Temp);
                var polygon = new Polygon(path, Allocator.Temp);
                dynamicList.Add(polygon);
            }

            shape.Dispose();

            return(dynamicList.Convert());
        }
Пример #2
0
        public void Test_00()
        {
            var data = BreakerTestData.data[0];

            var nPoints = new NativeArray <Vector2>(data, allocator);
            var iPoints = iGeom.Int(nPoints, allocator);

            var pShape = new PlainShape(iPoints, true, allocator);

            iPoints.Dispose();


            var indices = pShape.DelaunayTriangulate(allocator);

            pShape.Dispose();

            var triangles = TrianglesBuilder.build(nPoints, indices, allocator);

            indices.Dispose();
            nPoints.Dispose();

            var breaker0  = new BreakSolver(5, 300, BreakSolver.SmallSpawnStrategy.no);
            var polygons0 = breaker0.Divide(triangles, allocator);

            Assert.AreEqual(polygons0.Count, 3);

            Assert.AreEqual(polygons0.Get(0, allocator).Convert().isEqual(new[] {
                new Vector2(2.0710678f, 0.0f),
                new Vector2(-2.0710678f, 0.0f),
                new Vector2(-5.0f, 5.0f),
                new Vector2(-2.0710678f, 7.928932f),
                new Vector2(2.0710678f, 7.928932f),
                new Vector2(5.0f, 5.0f)
            }, 0.001f), true);

            Assert.AreEqual(polygons0.Get(1, allocator).Convert().isEqual(new[] {
                new Vector2(-4.1628227f, 3.570849f),
                new Vector2(-3.1991942f, 1.9258323f),
                new Vector2(-4.597563f, 0.0f),
                new Vector2(-6.504041f, 0.0f),
                new Vector2(-7.6229224f, 2.3770776f),
                new Vector2(-6.2748384f, 3.7251613f)
            }, 0.001f), true);

            Assert.AreEqual(polygons0.Get(2, allocator).Convert().isEqual(new[] {
                new Vector2(3.199194f, 1.925832f),
                new Vector2(4.1628222f, 3.5708487f),
                new Vector2(6.2748384f, 3.7251616f),
                new Vector2(7.622922f, 2.3770778f),
                new Vector2(6.504041f, 0.0f),
                new Vector2(4.597563f, 0.0f)
            }, 0.001f), true);

            polygons0.Dispose();

            var breaker1  = new BreakSolver(1.5f, 10, BreakSolver.SmallSpawnStrategy.no);
            var polygons1 = breaker1.Divide(triangles, allocator);

            Assert.AreEqual(polygons1.Count > 3, true);

            triangles.Dispose();
        }