-
Notifications
You must be signed in to change notification settings - Fork 673
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
feat(autoware_universe_utils): reduce dependence on Boost.Geometry #7778
feat(autoware_universe_utils): reduce dependence on Boost.Geometry #7778
Conversation
Thank you for contributing to the Autoware project! 🚧 If your pull request is in progress, switch it to draft mode. Please ensure:
|
e6b5275
to
805dd1d
Compare
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
805dd1d
to
bb65929
Compare
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
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 did not check all the code in details yet but I think there are a few issues to fix because the PR can be merged.
- the alternative
intersects
only works for convex polygons (whereas theboost
implementation also works for non-convex polygons). - the random test only use convex polygons.
- GJK is already implemented so we should see which implementation to keep.
common/autoware_universe_utils/test/src/geometry/test_geometry.cpp
Outdated
Show resolved
Hide resolved
@@ -583,6 +584,148 @@ std::optional<geometry_msgs::msg::Point> intersect( | |||
*/ | |||
bool intersects_convex(const Polygon2d & convex_polygon1, const Polygon2d & convex_polygon2); | |||
|
|||
// Alternatives for Boost.Geometry ---------------------------------------------------------------- |
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.
(minor) I think the new code could be added to a separate file as the current one is becoming too big.
This can be done in a future PR.
return true; | ||
} | ||
|
||
bool intersects(const alt::ConvexPolygon2d & poly1, const alt::ConvexPolygon2d & poly2) |
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.
GJK is already implemented (https://github.com/autowarefoundation/autoware.universe/blob/main/common/autoware_universe_utils/src/geometry/gjk_2d.cpp) but it only works for convex polygon.
If your goal is to provide an alternative to the boost::geometry::intersects
function, then you need to use a more general algorithm that also works for concave planners.
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 agree, but I already named the class for representing polygons ConvexPolygon2d
and thus I do not expect the input to be concave (at least for now).
} | ||
} | ||
|
||
TEST(geometry, intersects) |
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.
This test should include non-convex polygons.
} | ||
} | ||
|
||
TEST(geometry, intersectsRand) |
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.
This test (and probably the other random tests as well) should also use random non-convex polygons.
@mraditya01 is working on random polygon generation so maybe you can coordinate with him.
return std::abs(point1.x() - point2.x()) <= std::numeric_limits<double>::epsilon() && | ||
std::abs(point1.y() - point2.y()) <= std::numeric_limits<double>::epsilon(); |
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.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7778 +/- ##
===========================================
+ Coverage 15.09% 30.50% +15.41%
===========================================
Files 1967 1352 -615
Lines 135941 105603 -30338
Branches 42122 47098 +4976
===========================================
+ Hits 20520 32217 +11697
+ Misses 92700 64835 -27865
+ Partials 22721 8551 -14170
☔ View full report in Codecov by Sentry. |
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
Signed-off-by: mitukou1109 <mitukou1109@gmail.com>
…utowarefoundation#7778) * add within function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * return nullopt as is Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add disjoint function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add polygon-and-polygon version of intersect function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * use intersect for disjoint Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add test case for disjoint Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * checking intersection of edges is unnecessary Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * return nullopt when no intersection point found Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add distance function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add coveredBy function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add point-polygon variant of distance function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add isAbove function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add divideBySegment function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add convexHull function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add correct function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add area function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change point type to tf2::Vector3 Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * simplify correct function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * push geometry types to namespace Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * match the behavior of Boost.Geometry Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add test cases for benchmarking Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add headers for convex_hull() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * remove polygon-polygon intersect & disjoint function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add intersects function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add touches function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add disjoint function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * minor fix Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change name Polygon to CvxPolygon Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change name CvxPolygon to ConvexPolygon Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * rename intersect function and restore the original Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change function names to snake_case Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * early return Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change point type from tf2::Vector3 to custom struct Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * style(pre-commit): autofix * use alt::Vector2d to represent point Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * convert from boost before time measurement Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add header for std::move Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * avoid using long Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * convert from boost before time measurement Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add point-segment variant of touches function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of point-polygon touches() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of area() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add note for class naming Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of covered_by() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * simplify within() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of covered_by() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of within() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * use operator[] instead of at() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * print point when covered_by() test failed Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * avoid using hypot() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performace of convex_hull() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * remove divide_by_segment() function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * fix test cases Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of touches() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add test case for touches() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of touches() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change type alias PointList to Points2d Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add & fix vector size assertions Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * define epsilon respectively Signed-off-by: mitukou1109 <mitukou1109@gmail.com> --------- Signed-off-by: mitukou1109 <mitukou1109@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Satoshi OTA <44889564+satoshi-ota@users.noreply.github.com>
…utowarefoundation#7778) * add within function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * return nullopt as is Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add disjoint function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add polygon-and-polygon version of intersect function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * use intersect for disjoint Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add test case for disjoint Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * checking intersection of edges is unnecessary Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * return nullopt when no intersection point found Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add distance function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add coveredBy function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add point-polygon variant of distance function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add isAbove function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add divideBySegment function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add convexHull function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add correct function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add area function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change point type to tf2::Vector3 Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * simplify correct function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * push geometry types to namespace Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * match the behavior of Boost.Geometry Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add test cases for benchmarking Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add headers for convex_hull() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * remove polygon-polygon intersect & disjoint function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add intersects function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add touches function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add disjoint function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * minor fix Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change name Polygon to CvxPolygon Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change name CvxPolygon to ConvexPolygon Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * rename intersect function and restore the original Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change function names to snake_case Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * early return Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change point type from tf2::Vector3 to custom struct Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * style(pre-commit): autofix * use alt::Vector2d to represent point Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * convert from boost before time measurement Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add header for std::move Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * avoid using long Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * convert from boost before time measurement Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add point-segment variant of touches function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of point-polygon touches() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of area() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add note for class naming Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of covered_by() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * simplify within() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of covered_by() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of within() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * use operator[] instead of at() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * print point when covered_by() test failed Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * avoid using hypot() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performace of convex_hull() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * remove divide_by_segment() function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * fix test cases Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of touches() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add test case for touches() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of touches() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change type alias PointList to Points2d Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add & fix vector size assertions Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * define epsilon respectively Signed-off-by: mitukou1109 <mitukou1109@gmail.com> --------- Signed-off-by: mitukou1109 <mitukou1109@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Satoshi OTA <44889564+satoshi-ota@users.noreply.github.com>
…utowarefoundation#7778) * add within function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * return nullopt as is Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add disjoint function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add polygon-and-polygon version of intersect function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * use intersect for disjoint Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add test case for disjoint Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * checking intersection of edges is unnecessary Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * return nullopt when no intersection point found Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add distance function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add coveredBy function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add point-polygon variant of distance function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add isAbove function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add divideBySegment function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add convexHull function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add correct function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add area function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change point type to tf2::Vector3 Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * simplify correct function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * push geometry types to namespace Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * match the behavior of Boost.Geometry Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add test cases for benchmarking Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add headers for convex_hull() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * remove polygon-polygon intersect & disjoint function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add intersects function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add touches function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add disjoint function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * minor fix Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change name Polygon to CvxPolygon Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change name CvxPolygon to ConvexPolygon Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * rename intersect function and restore the original Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change function names to snake_case Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * early return Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change point type from tf2::Vector3 to custom struct Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * style(pre-commit): autofix * use alt::Vector2d to represent point Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * convert from boost before time measurement Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add header for std::move Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * avoid using long Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * convert from boost before time measurement Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add point-segment variant of touches function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of point-polygon touches() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of area() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add note for class naming Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of covered_by() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * simplify within() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of covered_by() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of within() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * use operator[] instead of at() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * print point when covered_by() test failed Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * avoid using hypot() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performace of convex_hull() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * remove divide_by_segment() function Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * fix test cases Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of touches() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add test case for touches() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * improve performance of touches() Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * change type alias PointList to Points2d Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * add & fix vector size assertions Signed-off-by: mitukou1109 <mitukou1109@gmail.com> * define epsilon respectively Signed-off-by: mitukou1109 <mitukou1109@gmail.com> --------- Signed-off-by: mitukou1109 <mitukou1109@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Satoshi OTA <44889564+satoshi-ota@users.noreply.github.com> Signed-off-by: xtk8532704 <1041084556@qq.com>
Description
This PR adds the following functions to reduce dependence on Boost.Geometry.
(
boost::geometry
)(
autoware::universe_utils
)area()
area()
convex_hull()
convex_hull()
correct()
correct()
covered_by()
covered_by()
disjoint()
disjoint()
distance()
distance()
equals()
equals()
intersects()
intersects()
touches()
touches()
within()
within()
Notes:
correct()
sorts outer points in clockwise order with respect to the first point AND removes duplicate points.Related links
Parent Issue:
How was this PR tested?
Benchmark result with 500 randomly generated polygons with 9 vertices:
area()
convex_hull()
covered_by()
disjoint()
intersects()
touches()
within()
Notes for reviewers
None.
Interface changes
None.
Effects on system behavior
None.