geometry
2D geometry in f64: Point, Rect and the affine Matrix, in the layout of CSS and
SVG matrix(a b c d e f).
Enough to map between coordinate spaces: build and multiply transforms, invert one to bring a
point back, take the bounding box of a transformed rectangle (hit areas, gradient bounds), place
content in a container like CSS object-fit (fit), simplify a polyline, and work with SVG
path data: parse it (parse_path), transform it by a matrix (transform_path) and write
rectangles and ellipses as paths (rounded_rect_path, ellipse_path).
Install
Section titled “Install”Cargo feature geometry (enabled by default). To compile only this module:
or in Cargo.toml:
Import path: helpers4::geometry.
| Item | What it does |
|---|---|
ellipse_path | The path of the ellipse that fills a box, as SVG path data: two half-turn arcs. |
FitAlign | Where fit places content in the space left over (or overflowing), as CSS object-position: 0.0 is left or top, 0.5 centered, 1.0 right or bottom. |
FitMode | How fit sizes content in a container, as CSS object-fit. |
fit | Places content in a container like CSS object-fit and object-position, e.g. |
format_path | Writes path commands back as SVG path data: letters glued to their first number, single spaces elsewhere, numbers rounded to precision decimals with the trailing zeros dropped (-0 is written 0). |
Matrix | A 2D affine transformation (a 2×3 matrix), in the layout of CSS and SVG matrix(a, b, c, d, e, f): |
parse_path | Parses SVG path data (the d attribute) into commands, as written: the letters keep their case (absolute or relative), H/V/S/T/A stay what they are, and a command repeated without its letter (L 1 2 3 4) becomes one command per set of numbers (M repeats as L, m as l). |
PathCommand | One command of SVG path data: its letter (uppercase is absolute, lowercase relative to the current point) and its numbers, as written in the d attribute. |
Point | A point in 2D space. |
Rect | An axis-aligned rectangle: its top-left corner and its size. |
rounded_rect_path | The path of a rectangle with a radius per corner, as SVG path data. |
simplify_polyline | Removes the points of a polyline that change its shape by less than tolerance, with the Ramer–Douglas–Peucker algorithm: each removed point is at most tolerance away from the simplified line. |
Size | A width and a height. |
transform_path | Transforms SVG path data by a matrix. |
Error types
Section titled “Error types”Documented on the page of the helper that returns them.
| Type | Returned by |
|---|---|
ParsePathError | parse_path, transform_path |
