-
Notifications
You must be signed in to change notification settings - Fork 55
Implement TrapezoidalDecomposer::decompose using sweep-line algorithm
#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
base: master
Are you sure you want to change the base?
Conversation
e8c0c41 to
7669f4a
Compare
|
|
||
| return {begin_index, end_index}; | ||
| } | ||
| std::pair<size_t, size_t> decompose(size_t polygon_id, std::vector<point_type> const & points); |
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.
Separate the implementation below.
| if (m_trapezoids->ndim() == 3) | ||
| { | ||
| edge.z_at_lower_y = p1.z(); | ||
| edge.dzdy = (p2.z() - p1.z()) / (p2.y() - p1.y()); |
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.
Since Z is still TODO, not sure if we should throw.
|
|
||
| size_t const begin_index = m_trapezoids->size(); | ||
|
|
||
| std::map<value_type, SweepEvent> events; // y-value to events starting at that y |
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.
New implementation starting from here.
| m_trapezoids->append(lower_x0, y_current, lower_x1, y_current, upper_x1, y_next, upper_x0, y_next); | ||
| } | ||
| } | ||
| } |
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.
New implementation ending here.
| std::vector<Edge> active_edges; | ||
|
|
||
| // Sweep from bottom to top | ||
| for (size_t i = 0; i < y_values.size() - 1; ++i) |
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.
From buttom to the top, sweeping the line one by one with each unique y value.
| return {begin_index, begin_index}; | ||
| } | ||
|
|
||
| std::vector<Edge> active_edges; |
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.
Active edges are the edges that bound the current trapezoidal region.
| namespace modmesh | ||
| { | ||
|
|
||
| TEST(TrapezoidalDecomposer, simple_rectangle) |
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.
All the cases are generated by AI and are manually checked and modified.
7669f4a to
c6cdc4c
Compare
|
@yungyuc Please help review the PR, thank you! |
Implemented TrapezoidalDecomposer::decompose using a sweep-line approach and added test cases in gtest.
AI usage: Copilot + Claude 4.5 generating the test cases, VSCode IntelliSense for auto-completion, ChatGPT 5.2 for discussing the algorithm.