fn geobounds_min2(a: f64, b: f64) -> f64 { if a < b { return a; } b } fn geobounds_max2(a: f64, b: f64) -> f64 { if a > b { return a; } b } fn geobounds_finite(values: vector) -> bool { let mut i = 0; while i < len(values) { let value = at(values, i); if !(value - value == 0.0) { return false; } i += 1; } true } fn geobounds_compute(east: vector, north: vector) -> vector { if len(east) == 0 || len(east) != len(north) { return []; } let mut west = at(east, 0); let mut right = west; let mut south = at(north, 0); let mut top = south; let mut i = 1; while i < len(east) { west = geobounds_min2(west, at(east, i)); right = geobounds_max2(right, at(east, i)); south = geobounds_min2(south, at(north, i)); top = geobounds_max2(top, at(north, i)); i += 1; } [west, south, right, top] } // Find a projected planar extent from paired point coordinates. // Returns [west, south, east, north]. A single point has a zero-area extent. Supply a common planar CRS for both axes. pub fn geobounds_extent(east: vector, north: vector) -> vector { if !geobounds_finite(east) { return []; } if !geobounds_finite(north) { return []; } let result = geobounds_compute(east, north); if !geobounds_finite(result) { return []; } result }