public static IEnumerable <IntVector2> GetPoints(Polygon polygon) { int yTop = int.MinValue; int yBot = int.MaxValue; foreach (var point in polygon.Points) { yTop = Math.Max(point.Y, yTop); yBot = Math.Min(point.Y, yBot); } var lines = polygon.GetLines().Where(line => !line.IsHorizontal()).ToList(); for (int y = yBot; y < yTop; y++) { var lineXs = GetLineIntersections(lines, y); for (int lineCoupleId = 0; lineCoupleId < Math.Floor(lineXs.Count / 2.0); lineCoupleId++) { int xMax = lineXs[2 * lineCoupleId + 1]; int xMin = lineXs[2 * lineCoupleId]; for (int x = xMin; x <= xMax; x++) { yield return(new IntVector2(x, y)); } } } }
public static IEnumerable<IntVector2> GetPoints(Polygon polygon) { int yTop = int.MinValue; int yBot = int.MaxValue; foreach (var point in polygon.Points) { yTop = Math.Max(point.Y, yTop); yBot = Math.Min(point.Y, yBot); } var lines = polygon.GetLines().Where(line => !line.IsHorizontal()).ToList(); for (int y = yBot; y < yTop; y++) { var lineXs = GetLineIntersections(lines, y); for (int lineCoupleId = 0; lineCoupleId < Math.Floor(lineXs.Count/2.0); lineCoupleId++) { int xMax = lineXs[2*lineCoupleId + 1]; int xMin = lineXs[2*lineCoupleId]; for (int x = xMin; x <= xMax; x++) { yield return new IntVector2(x, y); } } } }
public BoxPolygonDrawer(Polygon polygon) { SetBoxes(polygon); AddLinesToBoxes(polygon); foreach (var box in boxes) { box.SortLines(); } }
void SetBoxes(Polygon polygon) { GetSortedYs(polygon).HoldHandsLine().ForEachIndex( (index, bottomTop) => { yToBoxIndex[bottomTop.Item1] = index; yToBoxIndex[bottomTop.Item2] = index + 1; boxes.Add(new Box(bottomTop.Item1, bottomTop.Item2)); }); }
void AddLinesToBoxes(Polygon polygon) { foreach (var line in polygon.GetLines()) { if (line.IsHorizontal()) { continue; } int boxIndex1 = yToBoxIndex[(int)line.BottomY]; int boxIndex2 = yToBoxIndex[(int)line.TopY]; int boxStartIndex = Math.Min(boxIndex1, boxIndex2); int boxEndIndex = Math.Max(boxIndex1, boxIndex2); foreach (var boxIndex in ListUtil.FromTo(boxStartIndex, boxEndIndex - 1)) { boxes[boxIndex].AddLine(line); } } }
public IEnumerable<IntVector2> Draw(Polygon polygon) { return BoxPolygonDrawer.GetPoints(polygon); }
public IEnumerable <IntVector2> Draw(Polygon polygon) { return(PerYPolygonDrawer.GetPoints(polygon)); }
public static IEnumerable <IntVector2> GetPoints(Polygon polygon) { return(new BoxPolygonDrawer(polygon).GetPoints()); }
static IList <int> GetSortedYs(Polygon polygon) { return(polygon.Points.SelectList(point => point.Y).Distinct().OrderBy(x => x).ToList()); }