示例#1
0
        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);
                    }
                }
            }
        }
示例#3
0
 public BoxPolygonDrawer(Polygon polygon)
 {
     SetBoxes(polygon);
     AddLinesToBoxes(polygon);
     foreach (var box in boxes)
     {
         box.SortLines();
     }
 }
示例#4
0
 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));
     });
 }
示例#5
0
        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);
                }
            }
        }
示例#6
0
 public IEnumerable<IntVector2> Draw(Polygon polygon)
 {
     return BoxPolygonDrawer.GetPoints(polygon);
 }
示例#7
0
 public IEnumerable <IntVector2> Draw(Polygon polygon)
 {
     return(PerYPolygonDrawer.GetPoints(polygon));
 }
示例#8
0
 public static IEnumerable <IntVector2> GetPoints(Polygon polygon)
 {
     return(new BoxPolygonDrawer(polygon).GetPoints());
 }
示例#9
0
 static IList <int> GetSortedYs(Polygon polygon)
 {
     return(polygon.Points.SelectList(point => point.Y).Distinct().OrderBy(x => x).ToList());
 }