pub struct BinaryRasterizer { /* private fields */ }
Expand description
A rasterizer that burns shapes into a 2-dimensional boolean array. It can be built either by calling new or using BinaryBuilder.
Each Rasterizer requires a width
and height
measured in pixels
that describe the shape of the output array. They can optionally
take an affine transform that describes how to convert world-space
coordinates into pixel-space coordinates. When a transformer is
supplied, all of its parameters must be finite or
RasterizeError::NonFiniteCoordinate will be returned.
use geo::{Geometry, Line, Point};
use ndarray::array;
use geo_rasterize::BinaryBuilder;
let shapes: Vec<Geometry<i32>> =
vec![Point::new(3, 4).into(),
Line::new((0, 3), (3, 0)).into()];
let mut r = BinaryBuilder::new().width(4).height(5).build()?;
for shape in shapes {
r.rasterize(&shape)?;
}
let pixels = r.finish();
assert_eq!(
pixels.mapv(|v| v as u8),
array![
[0, 0, 1, 0],
[0, 1, 1, 0],
[1, 1, 0, 0],
[1, 0, 0, 0],
[0, 0, 0, 1]
]
);
Implementations§
Source§impl BinaryRasterizer
impl BinaryRasterizer
pub fn new( width: usize, height: usize, geo_to_pix: Option<Transform>, ) -> Result<Self>
Sourcepub fn geo_to_pix(&self) -> Option<Transform>
pub fn geo_to_pix(&self) -> Option<Transform>
Retrieve the transform.
Sourcepub fn rasterize<Coord, InputShape, ShapeAsF64>(
&mut self,
shape: &InputShape,
) -> Result<()>where
InputShape: MapCoords<Coord, f64, Output = ShapeAsF64>,
ShapeAsF64: Rasterize<u8> + for<'a> CoordsIter<'a, Scalar = f64> + MapCoordsInplace<f64>,
Coord: Into<f64> + Copy + Debug + Num + NumCast + PartialOrd,
pub fn rasterize<Coord, InputShape, ShapeAsF64>(
&mut self,
shape: &InputShape,
) -> Result<()>where
InputShape: MapCoords<Coord, f64, Output = ShapeAsF64>,
ShapeAsF64: Rasterize<u8> + for<'a> CoordsIter<'a, Scalar = f64> + MapCoordsInplace<f64>,
Coord: Into<f64> + Copy + Debug + Num + NumCast + PartialOrd,
Rasterize one shape, which can be any type that geo provides
using any coordinate numeric type that can be converted into
f64
.
Trait Implementations§
Source§impl Clone for BinaryRasterizer
impl Clone for BinaryRasterizer
Source§fn clone(&self) -> BinaryRasterizer
fn clone(&self) -> BinaryRasterizer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for BinaryRasterizer
impl RefUnwindSafe for BinaryRasterizer
impl Send for BinaryRasterizer
impl Sync for BinaryRasterizer
impl Unpin for BinaryRasterizer
impl UnwindSafe for BinaryRasterizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more