geokit/bbox
Bounding box computation for a Geometry.
A bounding box is the smallest axis-aligned rectangle that
contains every point of the geometry. The box is reported as the
south-west and north-east corners. Empty inputs produce
EmptyGeometry.
The implementation does not account for the antimeridian: a
geometry that straddles 180° longitude is treated as if the
world were a flat rectangle and produces a box that spans almost
the entire globe in the longitude axis. Antimeridian-aware
bounding boxes (the “narrow” variant chosen by Turfjs,
terraformer, etc.) are an explicit design choice and are out
of scope for this module.
Types
Values
pub fn compute(
geometry geometry: geometry.Geometry,
) -> Result(#(latlng.LatLng, latlng.LatLng), BBoxError)
Compute the bounding box of geometry as #(sw, ne).
pub fn of_points(
points points: List(latlng.LatLng),
) -> Result(#(latlng.LatLng, latlng.LatLng), BBoxError)
Convenience wrapper for callers who already hold a flat list of
points and don’t want to mint a LineString
just to feed it in. Mirrors the
simplify.line_string shape:
LineString carries edge / ordering semantics that
bbox.compute does not actually use, so wrapping a bag of points
in LineString reads as noise at the call site.
import geokit/bbox
import geokit/latlng
let assert Ok(a) = latlng.new(lat: 35.0, lng: 139.0)
let assert Ok(b) = latlng.new(lat: 36.0, lng: 140.0)
let assert Ok(#(sw, ne)) = bbox.of_points([a, b])
Equivalent to bbox.compute(LineString(points)). Empty input
returns EmptyGeometry.