Skip to content

Commit

Permalink
Add the 'broken' curve from #25 and test with the exist 'far away' test
Browse files Browse the repository at this point in the history
(This does seem to show the main issue; there's also a problem with some points returning very odd results included in this issue; hopefully they're the same)
  • Loading branch information
Logicalshift committed May 13, 2023
1 parent 303e05a commit c1310d5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/bezier/nearest_point_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ where
let t = (t as f64) / 100.0;
let test_point = test_line.point_at_pos(t);
let nearest = curve.nearest_point(&test_point);
let iter_nearest = curve.point_at_pos(nearest_t_value_iteration(curve, &test_point));
let iter_nearest_t = nearest_t_value_iteration(curve, &test_point);
let iter_nearest = curve.point_at_pos(iter_nearest_t);

let nearest_t = curve.nearest_t(&test_point);
let tangent = de_casteljau3(nearest_t, qn1, qn2, qn3);

// Log some information if there's a discrepency between the nearest point found by iteration and the nearest point found by the 'nearest point' algorithm
if iter_nearest.distance_to(&nearest) >= 0.1 {
// Log the t position and the distance between the curve, plus the distance between the point we found and the curve
println!("t={:?} distance={:?} ({:?} {:?}) to_curve={:?} to_curve_iter={:?}", t, iter_nearest.distance_to(&nearest), nearest, iter_nearest, test_point.distance_to(&nearest), test_point.distance_to(&iter_nearest));
println!("t={:?} distance={:?} ({:?} {:?}) to_curve={:?} to_curve_iter={:?} nearest_t={:?} (should be {:?})", t, iter_nearest.distance_to(&nearest), nearest, iter_nearest, test_point.distance_to(&nearest), test_point.distance_to(&iter_nearest), nearest_t, iter_nearest_t);
println!(" t={:?} distance={:?} ({:?} {:?})", t-0.01, iter_nearest.distance_to(&curve.nearest_point(&test_line.point_at_pos(t-0.01))), curve.nearest_point(&test_line.point_at_pos(t-0.01)), iter_nearest);
println!(" t={:?} distance={:?} ({:?} {:?})", t+0.01, iter_nearest.distance_to(&curve.nearest_point(&test_line.point_at_pos(t+0.01))), curve.nearest_point(&test_line.point_at_pos(t+0.01)), iter_nearest);

Expand Down Expand Up @@ -142,3 +143,10 @@ fn nearest_point_on_curve_newton_raphson_4() {

test_far_away_points(&curve);
}

#[test]
fn nearest_point_on_curve_newton_raphson_5() {
let curve = bezier::Curve::from_points(Coord2(259.0, 322.0), (Coord2(272.0, 329.0), Coord2(297.0, 341.0)), Coord2(350.0, 397.0));

test_far_away_points(&curve);
}

0 comments on commit c1310d5

Please sign in to comment.