Open Ughuuu opened 3 weeks ago
I too have this issue. I would suggest a change to the epsilon used in _from_convexpolyline making it much smaller:
let eps = 2.0 * crate::math::DEFAULT_EPSILON;
It would be nice to have the tolerance/epsilon as a parameter, in which case it could be disabled by making it zero. I bet that change would be quite disruptive though.
Related to this matter, here are also some unit tests I've added to my local version of parry2d (convex_polygon.rs):
#[test]
fn test_convex_polyline_for_stretched_quad() {
let vertices = vec![
Point::new(-35.0, 0.0),
Point::new(38.0, 0.0),
Point::new(39.0, 1.0),
Point::new(17.0, 1.0),
];
let expected_points = [
Point::new(-35.0, 0.0),
Point::new(38.0, 0.0),
Point::new(39.0, 1.0),
Point::new(17.0, 1.0),
]; // No change
let collider = ConvexPolygon::from_convex_polyline(vertices).unwrap();
assert_eq!(collider.points(), expected_points);
}
#[test]
fn test_convex_polyline_for_basicly_triangle() {
let vertices = vec![
Point::new(-1000.0, 0.0),
Point::new(1000.0, 0.0),
Point::new(1000.0, 1.0),
Point::new(-0.01, 0.5),
];
let expected_points = [
Point::new(-1000.0, 0.0),
Point::new(1000.0, 0.0),
Point::new(1000.0, 1.0),
];
let collider = ConvexPolygon::from_convex_polyline(vertices).unwrap();
assert_eq!(collider.points(), expected_points);
}
Right now if I create a
ConvexPolygon
I usefrom_convex_polyline
, however sometimes this will remove some points. Give option to not remove the points (eg. default constructor or simpler constructor).