Rect

from kurbopy import Rect

r = Rect(50.0, 100.0, 200.0, 300.0)
class kurbopy.Rect

A rectangle.

abs()

Take absolute value of width and height.

The resulting rect has the same extents as the original, but is guaranteed to have non-negative width and height.

area()

The area of the rectangle.

aspect_ratio()

The aspect ratio of the Rect.

This is defined as the height divided by the width. It measures the “squareness” of the rectangle (a value of 1 is square).

If the width is 0 the output will be sign(y1 - y0) * infinity.

If the width and height are 0, the result will be NaN.

bounding_box()

The smallest rectangle that encloses the shape.

ceil()

Returns a new Rect, with each coordinate value rounded up to the nearest integer, unless they are already an integer.

center()

The center point of the rectangle.

contained_rect_with_aspect_ratio(aspect_ratio)

Returns the largest possible Rect that is fully contained in self with the given aspect_ratio.

The aspect ratio is specified fractionally, as height / width.

The resulting rectangle will be centered if it is smaller than the input rectangle.

For the special case where the aspect ratio is 1.0, the resulting Rect will be square.

contains(p)

Returns true if point lies within self.

expand()

Returns a new Rect, with each coordinate value rounded away from the center of the Rect to the nearest integer, unless they are already an integer. That is to say this function will return the smallest possible Rect with integer coordinates that is a superset of self.

floor()

Returns a new Rect, with each coordinate value rounded down to the nearest integer, unless they are already an integer.

from_points(p0, p1)

A new rectangle from two points.

The result will have non-negative width and height.

height()

The height of the rectangle.

Note: nothing forbids negative height.

inflate(width, height)

Expand a rectangle by a constant amount in both directions.

The logic simply applies the amount in each direction. If rectangle area or added dimensions are negative, this could give odd results.

inset(inset)
intersect(other)

The intersection of two rectangles.

The result is zero-area if either input has negative width or height. The result always has non-negative width and height.

is_empty()

Whether this rectangle has zero area.

Note: a rectangle with negative area is not considered empty.

is_finite()

Is this rectangle finite?

is_nan()

Is this rectangle NaN?

max_x()

Returns the maximum value for the x-coordinate of the rectangle.

max_y()

Returns the maximum value for the y-coordinate of the rectangle.

min_x()

Returns the minimum value for the x-coordinate of the rectangle.

min_y()

Returns the minimum value for the y-coordinate of the rectangle.

origin()

The origin of the rectangle.

This is the top left corner in a y-down space and with non-negative width and height.

perimeter(accuracy)

Total length of perimeter.

round()

Returns a new Rect, with each coordinate value rounded to the nearest integer.

scale_from_origin(factor)

Scales the Rect by factor with respect to the origin (the point (0, 0)).

Examples:

from kurbopy import Rect
rect = Rect(2, 2, 4, 6).scale_from_origin(2)
assert rect.x0 == 4
assert rect.x1 == 8
to_path(tolerance)

Convert to a Bézier path.

trunc()

Returns a new Rect, with each coordinate value rounded towards the center of the Rect to the nearest integer, unless they are already an integer. That is to say this function will return the biggest possible Rect with integer coordinates that is a subset of self.

union(other)

The smallest rectangle enclosing two rectangles.

Results are valid only if width and height are non-negative.

union_pt(pt)

Compute the union with one point.

This method includes the perimeter of zero-area rectangles. Thus, a succession of union_pt operations on a series of points yields their enclosing rectangle.

Results are valid only if width and height are non-negative.

width()

The width of the rectangle.

Note: nothing forbids negative width.

winding(pt)

The winding number of a point.

This method only produces meaningful results with closed shapes.

The sign of the winding number is consistent with that of area, meaning it is +1 when the point is inside a positive area shape and -1 when it is inside a negative area shape. Of course, greater magnitude values are also possible when the shape is more complex.

with_origin(origin)

Create a new Rect with the same size as self and a new origin.