pub struct Rasterizer<Label> { /* private fields */ }
Expand description
Rasterizer rasterizes shapes like BinaryRasterizer but instead
of making a boolean array, it produces an array of some generic
type (Label
) that implements Copy and
Add though typically you’d use a numeric type.
You can call new or use LabelBuilder to
construct Rasterizer instances. Constructing one requires a
width
, height
and optional geo_to_pix
transform in addition
to background
which specifies the default Label
value used to
fill the raster array. And you can provide a MergeAlgorithm
value to specify what the rasterizer should do when two different
shapes fill the same pixel. If you don’t supply anything, the
rasterizer will use Replace by default.
use geo::{Geometry, Line, Point};
use ndarray::array;
let point = Point::new(3, 4);
let line = Line::new((0, 3), (3, 0));
let mut rasterizer = LabelBuilder::background(0).width(4).height(5).build()?;
rasterizer.rasterize(&point, 7)?;
rasterizer.rasterize(&line, 3)?;
let pixels = rasterizer.finish();
assert_eq!(
pixels.mapv(|v| v as u8),
array![
[0, 0, 3, 0],
[0, 3, 3, 0],
[3, 3, 0, 0],
[3, 0, 0, 0],
[0, 0, 0, 7]
]
);
Implementations§
Source§impl<Label> Rasterizer<Label>
impl<Label> Rasterizer<Label>
pub fn new( width: usize, height: usize, geo_to_pix: Option<Transform>, algorithm: MergeAlgorithm, background: Label, ) -> 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,
foreground: Label,
) -> Result<()>where
InputShape: MapCoords<Coord, f64, Output = ShapeAsF64>,
ShapeAsF64: Rasterize<Label> + 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,
foreground: Label,
) -> Result<()>where
InputShape: MapCoords<Coord, f64, Output = ShapeAsF64>,
ShapeAsF64: Rasterize<Label> + 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<Label: Clone> Clone for Rasterizer<Label>
impl<Label: Clone> Clone for Rasterizer<Label>
Source§fn clone(&self) -> Rasterizer<Label>
fn clone(&self) -> Rasterizer<Label>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl<Label> Freeze for Rasterizer<Label>where
Label: Freeze,
impl<Label> RefUnwindSafe for Rasterizer<Label>where
Label: RefUnwindSafe,
impl<Label> Send for Rasterizer<Label>where
Label: Send,
impl<Label> Sync for Rasterizer<Label>where
Label: Sync,
impl<Label> Unpin for Rasterizer<Label>where
Label: Unpin,
impl<Label> UnwindSafe for Rasterizer<Label>where
Label: UnwindSafe + RefUnwindSafe,
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
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>
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>
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