예제 #1
0
 public VectorI2 GetOffset(VectorI2 radius)
 {
     return(new VectorI2(
                source.GetOffset(radius.x),
                source.GetOffset(radius.y)
                ));
 }
예제 #2
0
        static public bool IsCardinallyAdjacent(this VectorI2 item, VectorI2 other)
        {
            if (item.x == other.x)
            {
                if (item.y == other.y - 1)
                {
                    return(true);
                }

                if (item.y == other.y + 1)
                {
                    return(true);
                }
            }

            if (item.y == other.y)
            {
                if (item.x == other.x - 1)
                {
                    return(true);
                }

                if (item.x == other.x + 1)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #3
0
 public VectorI2 GetMagnitude(VectorI2 m)
 {
     return(new VectorI2(
                source.GetMagnitude(m.x),
                source.GetMagnitude(m.y)
                ));
 }
예제 #4
0
 public VectorI2 GetBetween(VectorI2 a, VectorI2 b)
 {
     return(new VectorI2(
                source.GetBetween(a.x, b.x),
                source.GetBetween(a.y, b.y)
                ));
 }
예제 #5
0
        static public RectI2 CreateStrictMinMaxRectI2(VectorI2 min, VectorI2 max)
        {
            RectI2 rect;

            TryCreateStrictMinMaxRectI2(min, max, out rect);
            return(rect);
        }
예제 #6
0
        static public IEnumerable <IEnumerable <VectorI2> > TraverseEdges(this IGrid <bool> item, int maximum_gap)
        {
            VectorI2     point;
            IGrid <bool> edges = item.ConvertToStrictEdges().ToGrid();

            int width  = edges.GetWidth();
            int height = edges.GetHeight();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    point = new VectorI2(x, y);

                    if (edges.Get(point))
                    {
                        List <VectorI2> points = new List <VectorI2>();

                        do
                        {
                            edges.SetDropped(point, false);
                            points.Add(point);
                        }while (point.GetRadiating(maximum_gap).TryFindFirst(p => edges.Get(p), out point));

                        if (points.Count >= 3)
                        {
                            yield return(points);
                        }
                    }
                }
            }
        }
예제 #7
0
 public VectorI2 GetVariance(VectorI2 center, VectorI2 radius)
 {
     return(new VectorI2(
                source.GetVariance(center.x, radius.x),
                source.GetVariance(center.y, radius.y)
                ));
 }
예제 #8
0
        static public bool IsBoundBelow(this VectorI2 item, VectorI2 value)
        {
            if (item.x <= value.x && item.y <= value.y)
            {
                return(true);
            }

            return(false);
        }
예제 #9
0
        static public bool IsCardinallyOrOrdinallyAdjacent(this VectorI2 item, VectorI2 other)
        {
            if (item.IsCardinallyAdjacent(other) || item.IsOrdinallyAdjacent(other))
            {
                return(true);
            }

            return(false);
        }
예제 #10
0
        static public int GetMagnitudeMinComponent(this VectorI2 item)
        {
            if (item.x.GetAbs() < item.y.GetAbs())
            {
                return(item.x);
            }

            return(item.y);
        }
예제 #11
0
        static public bool IsCardinallyAdjacent(this IEnumerable <VectorI2> item, VectorI2 point)
        {
            if (item.GetCardinallyAdjacent(point).IsNotEmpty())
            {
                return(true);
            }

            return(false);
        }
예제 #12
0
        static public bool IsBoundAbove(this VectorI2 item, VectorI2 value)
        {
            if (item.x >= value.x && item.y >= value.y)
            {
                return(true);
            }

            return(false);
        }
예제 #13
0
        static public IEnumerable <VectorI2> GetCardinalNeighbors(this VectorI2 item)
        {
            yield return(new VectorI2(item.x, item.y - 1));

            yield return(new VectorI2(item.x - 1, item.y));

            yield return(new VectorI2(item.x + 1, item.y));

            yield return(new VectorI2(item.x, item.y + 1));
        }
예제 #14
0
        static public bool TryCreateStrictMinMaxRectI2(VectorI2 min, VectorI2 max, out RectI2 rect)
        {
            if (min.IsBoundBelow(max))
            {
                rect = new RectI2(min, max);
                return(true);
            }

            rect = RectI2.ZERO;
            return(false);
        }
