~raph/interp-toy

abff8f3807109cf1573ccc09b435557a6bce8dec — Raph Levien 2 years ago 3ff2c40
Add linear option

It's not bilinear though in higher dimensions, actually polyharmonic
with order 1.
2 files changed, 10 insertions(+), 7 deletions(-)

M src/app_state.rs
M src/main.rs
M src/app_state.rs => src/app_state.rs +8 -6
@@ 25,13 25,14 @@ pub struct AppState {

#[derive(Clone, Copy, PartialEq)]
pub enum InterpType {
    ThinPlate,
    Gaussian,
    ThinPlate,
    Linear,
}

impl Default for InterpType {
    fn default() -> Self {
        InterpType::ThinPlate
        InterpType::Gaussian
    }
}



@@ 222,12 223,13 @@ impl InterpPt {
            centers.push(DVector::from_vec(vec![sample.width, sample.weight]));
            vals.push(DVector::from_vec(vec![sample.pt.x, sample.pt.y]));
        }
        let basis = match interp_type {
            InterpType::ThinPlate => Basis::PolyHarmonic(2),
        let (basis, order) = match interp_type {
            InterpType::ThinPlate => (Basis::PolyHarmonic(2), 2),
            // TODO: control over radius
            InterpType::Gaussian => Basis::Gaussian(1.0),
            InterpType::Gaussian => (Basis::Gaussian(1.0), 2),
            InterpType::Linear => (Basis::PolyHarmonic(1), 1),
        };
        let scatter = Scatter::create(centers, vals, basis, 2);
        let scatter = Scatter::create(centers, vals, basis, order);
        let params = DVector::from_vec(vec![width, weight]);
        let interp = scatter.eval(params);
        Point::new(interp[0], interp[1])

M src/main.rs => src/main.rs +2 -1
@@ 34,8 34,9 @@ fn build_ui() -> impl Widget<AppState> {
    col.add_child(
        LensWrap::new(
            radio(vec![
                (InterpType::ThinPlate, LocalizedString::new("Thin plate")),
                (InterpType::Gaussian, LocalizedString::new("Gaussian")),
                (InterpType::ThinPlate, LocalizedString::new("Thin plate")),
                (InterpType::Linear, LocalizedString::new("Linear")),
            ]),
            lenses::app_state::InterpType,
        ),