public void ReplaceAt(int index, NativeSlice <IntVector> path)
        {
            var oldLayout = this.layouts[index];
            var newLayout = new PathLayout(oldLayout.begin, path.Length, oldLayout.isClockWise);

            if (newLayout.length == oldLayout.length)
            {
                this.points.Slice(oldLayout.begin, oldLayout.length).CopyFrom(path);
            }
            else if (index + 1 == this.layouts.Count)
            {
                this.layouts[index] = newLayout;
                this.points.RemoveLast(oldLayout.length);
                this.points.Add(path);
            }
            else
            {
                this.layouts[index] = newLayout;
                int shift         = newLayout.length - oldLayout.length;
                int oldTailLength = this.points.Count - oldLayout.end - 1;
                this.points.Shift(shift);

                this.points.Slice(newLayout.end + 1, oldTailLength).CopyFrom(this.points.Slice(oldLayout.end + 1, oldTailLength));
                this.points.Slice(newLayout.begin, newLayout.length).CopyFrom(path);

                for (int i = index + 1; i < this.layouts.Count; ++i)
                {
                    var lt = this.layouts[i];
                    this.layouts[i] = new PathLayout(lt.begin + shift, lt.length, lt.isClockWise);
                }
            }
        }
        public void Add(NativeSlice <IntVector> path, bool isClockWise)
        {
            int begin  = points.Count;
            var layout = new PathLayout(begin, path.Length, isClockWise);

            this.points.Add(path);
            this.layouts.Add(layout);
        }
Beispiel #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;
            }
        }