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