sonolus.script.quad¶
Quad
¶
Bases: Record
A quad defined by its four corners.
Usage
Quad(bl: Vec2, tl: Vec2, tr: Vec2, br: Vec2)
bl
instance-attribute
¶
The bottom-left corner of the quad.
br
instance-attribute
¶
The bottom-right corner of the quad.
center
property
¶
The center of the quad.
tl
instance-attribute
¶
The top-left corner of the quad.
tr
instance-attribute
¶
The top-right corner of the quad.
contains_point(point)
¶
Check if the quad contains the given point.
It is not guaranteed whether points on the edges of the quad are considered inside or outside.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
Vec2
|
The point to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the point is inside the quad, False otherwise. |
from_quad(value)
classmethod
¶
Create a quad from a quad-like value.
permute(count=1)
¶
Perform a cyclic permutation of the quad's vertices and return a new quad.
On a square, this operation is equivalent to rotating the square counterclockwise 90 degrees count
times.
Negative values of count
are allowed and will rotate the quad clockwise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
count
|
int
|
The number of vertices to shift. Defaults to 1. |
1
|
Returns:
Type | Description |
---|---|
Self
|
The permuted quad. |
rotate(angle)
¶
Rotate the quad by the given angle about the origin and return a new quad.
rotate_about(angle, /, pivot)
¶
Rotate the quad by the given angle about the given pivot and return a new quad.
rotate_centered(angle)
¶
Rotate the quad by the given angle about its center and return a new quad.
scale(factor)
¶
Scale the quad by the given factor about the origin and return a new quad.
scale_about(factor, /, pivot)
¶
Scale the quad by the given factor about the given pivot and return a new quad.
scale_centered(factor)
¶
Scale the quad by the given factor about its center and return a new quad.
translate(translation)
¶
Translate the quad by the given translation and return a new quad.
Rect
¶
Bases: Record
A rectangle defined by its top, right, bottom, and left edges.
Usage
Rect(t: float, r: float, b: float, l: float)
b
instance-attribute
¶
The bottom edge of the rectangle.
bl
property
¶
The bottom-left corner of the rectangle.
br
property
¶
The bottom-right corner of the rectangle.
center
property
¶
The center of the rectangle.
h
property
¶
The height of the rectangle.
l
instance-attribute
¶
The left edge of the rectangle.
r
instance-attribute
¶
The right edge of the rectangle.
t
instance-attribute
¶
The top edge of the rectangle.
tl
property
¶
The top-left corner of the rectangle.
tr
property
¶
The top-right corner of the rectangle.
w
property
¶
The width of the rectangle.
contains_point(point)
¶
Check if the rectangle contains the given point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
Vec2
|
The point to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the point is inside the rectangle, False otherwise. |
expand(expansion)
¶
Expand the rectangle by the given amount and return a new rectangle.
from_center(center, dimensions)
classmethod
¶
Create a rectangle from its center and dimensions.
scale(factor)
¶
Scale the rectangle by the given factor about the origin and return a new rectangle.
scale_about(factor, /, pivot)
¶
Scale the rectangle by the given factor about the given pivot and return a new rectangle.
scale_centered(factor)
¶
Scale the rectangle by the given factor about its center and return a new rectangle.
shrink(shrinkage)
¶
Shrink the rectangle by the given amount and return a new rectangle.
translate(translation)
¶
Translate the rectangle by the given translation and return a new rectangle.