~raph/bezoid

0d19b67a88b934b43032983f51c2a85f9be2c74e — Raph Levien 1 year, 6 months ago 5d397ea
Better calibration

Smoother mapping between curve handles and parameters.
1 files changed, 6 insertions(+), 10 deletions(-)

M src/solve.rs
M src/solve.rs => src/solve.rs +6 -10
@@ 2,7 2,7 @@

use druid::kurbo::{CubicBez, ParamCurveArclen, Point};

use crate::bezoid::{CurveParams, BEZ_BIAS_EXP, BEZ_CHORD_EXP};
use crate::bezoid::CurveParams;

pub struct Solver;



@@ 14,14 14,11 @@ impl Solver {
    pub fn solve(&self, p1: Point, p2: Point) -> CurveParams {
        println!("({:.3}, {:.3}) ({:.3}, {:.3})", p1.x, p1.y, p2.x, p2.y);
        fn inv_arm_len(h: f64, chord: f64) -> f64 {
            let a = h * 3.0 * chord.powf(2.0);
            let bias = 2.0 - a.powf(1.0 / BEZ_BIAS_EXP);
            // Note: with the correction below, it no longer matches
            // arm_len in infer_bezier.
            if bias > 0.0 {
                bias
            let a = h * 3.0 * chord.powf(1.0);
            if a < 1.0 {
                2.0 - a.powf(2.0)
            } else {
                (0.5 * bias).tanh()
                1.0 + 2.0 * (0.5 * (1.0 - a)).tanh()
            }
        }
        let v1 = p1.to_vec2();


@@ 52,8 49,7 @@ impl Solver {
            }
            // Secant method
            let nextxy = (dth, th_err);
            let delta = if i >= 1 {
                let lastxy = lastxy.unwrap();
            let delta = if let Some(lastxy) = lastxy {
                (nextxy.0 - lastxy.0) / (nextxy.1 - lastxy.1)
            } else {
                -0.5