Skip to main content

Quantizer

Struct Quantizer 

Source
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

Source

pub fn new() -> Self

An empty quantizer.

Source

pub fn polygon<R>(&mut self, rings: R) -> Result<Quantized<'_>, TileError>
where R: IntoIterator, R::Item: IntoIterator<Item = Coord<f64>>,

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.

Source

pub fn multi_polygon<P>( &mut self, polygons: P, ) -> Result<Quantized<'_>, TileError>

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.

Source

pub fn make_valid<R>(&mut self, rings: R) -> Result<Quantized<'_>, TileError>
where R: IntoIterator, R::Item: IntoIterator<Item = Coord<f64>>,

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.

Trait Implementations§

Source§

impl Clone for Quantizer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Quantizer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Quantizer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.