Пример #1
0
        public void BrushLine(Canvas.Pixel _p1, Canvas.Pixel _p2, Canvas.Brush _brush)
        {
            var bh = new Bresenham(_p1, _p2);

            do
            {
                Paint(bh.Current, _brush);
            } while (bh.MoveNext());
        }
Пример #2
0
        public static HashSet <Pixel> StageLine(Pixel _p1, Pixel _p2)
        {
            var pixels = new HashSet <Pixel>();
            var bh     = new Bresenham(_p1, _p2);

            do
            {
                pixels.Add(bh.Current);
            } while (bh.MoveNext());

            return(pixels);
        }
Пример #3
0
        public static HashSet <Pixel> StageTriangle(Pixel _p1, Pixel _p2, Pixel _p3)
        {
            var vertices = new[]
            {
                _p1, _p2, _p3
            };

            // Sort by y
            Array.Sort(vertices, (_a, _b) => _a.y.CompareTo(_b.y));

            var bhLong   = new Bresenham(vertices[0], vertices[2]);
            var bhShortA = new Bresenham(vertices[0], vertices[1]);
            var bhShortB = new Bresenham(vertices[1], vertices[2]);

            var curY         = bhLong.Current.y;
            var stagedPixels = new HashSet <Pixel> {
                bhLong.Current
            };

            do
            {
                if (!bhShortA.End)
                {
                    do
                    {
                        bhLong.MoveNext();
                    } while (bhLong.Current.y == curY && !bhLong.End);
                    do
                    {
                        bhShortA.MoveNext();
                    } while (bhShortA.Current.y == curY && !bhShortA.End);
                    //Debug
                    if (bhLong.Previous.y != bhShortA.Previous.y)
                    {
                        throw new Exception("Y Mismatch");
                    }
                    stagedPixels.UnionWith(StageLineHorizontal(curY, bhLong.Previous.x, bhShortA.Previous.x));
                    curY = bhLong.Current.y;
                }
                else
                {
                    do
                    {
                        bhShortB.MoveNext();
                    } while (bhShortB.Current.y != bhLong.Current.y && !bhShortB.End);
                    //Debug
                    if (bhLong.Previous.y != bhShortB.Previous.y)
                    {
                        throw new Exception("Y Mismatch");
                    }
                    stagedPixels.UnionWith(StageLineHorizontal(curY, bhLong.Previous.x, bhShortB.Previous.x));

                    do
                    {
                        bhLong.MoveNext();
                    } while (bhLong.Current.y == curY && !bhLong.End);
                    curY = bhLong.Current.y;
                }
            } while (!bhLong.End);

            return(stagedPixels);
        }