pub struct Quantizer { /* private fields */ }Expand description
Rounds float polygons onto the integer grid, keeping a valid polygon valid.
use geo_types::coord;
use map_tile_toolkit::Quantizer;
let mut quantizer = Quantizer::new();
let exterior = [coord! { x: 0.2, y: 0.1 }, coord! { x: 9.7, y: 0.4 }, coord! { x: 5.1, y: 8.6 }];
let rounded = quantizer.polygon([exterior]).unwrap();
let polygons: Vec<Vec<&[_]>> = rounded.polygons().map(Iterator::collect).collect();
assert_eq!(polygons, [[&[coord! { x: 0, y: 0 }, coord! { x: 10, y: 0 }, coord! { x: 5, y: 9 }][..]]]);Implementations§
Source§impl Quantizer
impl Quantizer
Sourcepub fn polygon<R>(&mut self, rings: R) -> Result<Quantized<'_>, TileError>
pub fn polygon<R>(&mut self, rings: R) -> Result<Quantized<'_>, TileError>
Rounds one valid polygon’s rings, exterior first, in grid units, into valid polygons.
§Errors
TileError::Overflow if a coordinate is not finite or rounds outside the i32 range.
Sourcepub fn multi_polygon<P>(
&mut self,
polygons: P,
) -> Result<Quantized<'_>, TileError>where
P: IntoIterator,
P::Item: IntoIterator,
<P::Item as IntoIterator>::Item: IntoIterator<Item = Coord<f64>>,
pub fn multi_polygon<P>(
&mut self,
polygons: P,
) -> Result<Quantized<'_>, TileError>where
P: IntoIterator,
P::Item: IntoIterator,
<P::Item as IntoIterator>::Item: IntoIterator<Item = Coord<f64>>,
Rounds a multipolygon’s polygons, each its rings, exterior first, in grid units, into valid
polygons.
Each polygon must be valid on its own, as for Self::polygon, but they may touch or overlap:
parts whose rounded rings meet or overlap merge into one polygon.
§Errors
TileError::Overflow if a coordinate is not finite or rounds outside the i32 range.
Sourcepub fn make_valid<R>(&mut self, rings: R) -> Result<Quantized<'_>, TileError>
pub fn make_valid<R>(&mut self, rings: R) -> Result<Quantized<'_>, TileError>
Rounds any polygon’s rings, exterior first, in grid units, into valid polygons.
The area kept is what the exterior covers, minus what any hole covers.
§Errors
TileError::Overflow if a coordinate is not finite or rounds outside the i32 range.