pub struct DensityMap { /* private fields */ }
Expand description
Density map that contains density data and steepness per pixel.
Implementations§
Source§impl DensityMap
impl DensityMap
Sourcepub fn new(
width: usize,
height: usize,
scale: usize,
data: Vec<u8>,
) -> Result<Self, DensityMapError>
pub fn new( width: usize, height: usize, scale: usize, data: Vec<u8>, ) -> Result<Self, DensityMapError>
Create new density map.
§Arguments
width
- Columns.height
- Rows.scale
- Scale.data
- Raw pixel data.
§Returns
Density map or error.
§Examples
use density_mesh_core::prelude::*;
assert!(DensityMap::new(2, 2, 1, vec![0, 1, 2, 3]).is_ok());
assert_eq!(
DensityMap::new(1, 2, 1, vec![0, 1, 2, 3]),
Err(DensityMapError::WrongDataLength(4, 2)),
);
Sourcepub fn unscaled_width(&self) -> usize
pub fn unscaled_width(&self) -> usize
Returns unscaled width.
Sourcepub fn unscaled_height(&self) -> usize
pub fn unscaled_height(&self) -> usize
Returns unscaled height.
Sourcepub fn value_at_point(&self, point: (isize, isize)) -> Scalar
pub fn value_at_point(&self, point: (isize, isize)) -> Scalar
Sourcepub fn steepness_at_point(&self, point: (isize, isize)) -> Scalar
pub fn steepness_at_point(&self, point: (isize, isize)) -> Scalar
Sourcepub fn value_steepness_iter<'a>(
&'a self,
) -> impl Iterator<Item = (usize, usize, Scalar, Scalar)> + 'a
pub fn value_steepness_iter<'a>( &'a self, ) -> impl Iterator<Item = (usize, usize, Scalar, Scalar)> + 'a
Returns iterator over values and steepness buffers.
§Examples
use density_mesh_core::prelude::*;
let map = DensityMap::new(2, 2, 1, vec![2, 2, 4, 4])
.unwrap()
.value_steepness_iter()
.collect::<Vec<_>>();
assert_eq!(
map,
vec![
(0, 0, 0.007843138, 0.011764706),
(1, 0, 0.007843138, 0.011764707),
(0, 1, 0.015686275, 0.01633987),
(1, 1, 0.015686275, 0.01633987),
],
);
Sourcepub fn change(
&mut self,
col: usize,
row: usize,
width: usize,
height: usize,
data: Vec<u8>,
) -> Result<(), DensityMapError>
pub fn change( &mut self, col: usize, row: usize, width: usize, height: usize, data: Vec<u8>, ) -> Result<(), DensityMapError>
Change density map region data (replace “pixels”) - this recalculates internals.
§Arguments
col
- Column index.row
- Row index.width
- Number of columns.height
- Number of rows.data
- Data to replace with.
Trait Implementations§
Source§impl Clone for DensityMap
impl Clone for DensityMap
Source§fn clone(&self) -> DensityMap
fn clone(&self) -> DensityMap
Returns a copy 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 moreSource§impl Debug for DensityMap
impl Debug for DensityMap
Source§impl Default for DensityMap
impl Default for DensityMap
Source§fn default() -> DensityMap
fn default() -> DensityMap
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for DensityMap
impl<'de> Deserialize<'de> for DensityMap
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for DensityMap
impl PartialEq for DensityMap
Source§impl Serialize for DensityMap
impl Serialize for DensityMap
impl StructuralPartialEq for DensityMap
Auto Trait Implementations§
impl Freeze for DensityMap
impl RefUnwindSafe for DensityMap
impl Send for DensityMap
impl Sync for DensityMap
impl Unpin for DensityMap
impl UnwindSafe for DensityMap
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