예제 #15
0
        static public bool Contains(this RectI2 item, VectorI2 point)
        {
            if (point.IsBoundAbove(item.min))
            {
                if (point.IsBoundBelow(item.max))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #16
0
        static public bool IsBoundBetween(this VectorI2 item, VectorI2 value1, VectorI2 value2)
        {
            VectorI2 lower;
            VectorI2 upper;

            value1.Order(value2, out lower, out upper);

            if (item.IsBoundAbove(lower) && item.IsBoundBelow(upper))
            {
                return(true);
            }

            return(false);
        }
예제 #17
0
        static public void AddRectangle(this ICollection <VectorI2> item, VectorI2 point1, VectorI2 point2)
        {
            VectorI2 lower;
            VectorI2 upper;

            point1.Order(point2, out lower, out upper);

            for (int x = lower.x; x <= upper.x; x++)
            {
                for (int y = lower.y; y <= upper.y; y++)
                {
                    item.Add(new VectorI2(x, y));
                }
            }
        }
예제 #18
0
        static public void Order(this VectorI2 item, VectorI2 input, out VectorI2 lower, out VectorI2 upper)
        {
            int x_min;
            int x_max;

            item.x.Order(input.x, out x_min, out x_max);

            int y_min;
            int y_max;

            item.y.Order(input.y, out y_min, out y_max);

            lower = new VectorI2(x_min, y_min);
            upper = new VectorI2(x_max, y_max);
        }
예제 #19
0
        static public IEnumerable <HashSet <VectorI2> > GetCardinallyContinousAreas(this HashSet <VectorI2> item)
        {
            HashSet <VectorI2>         copy  = item.ToHashSet();
            List <HashSet <VectorI2> > areas = new List <HashSet <VectorI2> >();

            while (copy.IsNotEmpty())
            {
                VectorI2           point = copy.GetFirst();
                HashSet <VectorI2> area  = copy.GetCardinallyContinousAreaAt(point);

                areas.Add(area);
                copy.ExceptWith(area);
            }

            return(areas);
        }
예제 #20
0
 static public IEnumerable <VectorI2> GetRadiating(this VectorI2 item, int radius)
 {
     return(RadiatingWalker.Iterator(radius).Convert(d => item + d));
 }
예제 #21
0
 public RectI2(VectorI2 np1, VectorI2 np2)
 {
     np1.Order(np2, out min, out max);
 }
예제 #22
0
 public RandVectorI2Box_Between(VectorI2 na, VectorI2 nb, RandVectorI2Source s) : base(s)
 {
     a = na;
     b = nb;
 }
예제 #23
0
 static public bool IsIndexValid <T>(this IGrid <T> item, VectorI2 index)
 {
     return(item.IsIndexValid <T>(index.x, index.y));
 }
예제 #24
0
 static public void Add <T>(this IGrid <List <T> > item, VectorI2 index, T value)
 {
     item.Add(index.x, index.y, value);
 }
예제 #25
0
 public RandVectorI2Box_Between(VectorI2 na, VectorI2 nb) : this(na, nb, RandVectorI2.SOURCE)
 {
 }
예제 #26
0
 static public T GetLooped <T>(this IGrid <T> item, VectorI2 index)
 {
     return(item.GetLooped <T>(index.x, index.y));
 }
예제 #27
0
 static public void SetLooped <T>(this IGrid <T> item, VectorI2 index, T value)
 {
     item.SetLooped <T>(index.x, index.y, value);
 }
예제 #28
0
 static public IGrid <T> BoundSub <T>(this IGrid <T> item, VectorI2 index, VectorI2 size)
 {
     return(item.BoundSubSection <T>(index, index + size));
 }
예제 #29
0
 static public IGrid <T> BoundSubArea <T>(this IGrid <T> item, VectorI2 center, int radius)
 {
     return(item.BoundSubArea <T>(center.x, center.y, radius));
 }
예제 #30
0
 static public IGrid <T> BoundSubSection <T>(this IGrid <T> item, VectorI2 lower, VectorI2 upper)
 {
     return(item.BoundSubSection(lower.x, lower.y, upper.x, upper.y));
 }