Exemple #1
0
 static public RectI2 GetBottomSlice(this RectI2 item, int amount)
 {
     return(RectI2Extensions.CreateStrictMinMaxRectI2(
                item.GetLeft(),
                item.GetBottom(),
                item.GetRight(),
                (item.GetBottom() + amount).BindBelow(item.GetTop())
                ));
 }
Exemple #2
0
        static public RectI2 GetConstrainedAboveY(this RectI2 item, int y)
        {
            if (item.GetBottom() < y)
            {
                return(item.GetVerticallyShifted(y - item.GetBottom()));
            }

            return(item);
        }
Exemple #3
0
        static public IEnumerable <RectI2> GetSubtraction(this RectI2 item, RectI2 to_subtract)
        {
            if (item.TryGetIntersection(to_subtract, out to_subtract) == false)
            {
                yield return(item);
            }
            else
            {
                RectI2 left;
                if (RectI2Extensions.TryCreateStrictMinMaxRectI2(
                        item.GetLeft(), to_subtract.GetBottom(),
                        to_subtract.GetLeft(), to_subtract.GetTop(),
                        out left
                        ))
                {
                    yield return(left);
                }

                RectI2 right;
                if (RectI2Extensions.TryCreateStrictMinMaxRectI2(
                        to_subtract.GetRight(), to_subtract.GetBottom(),
                        item.GetRight(), to_subtract.GetTop(),
                        out right
                        ))
                {
                    yield return(right);
                }

                RectI2 bottom;
                if (RectI2Extensions.TryCreateStrictMinMaxRectI2(
                        item.GetLeft(), item.GetBottom(),
                        item.GetRight(), to_subtract.GetBottom(),
                        out bottom
                        ))
                {
                    yield return(bottom);
                }

                RectI2 top;
                if (RectI2Extensions.TryCreateStrictMinMaxRectI2(
                        item.GetLeft(), to_subtract.GetTop(),
                        item.GetRight(), item.GetTop(),
                        out top
                        ))
                {
                    yield return(top);
                }
            }
        }
Exemple #4
0
        static public RectI2 GetEncompassing(this RectI2 item, RectI2 rect)
        {
            return(RectI2Extensions.CreateStrictMinMaxRectI2(
                       item.GetLeft().Min(rect.GetLeft()),
                       item.GetBottom().Min(rect.GetBottom()),

                       item.GetRight().Max(rect.GetRight()),
                       item.GetTop().Max(rect.GetTop())
                       ));
        }
Exemple #5
0
 static public IEnumerable <VectorI2> GetPoints(this RectI2 item)
 {
     for (int y = item.GetBottom(); y < item.GetTop(); y++)
     {
         for (int x = item.GetLeft(); x < item.GetRight(); x++)
         {
             yield return(new VectorI2(x, y));
         }
     }
 }
Exemple #6
0
        static public bool TryGetIntersection(this RectI2 item, RectI2 rect, out RectI2 intersection)
        {
            return(RectI2Extensions.TryCreateStrictMinMaxRectI2(
                       item.GetLeft().Max(rect.GetLeft()),
                       item.GetBottom().Max(rect.GetBottom()),

                       item.GetRight().Min(rect.GetRight()),
                       item.GetTop().Min(rect.GetTop()),
                       out intersection
                       ));
        }
Exemple #7
0
        static public bool FullyContains(this RectI2 item, RectI2 target)
        {
            if (item.GetLeft() <= target.GetLeft() && item.GetRight() >= target.GetRight())
            {
                if (item.GetBottom() <= target.GetBottom() && item.GetTop() >= target.GetTop())
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #8
0
        static public bool TryGetConstrainedBy(this RectI2 item, RectI2 bounds, out RectI2 output)
        {
            output = item.GetConstrainedAboveX(bounds.GetLeft())
                     .GetConstrainedBelowX(bounds.GetRight())
                     .GetConstrainedAboveY(bounds.GetBottom())
                     .GetConstrainedBelowY(bounds.GetTop());

            if (bounds.FullyContains(output))
            {
                return(true);
            }

            return(false);
        }
Exemple #9
0
        static public int GetSide(this RectI2 item, RectSide side)
        {
            switch (side)
            {
            case RectSide.Left: return(item.GetLeft());

            case RectSide.Right: return(item.GetRight());

            case RectSide.Bottom: return(item.GetBottom());

            case RectSide.Top: return(item.GetTop());
            }

            throw new UnaccountedBranchException("side", side);
        }
Exemple #10
0
 static public void SplitByYBottomOffset(this RectI2 item, int y_offset, out RectI2 bottom, out RectI2 top)
 {
     item.SplitByY(item.GetBottom() + y_offset, out bottom, out top);
 }
Exemple #11
0
 static public IntRange GetVerticalRange(this RectI2 item)
 {
     return(new IntRange(item.GetBottom(), item.GetTop()));
 }
Exemple #12
0
 static public VectorI2 GetLowerRightPoint(this RectI2 item)
 {
     return(new VectorI2(item.GetRight(), item.GetBottom()));
 }