-
-
Notifications
You must be signed in to change notification settings - Fork 930
Fix issue with convex hull #2151
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
base: main
Are you sure you want to change the base?
Changes from all commits
d2033c9
2f67d22
0591a46
26ef1a1
8f7b84b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,8 +88,8 @@ void Shape::makeConvex() | |
|
|
||
| for (const auto window : poly | ranges::views::sliding(2)) | ||
| { | ||
| const Point2LL& current = window[0]; | ||
| const Point2LL& after = window[1]; | ||
| const auto& current = window[0]; | ||
| const auto& after = window[1]; | ||
|
|
||
| if (LinearAlg2D::pointIsLeftOfLine(current, convexified.back(), after) < 0) | ||
| { | ||
|
|
@@ -103,6 +103,11 @@ void Shape::makeConvex() | |
| convexified.push_back(current); | ||
| } | ||
| } | ||
|
|
||
| while (convexified.size() >= 2 && (LinearAlg2D::pointIsLeftOfLine(convexified.back(), convexified[convexified.size() - 2], poly.back()) >= 0)) | ||
| { | ||
| convexified.pop_back(); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to fix the symptom rather than the root cause of the issue, or is it the actual proper way of fixing this ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has been some time ago that I wrote this code. But from what I recall this was indeed a proper fix since we did not properly account for the end points in the top and bottom convex hull's.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, just re-read the code. This is indeed the proper fix. We're doing the following things.
The issue here is that we're always adding the current point in step 2.b. However, it could be that the last point(s) are not on the convex hull (due to the stable sort sorting first on x then on y, so either for the forward pass or backward pass it could be that the last inserted point is not on the convex hull). This code is to fix this oversight where keep removing the last point(s) untill all points are convex. |
||
| }; | ||
|
|
||
| std::stable_sort( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need for this change ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we also don't write type names for
for (const auto& x : xs). This is just the extension of a for loop iterator variable imo.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I would say it makes it even more confusing because of the
windownot being typed. Now if you want to know what types arecurrentandafter, you have to go up to the definition ofpoly. Not super annoying in this case because it is just above, but I really don't see the value in changing a readable typed object toauto. But I know we do have different personal opinions about this topic 😃There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
official CPP guidelines talk about AAA (almost always use auto), see https://cginternals.github.io/guidelines/articles/almost-always-auto/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, but I still don't agree with this paradigm. There are benefits, but according to me they are lesser than the issues it brings, especially on read-expliciteness and the risk of error that it adds of using a wrong type.
I don't really understand that popular languages like Python and JS got a typed-ish version, but on the other side, C++ is moving towards loosely-typed. In some specific cases,
autoreally saves your day, but the AAA principle looks really counter-intuitive to me.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most (all) languages are converging to the same paradigm. That is use strong types for function annotations, use types when it's really needed, like rust
Here you have to use
i32otherwise the compiler doens't know to what type it should parse.but simple variable declarations type annotations do more harm then good. They introduce large git diffs when types changes, introduce visual clutter and longer lines. And especially for cpp there is a risk of un intentional type conversions.