private void buildActiveList(ref SortedDoublyLinkedList <CActiveEdge> dest, ref SortedDoublyLinkedList <CActiveEdge> source) { foreach (var edge in source) { dest.Add(edge); } }
public void ScanLineFillPolygon(Graphics graph, PolygonBase shape, Color color) { if (shape.Vertices.Count < 3) { return; } if (shape.GetShapeType() == ShapeType.FreePencil) { return; } var rec = new Rectangle(Point.Round(shape.Location), Size.Round(shape.Size)); if (rec.Location.Equals(Point.Empty)) { return; } rec.X -= 1; rec.Y -= 1; rec.Width += 2; rec.Height += 2; //var h = rec.Y + 1; var h = rec.Y + rec.Height; var et = new SortedDoublyLinkedList <CActiveEdge> [h]; var active = new SortedDoublyLinkedList <CActiveEdge>(); for (int i = 0; i < h; i++) { et[i] = new SortedDoublyLinkedList <CActiveEdge>(); } BuildEdgeList(shape.Vertices.ToList(), ref et); //for (int i = rec.Y - rec.Height; i < rec.Y; i++) for (int i = rec.Y; i < rec.Y + rec.Height; i++) { buildActiveList(ref active, ref et[i]); if (active.Count != 0) { using (var p = new Pen(color, 1F)) FillScan(i, ref active, graph, p); updateEdgeList(i, ref active); active.Sort(); } } }
private void updateEdgeList(int line, ref SortedDoublyLinkedList <CActiveEdge> ae) { var p = ae.First; while (p != null) { if (line >= p.Value.YUper) { ae.Remove(p); } else { p.Value.XIntersection += p.Value.ReciSlope; } p = p.Next; } }
private void FillScan(int line, ref SortedDoublyLinkedList <CActiveEdge> ae, Graphics graph, Pen penline) { var points = new CActiveEdge[2]; int i = 0; foreach (var edge in ae) { points[i] = edge; if (i == 1) { FillLine((int)Math.Round(points[0].XIntersection, 0), (int)Math.Round(points[1].XIntersection, 0), line, graph, penline); } i = (i + 1) % 2; } }
public void ScanLineFillPolygon(Graphics graph, PolygonBase shape, Color color) { if (shape.Vertices.Count < 3) return; if (shape.GetShapeType() == ShapeType.FreePencil) return; var rec = new Rectangle(Point.Round(shape.Location), Size.Round(shape.Size)); if (rec.Location.Equals(Point.Empty)) return; rec.X -= 1; rec.Y -= 1; rec.Width += 2; rec.Height += 2; //var h = rec.Y + 1; var h = rec.Y + rec.Height; var et = new SortedDoublyLinkedList<CActiveEdge>[h]; var active = new SortedDoublyLinkedList<CActiveEdge>(); for (int i = 0; i < h; i++) et[i] = new SortedDoublyLinkedList<CActiveEdge>(); BuildEdgeList(shape.Vertices.ToList(), ref et); //for (int i = rec.Y - rec.Height; i < rec.Y; i++) for (int i = rec.Y; i < rec.Y + rec.Height; i++) { buildActiveList(ref active, ref et[i]); if (active.Count != 0) { using (var p = new Pen(color, 1F)) FillScan(i, ref active, graph, p); updateEdgeList(i, ref active); active.Sort(); } } }
private void updateEdgeList(int line, ref SortedDoublyLinkedList<CActiveEdge> ae) { var p = ae.First; while (p != null) { if (line >= p.Value.YUper) { ae.Remove(p); } else p.Value.XIntersection += p.Value.ReciSlope; p = p.Next; } }
private void makeEdgeRec(ref Point lower, ref Point upper, int yComp, ref SortedDoublyLinkedList<CActiveEdge>[] et) { var ae = new CActiveEdge { ReciSlope = (float)(upper.X - lower.X) / (upper.Y - lower.Y), XIntersection = lower.X }; // Make shorter edge if (upper.Y < yComp) ae.YUper = upper.Y - 1; else ae.YUper = upper.Y; et[lower.Y].Add(ae); }
private void FillScan(int line, ref SortedDoublyLinkedList<CActiveEdge> ae, Graphics graph, Pen penline) { var points = new CActiveEdge[2]; int i = 0; foreach (var edge in ae) { points[i] = edge; if (i == 1) FillLine((int)Math.Round(points[0].XIntersection, 0), (int)Math.Round(points[1].XIntersection, 0), line, graph, penline); i = (i + 1) % 2; } }
private void BuildEdgeList(IList<Point> points, ref SortedDoublyLinkedList<CActiveEdge>[] et) { var cnt = points.Count; int i, yPrev = points[cnt - 2].Y; Point v1 = points[cnt - 1]; for (i = 0; i < cnt; i++) { Point v2 = points[i]; if (v1.Y != v2.Y) { // Nonhorizontal line if (v1.Y < v2.Y) // up-going edge makeEdgeRec(ref v1, ref v2, yNext(i, cnt, ref points), ref et); else // down-going edge makeEdgeRec(ref v2, ref v1, yPrev, ref et); } yPrev = v1.Y; v1 = v2; } }
private void buildActiveList(ref SortedDoublyLinkedList<CActiveEdge> dest, ref SortedDoublyLinkedList<CActiveEdge> source) { foreach (var edge in source) dest.Add(edge); }