Insets¶
- class kurbopy.Insets(x0, y0, x1, y1)¶
Insets from the edges of a rectangle.
The inset value for each edge can be thought of as a delta computed from the center of the rect to that edge. For instance, with an inset of 2.0 on the x-axis, a rectangle with the origin (0.0, 0.0) with that inset added will have the new origin at (-2.0, 0.0).
Put alternatively, a positive inset represents increased distance from center, and a negative inset represents decreased distance from center.
## Examples
Positive insets added to a [Rect] produce a larger [Rect]: ``` rect = Rect.from_origin_size(Point(0., 0.,), Size(10., 10.,)) insets = Insets.uniform_xy(3., 0.)
inset_rect = rect + insets assert inset_rect.width() == 16.0, “10.0 + 3.0 × 2” assert inset_rect.x0 == -3.0 ```
Negative insets added to a [Rect] produce a smaller [Rect]:
``` rect = Rect.from_origin_size(Point(0., 0.,), Size(10., 10.,)) insets = Insets.uniform_xy(-3., 0.)
inset_rect = rect + insets assert inset_rect.width() == 4.0, “10.0 - 3.0 × 2” assert inset_rect.x0 == 3.0 ```
[Insets] operate on the absolute rectangle [Rect.abs], and so ignore existing negative widths and heights.
``` rect = Rect(7., 11., 0., 0.) insets = Insets.uniform_xy(0., 1.)
assert rect.width() == -7.0
inset_rect = rect + insets assert inset_rect.width() == 7.0 assert inset_rect.x0 == 0.0 assert inset_rect.height() == 13.0 ```
The width and height of an inset operation can still be negative if the [Insets]’ dimensions are greater than the dimensions of the original [Rect].
``` rect = Rect(Point(0., 0.), Point(3., 5.)) insets = Insets.uniform_xy(0., 7.)
inset_rect = rect - insets assert inset_rect.height() == -9., “5 - 7 × 2” ```
Rect - Rect = Insets:
``` rect = Rect(Point(0., 0.), Point(5., 11.)) insets = Insets.uniform_xy(1., 7.,)
inset_rect = rect + insets insets2 = inset_rect - rect
assert insets2.x0 == insets.x0 assert insets2.y1 == insets.y1 assert insets2.x_value() == insets.x_value() assert insets2.y_value() == insets.y_value() ```
- classmethod ZERO()¶
Zeroed insets
- are_nonnegative()¶
Return true iff all values are nonnegative.
- is_finite()¶
Is this value finite?
- is_nan()¶
Is this value NaN?
- nonnegative()¶
Return new Insets with all negative values replaced with 0.0.
This is provided as a convenience for applications where negative insets are not meaningful.
- size()¶
Returns the total delta represented by these insets as a [Size].
This is equivalent to creating a [Size] from the values returned by [x_value] and [y_value].
This function may return a size with negative values.
- classmethod uniform(value)¶
New uniform insets.
- classmethod uniform_xy(x_value, y_value)¶
New insets with uniform values along each axis.
- x0¶
- x1¶
- x_value()¶
The total delta on the x-axis represented by these insets.
# Examples
``` insets = Insets.uniform_xy(3., 8.) assert insets.x_value() == 6
insets = Insets(5., 0., -12., 0.,) assert insets.x_value() == -7 ```
- y0¶
- y1¶