public static List <Step> FindIntersections(double y, Polygon poly) { var result = new List <Step>(); for (int lineFromIndex = 0; lineFromIndex < poly.Vertices.Count; lineFromIndex++) { int lineToIndex = lineFromIndex + 1; if (lineFromIndex == poly.Vertices.Count - 1) { lineToIndex = 0; } var fromPoint = poly.Vertices[lineFromIndex]; var toPoint = poly.Vertices[lineToIndex]; var intersectionWithThisLine = FillCalculator.FindIntersection(fromPoint, toPoint, y); if (intersectionWithThisLine != null) { var step = new Step(Step.StepType.Stitch, intersectionWithThisLine); result.Add(step); } } List <Step> sortedByX = result .Select(step => new KeyValuePair <Step, double>(step, step.Point.X)) .OrderBy(x => x.Value) .Select <KeyValuePair <Step, double>, Step>(kvp => kvp.Key) .ToList(); return(sortedByX); }
public override List <Step> CalculateFillSteps() { FillCalculator fc = new FillCalculator(this.polygon, this.ct); return(fc.Calculate()); }