ki

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

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.