-
Notifications
You must be signed in to change notification settings - Fork 7
Description
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):
- image is closer to black when on the curve, moves towards red the farther away from the curve
- 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).
- same as 2, but with values > 200 set to pink (maybe a bit clearer?)
- 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.
- 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!