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)
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
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);
}
}
}
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)
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
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§
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.