Point
A class representing a location in a two-dimensional coordinate system.Constructor
number
required
Coordinate of the point on the horizontal axis
number
required
Coordinate of the point on the vertical axis
Static Methods
Point.delta
Returns the delta (difference) between two points.Point
required
First point
Point
required
Second point
Point
A new Point representing the difference (a.x - b.x, a.y - b.y)
Point.distance
Returns the distance (hypotenuse) between two points.Point
required
First point
Point
required
Second point
number
The Euclidean distance between the two points
Point.equals
Returns true if both points have the same coordinates.Point
required
First point
Point
required
Second point
boolean
True if both points are equal
Point.from
Creates a Point from coordinates.Coordinates
required
An object with
x and y propertiesPoint
A new Point instance
Usage Example
Rectangle
A class representing a rectangular shape in 2D space.Constructor
number
required
The x-coordinate of the left edge
number
required
The y-coordinate of the top edge
number
required
The width of the rectangle
number
required
The height of the rectangle
Properties
Point
The center point of the rectangle
number
The area of the rectangle (width × height)
number
The y-coordinate of the bottom edge (top + height)
number
The x-coordinate of the right edge (left + width)
number
The aspect ratio of the rectangle (width / height)
Coordinates[]
An array of the four corner coordinates
BoundingRectangle
An object containing width, height, left, top, right, and bottom properties
object
The scale factors for x and y axes (default:
{x: 1, y: 1})Methods
translate
Translates the rectangle by the given offsets.number
required
The x-axis offset
number
required
The y-axis offset
Rectangle
A new Rectangle instance at the translated position
equals
Checks if this rectangle is equal to another shape.Shape
required
The shape to compare with
boolean
True if the shapes are equal
containsPoint
Checks if a point is contained within the rectangle.Point
required
The point to check
boolean
True if the point is inside the rectangle
intersectionArea
Calculates the intersection area with another shape.Shape
required
The shape to check intersection with
number
The area of intersection, or 0 if shapes don’t intersect
intersectionRatio
Calculates the intersection ratio with another shape.Shape
required
The shape to check intersection with
number
The intersection ratio calculated as: intersectionArea / (shapeArea + thisArea - intersectionArea)
Static Methods
Rectangle.from
Creates a Rectangle from a BoundingRectangle.BoundingRectangle
required
An object with top, left, width, and height properties
Rectangle
A new Rectangle instance
Rectangle.delta
Calculates the delta between two rectangles based on alignment.BoundingRectangle
required
First rectangle
BoundingRectangle
required
Second rectangle
Alignment
default:"{x: 'center', y: 'center'}"
The alignment point to use for comparison. Can be ‘start’, ‘center’, or ‘end’ for each axis.
Point
The delta between the aligned points of the two rectangles
Rectangle.intersectionRatio
Calculates the intersection ratio between two rectangles.BoundingRectangle
required
First rectangle
BoundingRectangle
required
Second rectangle
number
The intersection ratio
Usage Example
Position
A class that tracks the current, previous, and initial positions with history and velocity tracking.Constructor
Coordinates
required
The initial coordinates
Properties
Point
The current position
Point | undefined
The previous position, or undefined if not yet moved
Point
The initial position
Point
The delta between current and initial positions (computed)
'up' | 'down' | 'left' | 'right' | null
The direction of movement based on the delta between current and previous positions (computed)
Point
The velocity in pixels per 100ms for x and y axes
Methods
reset
Resets the position to initial or provided coordinates.Coordinates
Optional coordinates to reset to (defaults to initial value)
Usage Example
exceedsDistance
Returns true if a set of relative coordinates exceeds a given distance.Parameters
Coordinates
required
The coordinates to check (typically a delta)
Distance
required
The distance threshold. Can be:
- A number (Euclidean distance)
- An object with
xandyproperties (both axes must exceed) - An object with only
x(horizontal distance) - An object with only
y(vertical distance)
Returns
boolean
True if the coordinates exceed the specified distance