Struct Field

Source
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: Point

Top 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>

Source

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§

Source§

impl<'a> Clone for Field<'a>

Source§

fn clone(&self) -> Field<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Field<'a>

Source§

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

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

impl<'a> PartialEq for Field<'a>

Source§

fn eq(&self, other: &Field<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.