static public RectF2 GetConstrainedAboveX(this RectF2 item, float x) { if (item.GetLeft() < x) { return(item.GetHorizontallyShifted(x - item.GetLeft())); } return(item); }
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 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 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 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 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 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 VectorF2 GetUpperLeftPoint(this RectF2 item) { return(new VectorF2(item.GetLeft(), item.GetTop())); }
static public void SplitByXLeftOffset(this RectF2 item, float x_offset, out RectF2 left, out RectF2 right) { item.SplitByX(item.GetLeft() + x_offset, out left, out right); }