Example #1
0
 public ActiveEdgeTableEntry(ActiveEdgeTableEntry aete)
 {
     yMax   = aete.yMax;
     yMin   = aete.yMin;
     xOfMax = aete.xOfMax;
     xOfMin = aete.xOfMin + aete.mInv;
     mInv   = aete.mInv;
 }
Example #2
0
        public List <ColorPoint> FillPoints(Rectangle boundingRect = null)
        {
            if (this.points != null && boundingRect == null)
            {
                return(this.points);
            }

            prePoints = new List <Point>();

            int k = 0;
            int i = indicies[k].Key;
            int y, ymin;

            y = ymin = vertices[indicies[0].Key].Y;
            int ymax = vertices[indicies[indicies.Count - 1].Key].Y;

            int len = vertices.Count;

            while (y < ymax)
            {
                while (vertices[i].Y == y)
                {
                    if (vertices[(i - 1 + len) % len].Y > vertices[i].Y)
                    {
                        AET.Add(new ActiveEdgeTableEntry(vertices[i], vertices[(i - 1 + len) % len]));
                    }

                    if (vertices[(i + 1) % len].Y > vertices[i].Y)
                    {
                        AET.Add(new ActiveEdgeTableEntry(vertices[i], vertices[(i + 1) % len]));
                    }

                    i = indicies[++k].Key;
                }

                AET.Sort(delegate(ActiveEdgeTableEntry e1, ActiveEdgeTableEntry e2)
                {
                    return(e1.xOfMin.CompareTo(e2.xOfMin));
                });

                for (int t = 0; t < AET.Count; t += 2)
                {
                    for (int x1 = (int)AET[t].xOfMin; x1 <= AET[(t + 1) % AET.Count].xOfMin; x1++)
                    {
                        if (boundingRect != null && (x1 > boundingRect.GetCorner(1).X || x1 < boundingRect.GetCorner(0).X || y > boundingRect.GetCorner(0).Y || y < boundingRect.GetCorner(2).Y))
                        {
                            continue;
                        }
                        prePoints.Add(new Point(x1, y));
                    }
                }

                ++y;
                for (int t = 0; t < AET.Count; t++)
                {
                    AET[t] = new ActiveEdgeTableEntry(AET[t]);
                    if (AET[t].yMax == y)
                    {
                        AET.RemoveAt(t--);
                    }
                }
            }

            points = new List <ColorPoint>();

            if (fillColor.HasValue)
            {
                foreach (var p in prePoints)
                {
                    points.Add(new ColorPoint(fillColor.Value, p));
                }
            }

            else
            {
                foreach (var kv in fillImage.GetPixels(prePoints, true))
                {
                    points.Add(new ColorPoint(kv.Value, kv.Key));
                }
            }

            return(points);
        }