static public void SplitByX(this RectI2 item, int x, out RectI2 left, out RectI2 right) { int split = x.Min(item.GetRight()); left = RectI2Extensions.CreateStrictMinMaxRectI2(item.min, item.max.GetWithX(split)); right = RectI2Extensions.CreateStrictMinMaxRectI2(item.min.GetWithX(split), item.max); }
static public RectF2 GetRectF2(this RectI2 item) { return(RectF2Extensions.CreateLowerLeftRectF2( item.GetLowerLeftPoint().GetVectorF2(), item.GetSize().GetVectorF2() )); }
static public RectI2 GetIntersection(this RectI2 item, RectI2 rect) { RectI2 intersection; item.TryGetIntersection(rect, out intersection); return(intersection); }
static public void SplitByY(this RectI2 item, int y, out RectI2 bottom, out RectI2 top) { int split = y.Min(item.GetTop()); bottom = RectI2Extensions.CreateStrictMinMaxRectI2(item.min, item.max.GetWithY(split)); top = RectI2Extensions.CreateStrictMinMaxRectI2(item.min.GetWithY(split), item.max); }
static public RectI2 GetConstrainedByOrShrunk(this RectI2 item, RectI2 bounds) { if (item.TryGetConstrainedBy(bounds, out item)) { return(item); } return(bounds.GetIntersection(item)); }
static public RectI2 GetConstrainedBelowX(this RectI2 item, int x) { if (item.GetRight() > x) { return(item.GetHorizontallyShifted(x - item.GetRight())); } return(item); }
static public RectI2 GetConstrainedAboveX(this RectI2 item, int x) { if (item.GetLeft() < x) { return(item.GetHorizontallyShifted(x - item.GetLeft())); } return(item); }
static public RectI2 GetConstrainedAboveY(this RectI2 item, int y) { if (item.GetBottom() < y) { return(item.GetVerticallyShifted(y - item.GetBottom())); } return(item); }
static public RectI2 GetConstrainedBelowY(this RectI2 item, int y) { if (item.GetTop() > y) { return(item.GetVerticallyShifted(y - item.GetTop())); } return(item); }
static public RectI2 GetLeftSlice(this RectI2 item, int amount) { return(RectI2Extensions.CreateStrictMinMaxRectI2( item.GetLeft(), item.GetBottom(), (item.GetLeft() + amount).BindBelow(item.GetRight()), item.GetTop() )); }
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)); } } }
static public void SplitIntoQuarters(this RectI2 item, out RectI2 r1, out RectI2 r2, out RectI2 r3, out RectI2 r4) { RectI2 left; RectI2 right; item.SplitByXCenter(out left, out right); left.SplitByYCenter(out r1, out r2); right.SplitByYCenter(out r3, out r4); }
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()) )); }
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 )); }
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); }
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); }
static public bool CouldContain(this RectI2 item, RectI2 target) { if (item.GetWidth() >= target.GetWidth()) { if (item.GetHeight() >= target.GetHeight()) { return(true); } } return(false); }
static public bool Contains(this RectI2 item, VectorI2 point) { if (point.IsBoundAbove(item.min)) { if (point.IsBoundBelow(item.max)) { return(true); } } return(false); }
static public IEnumerable <RectI2> SplitIntoQuarters(this RectI2 item) { RectI2 r1, r2, r3, r4; item.SplitIntoQuarters(out r1, out r2, out r3, out r4); yield return(r1); yield return(r2); yield return(r3); yield return(r4); }
static public bool IsCollapsed(this RectI2 item) { if (item.GetWidth() <= 0) { return(true); } if (item.GetHeight() <= 0) { return(true); } return(false); }
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); }
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); } } }
static public RectI2 GetSlice(this RectI2 item, int amount, RectSide side) { switch (side) { case RectSide.Left: return(item.GetLeftSlice(amount)); case RectSide.Right: return(item.GetRightSlice(amount)); case RectSide.Bottom: return(item.GetBottomSlice(amount)); case RectSide.Top: return(item.GetTopSlice(amount)); } throw new UnaccountedBranchException("side", side); }
static public void SplitBySideOffset(this RectI2 item, int offset, RectSide side, out RectI2 center, out RectI2 edge) { switch (side) { case RectSide.Left: item.SplitByXLeftOffset(offset, out edge, out center); return; case RectSide.Right: item.SplitByXRightOffset(offset, out center, out edge); return; case RectSide.Bottom: item.SplitByYBottomOffset(offset, out edge, out center); return; case RectSide.Top: item.SplitByYTopOffset(offset, out center, out edge); return; } throw new UnaccountedBranchException("side", side); }
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); }
public void EnsureRadius(int radius) { if (radius > current_radius) { RectI2 old_rect = RectI2Extensions.CreateCenterRectI2(VectorI2.ZERO, new VectorI2(current_radius * 2, current_radius * 2)); RectI2 new_rect = RectI2Extensions.CreateCenterRectI2(VectorI2.ZERO, new VectorI2(radius * 2, radius * 2)); new_rect.GetSubtraction(old_rect) .Convert(r => r.GetPoints()) .Flatten() .Process(p => points.Add(new RadiatingPoint(p))); current_radius = radius; points.Sort((x, y) => x.GetDistance().CompareTo(y.GetDistance())); } }
static public void SplitByYTopOffset(this RectI2 item, int y_offset, out RectI2 bottom, out RectI2 top) { item.SplitByY(item.GetTop() - y_offset, out bottom, out top); }
static public void SplitByXRightOffset(this RectI2 item, int x_offset, out RectI2 left, out RectI2 right) { item.SplitByX(item.GetRight() - x_offset, out left, out right); }
static public VectorF2 ConvertPercentPointToRangePoint(this RectI2 item, VectorF2 point) { return(point.ConvertFromPercentToRange(item.GetHorizontalRange(), item.GetVerticalRange())); }
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); }