Skip to content

distance_to/nearest_t returning unexpected results #25

@KevinThierauf

Description

@KevinThierauf

I'm trying to use the distance_to function to check whether a certain point is on a line, but have been receiving unexpected results. I wrote a basic test to showcase this issue (using the image library for displaying). Here is a simple example I've wrote to demonstrate:

for (x, y, pixel) in image.enumerate_pixels_mut() {
    let y = HEIGHT - y;
    let coord = Coord2(x as f64, y as f64);
    let distance = curve.distance_to(&coord);
    if distance.is_nan() {
        *pixel = Rgb([255, 255, 255]);
        panic!();
    } else {
        *pixel = Rgb([min(25 * distance as u32, 255) as u8, 0, 0]);
    }
}

Some curves work as expected, others run into issues. I've provided a couple of images using the curve Coord2(259, 322) Coord2(272, 329) Coord2(297, 341) Coord2(350, 397) (start, c1, c2, end) that hopefully help display this issue: https://imgur.com/a/N0A4BUJ

Quick image descriptions (in order of appearance):

  1. image is closer to black when on the curve, moves towards red the farther away from the curve
  2. same as 1, but with smoother interpolation (previous example has color increase red by 25 out of 255 points per pixel, this image only has the red increase by 1 out of 255 points per pixel).
  3. same as 2, but with values > 200 set to pink (maybe a bit clearer?)
  4. multiple curves rendered (including the one listed above) with some curves seeming to display correctly, others having some artifacts. pixels with a distance < 10 to curve are displayed.
  5. same as 4, but with a thicker line (distance < 10). There are some additional artifacts that are much clearer on this image; there seem to be some random points well outside of the bezier curve range that are returning a distance much closer than they are).

The images also have a single pixel set to a turquoise color where there is a start/end/control point.

I hope this is helpful -- let me know if there's anything I can do to clarify.
Thanks for the great library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions