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), and simplify a polyline.

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.9", default-features = false, features = ["geometry"] }

Import path: helpers4::geometry.

ItemWhat it does
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.
MatrixA 2D affine transformation (a 2×3 matrix), in the layout of CSS and SVG matrix(a, b, c, d, e, f):
PointA point in 2D space.
RectAn axis-aligned rectangle: its top-left corner and its size.
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.