Struct Scatter

Source
pub struct Scatter { /* private fields */ }

Implementations§

Source§

impl Scatter

Source

pub fn eval(&self, coords: DVector<f64>) -> DVector<f64>

Examples found in repository?
examples/simple.rs (line 19)
7fn main() {
8    let mut xs = Vec::with_capacity(10);
9    let mut ys = Vec::with_capacity(10);
10    for i in 0..10 {
11        let x = 0.2 * (i as f64);
12        let y = x.sin();
13        xs.push(DVector::from_vec(vec![x]));
14        ys.push(DVector::from_vec(vec![y]));
15    }
16    let scatter = Scatter::create(xs, ys, Basis::PolyHarmonic(2), 2);
17    for i in 0..500 {
18        let x = 0.004 * (i as f64);
19        let y = scatter.eval(DVector::from_vec(vec![x]));
20        println!("{} {} {}", x, y[0], x.sin());
21    }
22}
More examples
Hide additional examples
examples/mutator.rs (line 39)
17fn main() {
18    let locs = SAMPLES
19        .iter()
20        .map(|(loc, _color)| DVector::from_vec(vec![loc[0] as f64 + 0.5, loc[1] as f64 + 0.5]))
21        .collect::<Vec<_>>();
22    let colors = SAMPLES
23        .iter()
24        .map(|(_loc, color)| {
25            DVector::from_vec(vec![color[0] as f64, color[1] as f64, color[2] as f64])
26        })
27        .collect::<Vec<_>>();
28    let scatter = Scatter::create(locs, colors, Basis::PolyHarmonic(2), 2);
29    let width = 460;
30    let height = 460;
31    // Just output ASCII PPM so we don't need to depend on image coders.
32    println!("P3");
33    println!("{} {}", width, height);
34    println!("255");
35    for y in 0..height {
36        for x in 0..width {
37            let u = ((x as f64) * 0.05).floor();
38            let v = ((y as f64) * 0.05).floor();
39            let interp = scatter.eval(DVector::from_vec(vec![u, v]));
40            let r = interp[0].round().max(0.0).min(255.0) as u8;
41            let g = interp[1].round().max(0.0).min(255.0) as u8;
42            let b = interp[2].round().max(0.0).min(255.0) as u8;
43            println!("{} {} {}", r, g, b);
44        }
45    }
46}
Source

pub fn create( centers: Vec<DVector<f64>>, vals: Vec<DVector<f64>>, basis: Basis, order: usize, ) -> Scatter

Examples found in repository?
examples/simple.rs (line 16)
7fn main() {
8    let mut xs = Vec::with_capacity(10);
9    let mut ys = Vec::with_capacity(10);
10    for i in 0..10 {
11        let x = 0.2 * (i as f64);
12        let y = x.sin();
13        xs.push(DVector::from_vec(vec![x]));
14        ys.push(DVector::from_vec(vec![y]));
15    }
16    let scatter = Scatter::create(xs, ys, Basis::PolyHarmonic(2), 2);
17    for i in 0..500 {
18        let x = 0.004 * (i as f64);
19        let y = scatter.eval(DVector::from_vec(vec![x]));
20        println!("{} {} {}", x, y[0], x.sin());
21    }
22}
More examples
Hide additional examples
examples/mutator.rs (line 28)
17fn main() {
18    let locs = SAMPLES
19        .iter()
20        .map(|(loc, _color)| DVector::from_vec(vec![loc[0] as f64 + 0.5, loc[1] as f64 + 0.5]))
21        .collect::<Vec<_>>();
22    let colors = SAMPLES
23        .iter()
24        .map(|(_loc, color)| {
25            DVector::from_vec(vec![color[0] as f64, color[1] as f64, color[2] as f64])
26        })
27        .collect::<Vec<_>>();
28    let scatter = Scatter::create(locs, colors, Basis::PolyHarmonic(2), 2);
29    let width = 460;
30    let height = 460;
31    // Just output ASCII PPM so we don't need to depend on image coders.
32    println!("P3");
33    println!("{} {}", width, height);
34    println!("255");
35    for y in 0..height {
36        for x in 0..width {
37            let u = ((x as f64) * 0.05).floor();
38            let v = ((y as f64) * 0.05).floor();
39            let interp = scatter.eval(DVector::from_vec(vec![u, v]));
40            let r = interp[0].round().max(0.0).min(255.0) as u8;
41            let g = interp[1].round().max(0.0).min(255.0) as u8;
42            let b = interp[2].round().max(0.0).min(255.0) as u8;
43            println!("{} {} {}", r, g, b);
44        }
45    }
46}

Auto Trait Implementations§

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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.