Geometry Helpers
Utility functions for working with geometry operations.
Functions
Section titled “Functions”| Function | Description |
|---|---|
applyToPoint | Transforms a point by a matrix. |
applyToRect | Transforms a rectangle by a matrix and returns its bounding box: the smallest axis-aligned rectangle that contains it. |
contains | Whether a point or a rectangle is inside a rectangle. |
ellipsePath | The path of the ellipse that fills a box, as SVG path data: two half-turn arcs. |
fit | Places content in a box like CSS `object-fit` and `object-position`, e.g. |
fitContain | Places content in a box, as large as possible while staying entirely inside the box (CSS `object-fit: contain`). |
fitCover | Places content in a box, as small as possible while covering the whole box (CSS `object-fit: cover`). |
fitFill | Places content in a box, stretched to the box on each axis, without keeping its proportions (CSS `object-fit: fill`). |
fitNone | Places content in a box, at its own size, only positioned (CSS `object-fit: none`). |
fitScaleDown | Places content in a box, like fitContain, but never enlarged (CSS `object-fit: scale-down`). |
formatPath | Writes path commands back as SVG path data: letters and numbers separated by single spaces, numbers rounded to `precisi… |
identity | The matrix that changes nothing. |
intersection | The area two rectangles have in common. |
intersects | Whether two rectangles have an area in common, exactly when intersection returns a rectangle: rectangles that only touc… |
invert | The matrix that undoes `m`, e.g. |
matrixToCss | Writes a matrix as a CSS `transform` or SVG `transform` value. |
multiply | Multiplies matrices, in the mathematical order: the last one applies first. |
parsePath | Parses SVG path data (the `d` attribute) into commands, as written: the letters keep their case (absolute or relative),… |
rectToRect | The translation and scale that put one rectangle exactly on another, for animating or fitting between two boxes. |
rotate | A matrix that rotates points around the origin. |
roundedRectPath | The path of a rectangle with a radius per corner, as SVG path data. |
scale | A matrix that scales points from the origin. |
simplifyPolyline | Removes the points of a polyline that change its shape by less than `tolerance`, with the Ramer–Douglas–Peucker algorit… |
transformPath | Transforms SVG path data by a matrix. |
translate | A matrix that moves points by `(tx, ty)`. |
union | The smallest rectangle that contains all the given rectangles, e.g. |
