Rect¶
from kurbopy import Rect
r = Rect(50.0, 100.0, 200.0, 300.0)
- class kurbopy.Rect(p0, p1, p2, p3)¶
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()¶
Compute the signed area under the curve.
For a closed path, the signed area of the path is the sum of signed areas of the segments. This is a variant of the “shoelace formula.” See: <https://github.com/Pomax/bezierinfo/issues/44> and <http://ich.deanmcnamee.com/graphics/2016/03/30/CurveArea.html>
This can be computed exactly for Béziers thanks to Green’s theorem, and also for simple curves such as circular arcs. For more exotic curves, it’s probably best to subdivide to cubics. We leave that to the caller, which is why we don’t give an accuracy param here.
- 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
Rectthat is fully contained inselfwith the givenaspect_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 resultingRectwill be square.
- contains(pt)¶
Returns true if the [Point] is inside this shape.
This is only meaningful for closed shapes.
- 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.
- classmethod from_center_size(p0, p1)¶
- classmethod from_origin_size(p0, p1)¶
- classmethod from_points(cls, 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 value finite?
- is_nan()¶
Is this value 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
Rectbyfactorwith 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
- size()¶
The size of the rectangle.
- 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_ptoperations 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.
- with_size(size)¶
- x0¶
- x1¶
- y0¶