pub struct Field<'a> {
pub dimensions: (usize, usize),
pub top_left: Point,
pub pixel_size: (f32, f32),
pub values: &'a Vec<Vec<i16>>,
}Expand description
Raster heightmap field containing the z-values of each pixel
Fields§
§dimensions: (usize, usize)Amount of x and y pixels in the values field
top_left: PointTop left coordinates
pixel_size: (f32, f32)Size of each pixel (x and y)
values: &'a Vec<Vec<i16>>Z-values of each pixel, stored in rows, then columns
Implementations§
Source§impl<'a> Field<'a>
impl<'a> Field<'a>
Sourcepub fn get_contours(&self, z: i16) -> Vec<Line>
pub fn get_contours(&self, z: i16) -> Vec<Line>
Examples found in repository?
examples/function.rs (line 36)
4fn main() {
5 // Build the field
6
7 let width = 1600_usize;
8 let height = 1600_usize;
9 let n_steps = 10_usize;
10
11 let mut min_val = 0;
12 let mut max_val = 0;
13
14 let z_values = (0..height).map(|y| {
15 (0..width).map(|x| {
16 let x = (x as f64 - width as f64 / 2.0) / 150.0;
17 let y = (y as f64 - height as f64 / 2.0) / 150.0;
18 let val = ((1.3 * x).sin() * (0.9 * y).cos() + (0.8 * x).cos() * (1.9 * y).sin() + (y * 0.2 * x).cos()) as i16;
19 min_val = min_val.min(val);
20 max_val = max_val.max(val);
21 val
22 }).collect()
23 }).collect::<Vec<Vec<i16>>>();
24
25 let field = Field {
26 dimensions: (width, height),
27 top_left: Point { x: 0.0, y: 0.0 },
28 pixel_size: (1.0, 1.0),
29 values: &z_values,
30 };
31
32 let step_size = (max_val - min_val) as f32 / n_steps as f32;
33
34 for step in 0..n_steps {
35 let isoline_height = min_val as f32 + (step_size * step as f32);
36 println!("{:#?}", field.get_contours(isoline_height as i16));
37 }
38}Trait Implementations§
impl<'a> StructuralPartialEq for Field<'a>
Auto Trait Implementations§
impl<'a> Freeze for Field<'a>
impl<'a> RefUnwindSafe for Field<'a>
impl<'a> Send for Field<'a>
impl<'a> Sync for Field<'a>
impl<'a> Unpin for Field<'a>
impl<'a> UnwindSafe for Field<'a>
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