Exemple #1
0
        private NativeArray <int> Triangulate(int index)
        {
            var iGeom = IntGeom.DefGeom;

            var data = ComplexTests.data[index];

            var hull  = iGeom.Int(data[0]);
            var holes = new IntVector[data.Length - 1][];

            for (int i = 1; i < data.Length; ++i)
            {
                holes[i - 1] = iGeom.Int(data[i]);
            }

            var iShape = new IntShape(hull, holes);
            var pShape = new PlainShape(iShape, Allocator.Temp);

            var triangles = pShape.Triangulate(Allocator.Temp);

            Assert.IsTrue(Triangle.IsCCW(pShape.points, triangles));

            pShape.Dispose();

            return(triangles);
        }
        private NativeArray <int> Triangulate(int index)
        {
            var iGeom = IntGeom.DefGeom;

            var data    = MonotoneTests.data[index];
            var iPoints = iGeom.Int(data);

            var iShape = new IntShape(iPoints, new IntVector[0][]);
            var pShape = new PlainShape(iShape, Allocator.Temp);

            var triangles = pShape.Triangulate(Allocator.Temp);

            Assert.IsTrue(Triangle.IsCCW(pShape.points, triangles));

            pShape.Dispose();

            return(triangles);
        }
Exemple #3
0
        public PlainShape(IntShape iShape, Allocator allocator)
        {
            var count = iShape.hull.Length;

            for (int j = 0; j < iShape.holes.Length; ++j)
            {
                count += iShape.holes[j].Length;
            }

            this.points  = new NativeArray <IntVector>(count, allocator);
            this.layouts = new NativeArray <PathLayout>(iShape.holes.Length + 1, allocator);

            int layoutCounter = 0;

            int start = 0;
            int end   = iShape.hull.Length - 1;

            int pointCounter = 0;

            for (int k = 0; k < iShape.hull.Length; ++k)
            {
                this.points[pointCounter++] = iShape.hull[k];
            }

            var layout = new PathLayout(start, iShape.hull.Length, true);

            this.layouts[layoutCounter++] = layout;

            start = end + 1;

            for (int j = 0; j < iShape.holes.Length; ++j)
            {
                var hole = iShape.holes[j];
                end = start + hole.Length - 1;
                for (int k = 0; k < hole.Length; ++k)
                {
                    this.points[pointCounter++] = hole[k];
                }

                this.layouts[layoutCounter++] = new PathLayout(start, hole.Length, false);

                start = end + 1;
            }
        }
        public void Invoke(NativeArray <Vector2> hull, NativeArray <Vector2> hole, bool isDelaunay)
        {
            var iGeom = IntGeom.DefGeom;

            var iHull  = iGeom.Int(hull.ToArray());
            var iHoles = new[] { iGeom.Int(hole.ToArray()) };

            var iShape = new IntShape(iHull, iHoles);
            var pShape = new PlainShape(iShape, Allocator.TempJob);

            int totalCount = pShape.points.Length * 3;

            var triangles = new NativeArray <int>(totalCount, Allocator.TempJob);
            var length    = new NativeArray <int>(1, Allocator.TempJob);

            this.job = new TriangulationJob {
                plainShape = pShape,
                isDelaunay = isDelaunay,
                triangles  = triangles,
                length     = length
            };

            this.jobHandle = this.job.Schedule();
        }