Пример #1
0
        private PolygonScanner(
            ScanEdgeCollection edgeCollection,
            int maxIntersectionCount,
            int minY,
            int maxY,
            int subsampling,
            IntersectionRule intersectionRule,
            MemoryAllocator allocator)
        {
            this.minY             = minY;
            this.maxY             = maxY;
            this.SubpixelDistance = 1f / subsampling;
            this.SubpixelArea     = this.SubpixelDistance / subsampling;
            this.intersectionRule = intersectionRule;
            this.edgeCollection   = edgeCollection;
            this.edges            = edgeCollection.Edges;
            int edgeCount      = this.edges.Length;
            int dataBufferSize = (edgeCount * 3) + maxIntersectionCount;

            // In case of IntersectionRule.Nonzero, we need more space for intersectionTypes:
            if (intersectionRule == IntersectionRule.Nonzero)
            {
                dataBufferSize += maxIntersectionCount;
            }

            this.dataBuffer = allocator.Allocate <int>(dataBufferSize);
            Span <int>   dataBufferInt32Span = this.dataBuffer.Memory.Span;
            Span <float> dataBufferFloatSpan = MemoryMarshal.Cast <int, float>(dataBufferInt32Span);

            this.sorted0       = dataBufferInt32Span.Slice(0, edgeCount);
            this.sorted1       = dataBufferInt32Span.Slice(edgeCount, edgeCount);
            this.activeEdges   = new ActiveEdgeList(dataBufferInt32Span.Slice(edgeCount * 2, edgeCount));
            this.intersections = dataBufferFloatSpan.Slice(edgeCount * 3, maxIntersectionCount);
            if (intersectionRule == IntersectionRule.Nonzero)
            {
                Span <int> remainder =
                    dataBufferInt32Span.Slice((edgeCount * 3) + maxIntersectionCount, maxIntersectionCount);
                this.intersectionTypes = MemoryMarshal.Cast <int, NonZeroIntersectionType>(remainder);
            }
            else
            {
                this.intersectionTypes = default;
            }

            this.idx0       = 0;
            this.idx1       = 0;
            this.PixelLineY = minY - 1;
            this.SubPixelY  = default;
            this.yPlusOne   = default;
        }
Пример #2
0
        public static PolygonScanner Create(
            IPath polygon,
            int minY,
            int maxY,
            int subsampling,
            IntersectionRule intersectionRule,
            MemoryAllocator allocator)
        {
            var multipolygon = TessellatedMultipolygon.Create(polygon, allocator);
            var edges        = ScanEdgeCollection.Create(multipolygon, allocator, subsampling);
            var scanner      = new PolygonScanner(edges, multipolygon.TotalVertexCount * 2, minY, maxY, subsampling, intersectionRule, allocator);

            scanner.Init();
            return(scanner);
        }