Skip to content

Conversation

@tigercosmos
Copy link
Collaborator

@tigercosmos tigercosmos commented Feb 2, 2026

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.


return {begin_index, end_index};
}
std::pair<size_t, size_t> decompose(size_t polygon_id, std::vector<point_type> const & points);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate the implementation below.

Comment on lines +1051 to +1054
if (m_trapezoids->ndim() == 3)
{
edge.z_at_lower_y = p1.z();
edge.dzdy = (p2.z() - p1.z()) / (p2.y() - p1.y());
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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);
}
}
}
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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.

@tigercosmos
Copy link
Collaborator Author

@yungyuc Please help review the PR, thank you!

@yungyuc yungyuc added the geometry Geometry entities and manipulation label Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

geometry Geometry entities and manipulation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants