Пример #1
0
 static IEnumerable <IntVector2> GetLineBoxEnclosingPoints(Box box, IBoundedLine leftLine, IBoundedLine rightLine)
 {
     return(from y in ListUtil.FromTo(box.Bottom, box.Top - 1)
            let rightX = (int)rightLine.X(y)
                         from x in ListUtil.FromTo((int)leftLine.X(y), rightX)
                         select(new IntVector2(x, y)));
 }
Пример #2
0
        private IEnumerable <PolygonChanged> OutGoingForPointRange(int index, int range)
        {
            var polygonMutations = Diagonalizes.DiagonalizeListRate(ListUtil.FromTo(index, index + range - 1).SelectList(i =>
                                                                                                                         GetPointMutationsForIndex(i % Polygon.Points.Count)), 2).ConcatUtil().Select(xs => CombinePointMutations(xs.ToLazyList()));
            var changedPolygons          = polygonMutations.Select(polygon => new PolygonChanged(polygon, 0));
            var withoutSelfIntersections = changedPolygons.Where(changedPolygon => !changedPolygon.NewPolygon.IsSelfIntersecting());

            return(withoutSelfIntersections);
        }
Пример #3
0
        public static IEnumerable <int> DistinctSampling(Random random, int count, double exp = 0.5)
        {
            var indexes   = ListUtil.FromTo(0, count);
            int itemsLeft = count;

            for (int i = 0; i < count; i++)
            {
                int index   = (int)(itemsLeft * Sample(random, exp));
                int element = indexes[index];
                indexes = RemoveRewrite(indexes, index);
                itemsLeft--;
                yield return(element);
            }
        }
Пример #4
0
        static IList <int> RemoveRewrite(this IList <int> xs, int index)
        {
            if (xs is Concat <int> )
            {
                var concat = (Concat <int>)xs;
                if (concat.First.Count <= index)
                {
                    return(concat.First.ConcatRewrite(RemoveRewrite(concat.Second, index - concat.First.Count)));
                }

                return(RemoveRewrite(concat.First, index).ConcatRewrite(concat.Second));
            }
            var fromTo   = (FromToInt)xs;
            var midValue = fromTo.From + index;

            return(ListUtil.FromTo(fromTo.From, midValue - 1).ConcatRewrite(ListUtil.FromTo(midValue + 1, fromTo.To)));
        }
Пример #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
 private IEnumerable <PolygonChanged> OutGoingForPoint(int index)
 {
     return(ListUtil.FromTo(1, Polygon.Points.Count).SelectList(range => OutGoingForPointRange(index, range)).IntertwineRate(2));
 }