static public RectF2 GetConstrainedAboveX(this RectF2 item, float x) { if (item.GetLeft() < x) { return(item.GetHorizontallyShifted(x - item.GetLeft())); } return(item); }
static public RectF2 GetConstrainedBelowY(this RectF2 item, float y) { if (item.GetTop() > y) { return(item.GetVerticallyShifted(y - item.GetTop())); } return(item); }
static public RectF2 GetEncompassing(this RectF2 item, RectF2 rect) { return(RectF2Extensions.CreateStrictMinMaxRectF2( item.GetLeft().Min(rect.GetLeft()), item.GetBottom().Min(rect.GetBottom()), item.GetRight().Max(rect.GetRight()), item.GetTop().Max(rect.GetTop()) )); }
static public void SplitIntoQuarters(this RectF2 item, out RectF2 r1, out RectF2 r2, out RectF2 r3, out RectF2 r4) { RectF2 left; RectF2 right; item.SplitByXCenter(out left, out right); left.SplitByYCenter(out r1, out r2); right.SplitByYCenter(out r3, out r4); }
static public bool TryGetIntersection(this RectF2 item, RectF2 rect, out RectF2 intersection) { return(RectF2Extensions.TryCreateStrictMinMaxRectF2( 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 TryCreateStrictMinMaxRectF2(VectorF2 min, VectorF2 max, out RectF2 rect) { if (min.IsBoundBelow(max)) { rect = new RectF2(min, max); return(true); } rect = RectF2.ZERO; return(false); }
static public bool FullyContains(this RectF2 item, RectF2 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 RectF2 item, RectF2 target) { if (item.GetWidth() >= target.GetWidth()) { if (item.GetHeight() >= target.GetHeight()) { return(true); } } return(false); }
static public bool Contains(this RectF2 item, VectorF2 point) { if (point.IsBoundAbove(item.min)) { if (point.IsBoundBelow(item.max)) { return(true); } } return(false); }
static public bool IsCollapsed(this RectF2 item, float tolerance) { if (item.GetWidth() <= tolerance) { return(true); } if (item.GetHeight() <= tolerance) { return(true); } return(false); }
static public bool TryGetConstrainedBy(this RectF2 item, RectF2 bounds, out RectF2 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 <RectF2> SplitIntoQuarters(this RectF2 item) { RectF2 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 IEnumerable <RectF2> GetSubtraction(this RectF2 item, RectF2 to_subtract) { if (item.TryGetIntersection(to_subtract, out to_subtract) == false) { yield return(item); } else { RectF2 left; if (RectF2Extensions.TryCreateStrictMinMaxRectF2( item.GetLeft(), to_subtract.GetBottom(), to_subtract.GetLeft(), to_subtract.GetTop(), out left )) { yield return(left); } RectF2 right; if (RectF2Extensions.TryCreateStrictMinMaxRectF2( to_subtract.GetRight(), to_subtract.GetBottom(), item.GetRight(), to_subtract.GetTop(), out right )) { yield return(right); } RectF2 bottom; if (RectF2Extensions.TryCreateStrictMinMaxRectF2( item.GetLeft(), item.GetBottom(), item.GetRight(), to_subtract.GetBottom(), out bottom )) { yield return(bottom); } RectF2 top; if (RectF2Extensions.TryCreateStrictMinMaxRectF2( item.GetLeft(), to_subtract.GetTop(), item.GetRight(), item.GetTop(), out top )) { yield return(top); } } }
static public float GetSide(this RectF2 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); }
static public RectF2 GetShrunk(this RectF2 item, float amount) { return(item.GetShrunk(amount, amount)); }
static public RectF2 GetShrunk(this RectF2 item, VectorF2 amount) { return(item.GetShrunk(amount.x, amount.y)); }
static public RectF2 GetShrunk(this RectF2 item, float x, float y) { return(item.GetShrunk(new VectorF2(x, y), new VectorF2(x, y))); }
static public RectF2 GetShrunk(this RectF2 item, VectorF2 min_adjust, VectorF2 max_adjust) { return(item.GetEnlarged(-min_adjust, -max_adjust)); }
static public RectF2 GetEnlarged(this RectF2 item, float amount) { return(item.GetEnlarged(amount, amount)); }
static public VectorF2 GetLowerLeftPoint(this RectF2 item) { return(item.min); }
static public void ProcessCroppedGrid(this RectF2 item, VectorF2 cell_size, Process <int, int, RectF2> process) { item.GetCroppedGridChunkInfos(cell_size).Process(t => process(t.item1, t.item2, t.item3)); }
static public IEnumerable <Tuple <int, int, RectF2> > GetCroppedGridChunkInfos(this RectF2 item, VectorF2 cell_size) { int width_in_cells = Mathq.CeilToInt(item.GetWidth() / cell_size.x); int height_in_cells = Mathq.CeilToInt(item.GetHeight() / cell_size.y); for (int y = 0; y < height_in_cells; y++) { for (int x = 0; x < width_in_cells; x++) { yield return(Tuple.New(x, y, item.GetCroppedGridChunk(x, y, cell_size))); } } }
static public RectF2 GetAdjusted(this RectF2 item, VectorF2 min_adjust, VectorF2 max_adjust) { return(new RectF2(item.min + min_adjust, item.max + max_adjust)); }
static public VectorF2 BindWithin(this VectorF2 item, RectF2 rect) { return(item.BindBetween(rect.min, rect.max)); }
static public RectF2 GetCroppedGridChunk(this RectF2 item, int x, int y, VectorF2 cell_size) { return(item.GetIntersection(item.GetOverflownGridChunk(x, y, cell_size))); }
static public RectF2 GetEnlarged(this RectF2 item, float x, float y) { return(item.GetEnlarged(new VectorF2(x, y), new VectorF2(x, y))); }
static public IEnumerable <RectF2> GetCroppedGridChunks(this RectF2 item, VectorF2 cell_size) { return(item.GetCroppedGridChunkInfos(cell_size).Convert(t => t.item3)); }
static public RectF2 GetEnlarged(this RectF2 item, VectorF2 amount) { return(item.GetEnlarged(amount.x, amount.y)); }
static public RectF2 GetOverflownGridChunk(this RectF2 item, int x, int y, VectorF2 cell_size) { return(new RectF2(item.min + new VectorF2(x * cell_size.x, y * cell_size.y), cell_size)); }
static public VectorF2 GetCenterPoint(this RectF2 item) { return(new VectorF2(item.GetHorizontalCenter(), item.GetVerticalCenter())); }