Ejemplo n.º 1
0
        private static void InterpolateX(
            int y,
            RasterizerPoint a, RasterizerPoint b,
            int notUsedIndex,
            out RasterizerResult result
            )
        {
            int dY     = b.Y - a.Y;
            var ratio  = (y - a.Y) / (float)(dY != 0 ? dY : 1);
            var iratio = 1 - ratio;
            var x      = ratio.Interpolate(a.X, b.X);

            switch (notUsedIndex)
            {
            case 0:
                result = new RasterizerResult(x, new Vector3(0, iratio, ratio));
                return;

            case 1:
                result = new RasterizerResult(x, new Vector3(iratio, 0, ratio));
                return;

            case 2:
                result = new RasterizerResult(x, new Vector3(iratio, ratio, 0));
                return;

            default:
                throw new Exception();
            }
        }
Ejemplo n.º 2
0
        private void AdjustX(ref RasterizerResult r0, ref RasterizerResult r1)
        {
            if (r0.X > r1.X)
            {
                Swap(ref r0, ref r1);
            }

            var rx0 = r0.X;
            var rx1 = r1.X;

            if (rx0 < xmin || rx0 > xmax || rx1 < xmin || rx1 > xmax)
            {
                var x0 = rx0.Clamp(xmin, xmax);
                var x1 = rx1.Clamp(xmin, xmax);

                r0 = new RasterizerResult(x0, Vector3.Lerp(r0.Ratios, r1.Ratios, x0.RatioInRange(rx0, rx1)));
                r1 = new RasterizerResult(x1, Vector3.Lerp(r0.Ratios, r1.Ratios, x1.RatioInRange(rx0, rx1)));
            }
        }
Ejemplo n.º 3
0
        public void RasterizeLine(
            RasterizerPoint p0, RasterizerPoint p1, T param
            )
        {
            // ReSharper disable InvocationIsSkipped
            Debug.Assert(p0.Y <= p1.Y);

            var y0 = p0.Y.Clamp(ymin, ymax);
            var y1 = p1.Y.Clamp(ymin, ymax);

            for (var y = y0; y < y1; y++)
            {
                var ratio0 = y.RatioInRange(y0, y1);
                var ratio1 = (y + 1).RatioInRange(y0, y1);
                var vx0    = ratio0.Interpolate(p0.X, p1.X);
                var vx1    = ratio1.Interpolate(p0.X, p1.X) + 1;
                var r0     = new RasterizerResult(vx0, new Vector3(ratio0));
                var r1     = new RasterizerResult(vx1, new Vector3(ratio1));
                AdjustX(ref r0, ref r1);
                rowHandler(y, ref r0, ref r1, ref param);
            }
        }