dimforge / parry

2D and 3D collision-detection library for Rust.
https://parry.rs
Apache License 2.0
594 stars 104 forks source link

Wrong figure generated by from_convex_polyline or wrong contains_local_point detection #280

Closed inferrna closed 1 month ago

inferrna commented 1 month ago

I created this

figure path1
in Inkscape then converted it's coordinates in Python console

   rawstr = "57.367384,108.41142 81.080294,133.27454 109.8215,111.12082 92.883499,64.38938 124.27872,46.810956 141.26926,98.512459 153.76969,83.333867 132.725,23.228685 63.342826,37.974172 58.920885,13.485929 163.83905,4.4276218 175.72178,110.3895 122.54345,159.52787 61.43858,183.78039 27.869311,148.54828 30.159801,95.067489 17.082839,41.786926 42.390433,35.638239"
   coords = [[float(m)/200.0 for m in pair.split(",")] for pair in rawstr.split(" ")]
   ", ".join([f"Point2::new({x:.3f}, {y:.3f})" for [x,y] in coords])

and drew it with this code

let points = vec![Point2::new(0.287, 0.542), Point2::new(0.405, 0.666), Point2::new(0.549, 0.556), Point2::new(0.464, 0.322), Point2::new(0.621, 0.234), Point2::new(0.706, 0.493), Point2::new(0.769, 0.417), Point2::new(0.664, 0.116), Point2::new(0.317, 0.190), Point2::new(0.295, 0.067), Point2::new(0.819, 0.022), Point2::new(0.879, 0.552), Point2::new(0.613, 0.798), Point2::new(0.307, 0.919), Point2::new(0.139, 0.743), Point2::new(0.151, 0.475), Point2::new(0.085, 0.209), Point2::new(0.212, 0.178)];
let occluder = ConvexPolygon::from_convex_polyline(points).unwrap();
for x in 0..WIDTH {
    for y in 0..HEIGHT {
        if occluder.contains_local_point(&pixel_pos) {
            img.put_pixel(x, y, Rgb([ 255, 0, 0]));
        }
    }
}

Suddelly it became this

picture ![path1](https://github.com/user-attachments/assets/87827035-f2b3-4bd7-af7c-b7ee221a4c64)

Instead of obviously expected this

picture ![path_filled](https://github.com/user-attachments/assets/8bddfae9-a47f-4edd-ad4e-bb6fbab53f47)

I also tried project_local_point(&pixel_pos, false).is_inside result was the same. (Also solid is undocumented)

inferrna commented 1 month ago

My fault. My polygon actually is a concave one. Close issue.