Skip to content

lucem_hist::polygon

Outlines: area, perimeter, centroid, point inside, and labels traced into outlines.

pub fn area(p: &[Point]) -> f64
pub fn perimeter(p: &[Point]) -> f64
pub fn centroid(p: &[Point]) -> Point

The centroid of the enclosed area (the mean of the points for a degenerate outline).

pub fn contains(p: &[Point], q: Point) -> bool

Whether q is inside p (even-odd rule).

pub fn bounds(p: &[Point]) -> (f64, f64, f64, f64)

The bounding box (x0, y0, x1, y1).

pub fn trace_labels(
labels: &[u32],
w: usize,
h: usize,
origin: Point,
ds: f64,
) -> Vec<(u32, Polygon)>

The outer outline of every label of a w × h raster (pixel corners, level-0 pixels: origin + corner · ds), by label. Each pixel side between a label and anything else is an edge; edges chain into loops and the largest loop of a label is its outline (holes are left out). Points along straight runs are dropped.

pub fn fill(
p: &[Point],
raster: &mut [u32],
w: usize,
h: usize,
origin: Point,
ds: f64,
value: u32,
)

Fills p (level-0 pixels) into a w × h raster of a region at origin with ds level-0 pixels per raster pixel: pixels whose centre is inside get value.