Skip to content

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).

Cargo feature geometry (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features geometry

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.11", default-features = false, features = ["geometry"] }

Import path: helpers4::geometry.

ItemWhat it does
ellipse_pathThe path of the ellipse that fills a box, as SVG path data: two half-turn arcs.
FitAlignWhere 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.
FitModeHow fit sizes content in a container, as CSS object-fit.
fitPlaces content in a container like CSS object-fit and object-position, e.g.
format_pathWrites 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).
MatrixA 2D affine transformation (a 2×3 matrix), in the layout of CSS and SVG matrix(a, b, c, d, e, f):
parse_pathParses 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).
PathCommandOne 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.
PointA point in 2D space.
RectAn axis-aligned rectangle: its top-left corner and its size.
rounded_rect_pathThe path of a rectangle with a radius per corner, as SVG path data.
simplify_polylineRemoves 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.
SizeA width and a height.
transform_pathTransforms SVG path data by a matrix.

Documented on the page of the helper that returns them.

TypeReturned by
ParsePathErrorparse_path, transform_path