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

Give option to not remove vertices when constructing ConvexPolyline and other such shapes #277

Open
Ughuuu opened this issue Oct 6, 2024 · 1 comment · May be fixed by #278
Open

Give option to not remove vertices when constructing ConvexPolyline and other such shapes #277

Ughuuu opened this issue Oct 6, 2024 · 1 comment · May be fixed by #278

Comments

@Ughuuu
Copy link
Contributor

Ughuuu commented Oct 6, 2024

Right now if I create a ConvexPolygon I use from_convex_polyline, however sometimes this will remove some points. Give option to not remove the points (eg. default constructor or simpler constructor).

@WaffeFIN
Copy link

I too have this issue. I would suggest a change to the epsilon used in from_convex_polyline 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);
}

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

Successfully merging a pull request may close this issue.

2 participants