@@ 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