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 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 GetRectI2(this RectF2 item) { return(RectI2Extensions.CreateLowerLeftRectI2( item.GetLowerLeftPoint().GetVectorI2(), item.GetSize().GetVectorI2() )); }
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 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 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); } } }
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())); } }