-
Notifications
You must be signed in to change notification settings - Fork 631
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
fix(autoware_utils): address self-intersecting polygons in random_concave_generator and handle empty inners() during triangulation #8995
base: main
Are you sure you want to change the base?
Changes from 4 commits
3e35f7c
5960d28
4449916
b93d4bd
e141914
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2024 TIER IV, Inc. | ||
Check notice on line 1 in common/autoware_universe_utils/src/geometry/ear_clipping.cpp CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)✅ Getting better: Overall Code Complexity
|
||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
|
@@ -420,6 +420,9 @@ | |
std::vector<std::size_t> queue; | ||
|
||
for (const auto & ring : inners) { | ||
if (ring.empty()) { | ||
continue; | ||
} | ||
auto inner_index = linked_list(ring, false, vertices, points); | ||
|
||
if (points[inner_index].next_index.value() == inner_index) { | ||
|
@@ -561,6 +564,28 @@ | |
} | ||
} | ||
|
||
double calculate_triangle_area(const autoware::universe_utils::Polygon2d & triangle) | ||
{ | ||
const auto & points = triangle.outer(); | ||
double x1 = points[0].x(); | ||
double y1 = points[0].y(); | ||
double x2 = points[1].x(); | ||
double y2 = points[1].y(); | ||
double x3 = points[2].x(); | ||
double y3 = points[2].y(); | ||
|
||
return std::abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0); | ||
} | ||
|
||
double calculate_total_triangle(const std::vector<autoware::universe_utils::Polygon2d> & triangles) | ||
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. the name of this function is not clear. 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. Ok, I will move the function to |
||
{ | ||
double totalArea = 0.0; | ||
for (const auto & triangle : triangles) { | ||
totalArea += calculate_triangle_area(triangle); | ||
} | ||
return totalArea; | ||
} | ||
|
||
std::vector<LinkedPoint> perform_triangulation( | ||
const alt::Polygon2d & polygon, std::vector<std::size_t> & indices) | ||
{ | ||
|
@@ -617,10 +642,6 @@ | |
std::vector<Polygon2d> triangulate(const Polygon2d & poly) | ||
{ | ||
const auto alt_poly = alt::Polygon2d::create(poly); | ||
if (!alt_poly.has_value()) { | ||
return {}; | ||
} | ||
|
||
const auto alt_triangles = triangulate(alt_poly.value()); | ||
std::vector<Polygon2d> triangles; | ||
for (const auto & alt_triangle : alt_triangles) { | ||
|
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.
Can you add a source for this formula ?
Or if this function is only needed for the test then just use
boost::geometry::area
in the tests.