Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SegmentsIntersection::Segment::first_loc1 is OnEdge([1.0, 0.0]) instead of OnVertex(0) #109

Open
wlinna opened this issue Nov 20, 2022 · 1 comment

Comments

@wlinna
Copy link
Contributor

wlinna commented Nov 20, 2022

When using segments_intersection2d, I get misleading results. Instead of first_loc1 being OnVertex(0), I get OnEdge([1.0, 0.0]). While they represent the same point, the result is misleading since the doc comment of OnEdge says
The point lies on the segment interior., and OnVertex would be more precise. One should also note that OnEdge([1.0, 0.0]) != OnVertex(0).

When I run the following code:

use rapier2d::prelude::*;

let seg1 = Segment::new(point![10.0, 0.0], point![10.0, 10.0]);
let seg2 = Segment::new(point![10.0, 0.0], point![10.0, 10.0]);

let intersection = rapier2d::parry::utils::segments_intersection2d(&seg1.a, &seg1.b, &seg2.a, &seg2.b, 0.0).unwrap();

let rapier2d::parry::utils::SegmentsIntersection::Segment { first_loc1, first_loc2, second_loc1, second_loc2 } = intersection else {
    unreachable!("The intersection should be a Segment intersection!");
};

dbg!(first_loc1);
dbg!(first_loc2);
dbg!(second_loc1);
dbg!(second_loc2);

The output is

first_loc1 = OnEdge([1.0, 0.0])
first_loc2 = OnVertex(0)
second_loc1 = OnEdge([0.0, 1.0,])
second_loc2 = OnVertex(1)

The output should be:

first_loc1 = OnVertex(0)
first_loc2 = OnVertex(0)
second_loc1 = OnVertex(1)
second_loc2 = OnVertex(1)

rustc: 1.65
parry2d: tested on 0.10 and 0.11.1

@wlinna
Copy link
Contributor Author

wlinna commented May 1, 2024

I tested this on parry2d 0.14, and the bug still exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant