sonolus.script.transform¶
InvertibleTransform2d
¶
Bases: Record
A transformation matrix for 2D points that can be inverted.
Usage
InvertibleTransform2d.new()
compose(other)
¶
Compose with another invertible transform which is applied after this transform and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Self
|
The other invertible transform to compose with. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new invertible transform resulting from the composition. |
compose_before(other)
¶
Compose with another invertible transform which is applied before this transform and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Self
|
The other invertible transform to compose with. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new invertible transform resulting from the composition. |
inverse_transform_quad(quad)
¶
inverse_transform_vec(v)
¶
new()
classmethod
¶
Create a new identity transform.
Returns:
Type | Description |
---|---|
Self
|
A new identity transform. |
normalize()
¶
Normalize the transform to have a 1 in the bottom right corner and return a new transform.
This may fail in some special cases involving perspective transformations where the bottom right corner is 0.
Returns:
Type | Description |
---|---|
Self
|
A new normalized invertible transform. |
perspective_x(foreground_x, vanishing_point)
¶
Apply a perspective transformation along the x-axis and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
foreground_x
|
float
|
The foreground x-coordinate. |
required |
vanishing_point
|
Vec2
|
The vanishing point vector. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new invertible transform after applying perspective. |
perspective_y(foreground_y, vanishing_point)
¶
Apply a perspective transformation along the y-axis and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
foreground_y
|
float
|
The foreground y-coordinate. |
required |
vanishing_point
|
Vec2
|
The vanishing point vector. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new invertible transform after applying perspective. |
rotate(angle)
¶
Rotate about the origin and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle
|
float
|
The angle of rotation in radians. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new invertible transform after rotation. |
rotate_about(angle, /, pivot)
¶
Rotate about the pivot and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle
|
float
|
The angle of rotation in radians. |
required |
pivot
|
Vec2
|
The pivot point for rotation. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new invertible transform after rotation. |
scale(factor)
¶
Scale about the origin and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
factor
|
Vec2
|
The scale factor vector. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new invertible transform after scaling. |
scale_about(factor, /, pivot)
¶
shear_x(m)
¶
Shear along the x-axis and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
float
|
The shear factor along the x-axis. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new invertible transform after shearing. |
shear_y(m)
¶
Shear along the y-axis and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
float
|
The shear factor along the y-axis. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new invertible transform after shearing. |
simple_perspective_x(x)
¶
Apply perspective along the x-axis with vanishing point at the given x coordinate and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float
|
The x coordinate of the vanishing point. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new invertible transform after applying perspective. |
simple_perspective_y(y)
¶
Apply perspective along the y-axis with vanishing point at the given y coordinate and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
float
|
The y coordinate of the vanishing point. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new invertible transform after applying perspective. |
transform_quad(quad)
¶
transform_vec(v)
¶
Transform2d
¶
Bases: Record
A transformation matrix for 2D points.
Usage
Transform2d.new()
compose(other)
¶
Compose with another transform which is applied after this transform and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Self
|
The other transform to compose with. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform resulting from the composition. |
compose_before(other)
¶
Compose with another transform which is applied before this transform and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Self
|
The other transform to compose with. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform resulting from the composition. |
inverse_perspective_x(foreground_x, vanishing_point)
¶
Apply the inverse of a perspective transformation along the x-axis and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
foreground_x
|
float
|
The foreground x-coordinate. |
required |
vanishing_point
|
Vec2
|
The vanishing point vector. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform after applying the inverse perspective. |
inverse_perspective_y(foreground_y, vanishing_point)
¶
Apply the inverse of a perspective transformation along the y-axis and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
foreground_y
|
float
|
The foreground y-coordinate. |
required |
vanishing_point
|
Vec2
|
The vanishing point vector. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform after applying the inverse perspective. |
new()
classmethod
¶
Create a new identity transform.
Returns:
Type | Description |
---|---|
Self
|
A new identity transform. |
normalize()
¶
Normalize the transform to have a 1 in the bottom right corner and return a new transform.
This may fail in some special cases involving perspective transformations where the bottom right corner is 0.
Returns:
Type | Description |
---|---|
Self
|
A new normalized transform. |
perspective_x(foreground_x, vanishing_point)
¶
Apply a perspective transformation along the x-axis and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
foreground_x
|
float
|
The foreground x-coordinate. |
required |
vanishing_point
|
Vec2
|
The vanishing point vector. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform after applying perspective. |
perspective_y(foreground_y, vanishing_point)
¶
Apply a perspective transformation along the y-axis and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
foreground_y
|
float
|
The foreground y-coordinate. |
required |
vanishing_point
|
Vec2
|
The vanishing point vector. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform after applying perspective. |
rotate(angle)
¶
Rotate about the origin and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle
|
float
|
The angle of rotation in radians. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform after rotation. |
rotate_about(angle, /, pivot)
¶
Rotate about the pivot and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle
|
float
|
The angle of rotation in radians. |
required |
pivot
|
Vec2
|
The pivot point for rotation. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform after rotation. |
scale(factor)
¶
Scale about the origin and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
factor
|
Vec2
|
The scale factor vector. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform after scaling. |
scale_about(factor, /, pivot)
¶
shear_x(m)
¶
Shear along the x-axis and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
float
|
The shear factor along the x-axis. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform after shearing. |
shear_y(m)
¶
Shear along the y-axis and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
float
|
The shear factor along the y-axis. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform after shearing. |
simple_perspective_x(x)
¶
Apply perspective along the x-axis with vanishing point at the given x coordinate and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
float
|
The x coordinate of the vanishing point. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform after applying perspective. |
simple_perspective_y(y)
¶
Apply perspective along the y-axis with vanishing point at the given y coordinate and return a new transform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y
|
float
|
The y coordinate of the vanishing point. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new transform after applying perspective. |
transform_quad(quad)
¶
transform_vec(v)
¶
perspective_approach(distance_ratio, progress)
¶
Calculate the perspective correct approach curve given the initial distance, target distance, and progress.
For typical engines with stage tilt, distance_ratio is the displayed width of a lane at the judge line divided by the displayed width of a lane at note spawn. For flat stages, this will be 1.0, and this function would simply return progress unchanged.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
distance_ratio
|
float
|
The ratio of the distance at note spawn to the distance at the judge line. |
required |
progress
|
float
|
The progress value, where 0 corresponds to note spawn and 1 corresponds to the judge line. |
required |
Returns:
Type | Description |
---|---|
float
|
The perspective-corrected progress value. |