コード例 #1
0
        private void Init()
        {
            // Reuse memory buffers of 'intersections' and 'activeEdges' for key-value sorting,
            // since that region is unused at initialization time.
            Span <float> keys0 = this.intersections.Slice(0, this.sorted0.Length);
            Span <float> keys1 = MemoryMarshal.Cast <int, float>(this.activeEdges.Buffer);

            for (int i = 0; i < this.edges.Length; i++)
            {
                ref ScanEdge edge = ref this.edges[i];
                keys0[i]        = edge.Y0;
                keys1[i]        = edge.Y1;
                this.sorted0[i] = i;
                this.sorted1[i] = i;
            }
コード例 #2
0
        public Span <float> ScanOddEven(float y, Span <ScanEdge> edges, Span <float> intersections)
        {
            DebugGuard.MustBeLessThanOrEqualTo(edges.Length, MaxEdges, "edges.Length");

            int intersectionCounter = 0;
            int offset = 0;

            Span <int> active = this.ActiveEdges;

            for (int i = 0; i < active.Length; i++)
            {
                int          flaggedIdx = active[i];
                int          edgeIdx    = Strip(flaggedIdx);
                ref ScanEdge edge       = ref edges[edgeIdx];
                float        x          = edge.GetX(y);
                if (IsEntering(flaggedIdx))
                {
                    Emit(x, edge.EmitV0, intersections, ref intersectionCounter);
                }
                else if (IsLeaving(flaggedIdx))
                {
                    Emit(x, edge.EmitV1, intersections, ref intersectionCounter);

                    offset++;

                    // Do not offset:
                    continue;
                }
                else
                {
                    // Emit once:
                    intersections[intersectionCounter++] = x;
                }

                // Unmask and offset:
                active[i - offset] = edgeIdx;
            }