pub struct Scatter { /* private fields */ }
Implementations§
Source§impl Scatter
impl Scatter
Sourcepub fn eval(&self, coords: DVector<f64>) -> DVector<f64>
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
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}
Sourcepub fn create(
centers: Vec<DVector<f64>>,
vals: Vec<DVector<f64>>,
basis: Basis,
order: usize,
) -> Scatter
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
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§
impl Freeze for Scatter
impl RefUnwindSafe for Scatter
impl Send for Scatter
impl Sync for Scatter
impl Unpin for Scatter
impl UnwindSafe for Scatter
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
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.