Skip to content
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

2D polygon robustness #1493

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

2D polygon robustness #1493

wants to merge 4 commits into from

Conversation

bmhan12
Copy link
Contributor

@bmhan12 bmhan12 commented Jan 21, 2025

This PR:

  • Adds robustness example to unit tests from axom::primal::clip() for polygons is unreliable. #1481
  • Fixes robustness issue with 2D polygon clipping by:
    • Adding missing tolerance parameter to intersect overload between plane and segment
    • Generalizing, simplifying logic to handle duplicate vertices in Sutherland–Hodgman algorithm by performing a pass at the end to remove duplicates.

Closes #1481

@bmhan12 bmhan12 added the Primal Issues related to Axom's 'primal component label Jan 21, 2025
Copy link
Member

@rhornung67 rhornung67 left a comment

Choose a reason for hiding this comment

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

Thank you @bmhan12

Copy link
Member

@BradWhitlock BradWhitlock left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this so soon @bmhan12 !

Copy link
Member

@kennyweiss kennyweiss left a comment

Choose a reason for hiding this comment

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

Thanks @bmhan12!

Please note the bugfix in the RELEASE-NOTES before merging

for(int i = 0; i < outputList.numVertices(); i++)
{
int prevIndex = ((i - 1) == -1) ? (outputList.numVertices() - 1) : (i - 1);
if(outputList[i] != outputList[prevIndex])
Copy link
Member

Choose a reason for hiding this comment

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

I have a late follow-up question about this point test. Might tolerances need to apply here too? I ask because I tried the fixed code with 2 quads where the resulting output ought to be a triangle but it outputs a quad where the first 2 points are essentially the same.

void test4()
{
  using Polygon = axom::primal::Polygon<double, 2>;
  using Point = axom::primal::Point<double, 2>;
  constexpr double eps = 1.e-6;

  Polygon p1;
  p1.addVertex(Point{0., 0.});
  p1.addVertex(Point{1., 0.});
  p1.addVertex(Point{1., 1.});
  p1.addVertex(Point{0., 1.});

  Polygon p2;
  p2.addVertex(Point{0., 0.});
  p2.addVertex(Point{0.3, 0.3});
  p2.addVertex(Point{0., 1.});
  p2.addVertex(Point{-0.3, 0.7});

  const auto overlapPoly = axom::primal::clip(p1, p2, eps);
  const auto area = overlapPoly.area();
  std::cout << "subject=" << p1
            << ", clip=" << p2
            << ", overlap=" << overlapPoly
            << ", area=" << area
            << std::endl;

// Leads to a polygon with an extra vertex... area is good.
// subject={4-gon:(0,0),(1,0),(1,1),(0,1)}, clip={4-gon:(0,0),(0.3,0.3),(0,1),(-0.3,0.7)}, overlap={4-gon:(-6.66134e-17,1),(0,1),(0,0),(0.3,0.3)}, area=0.15

}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primal Issues related to Axom's 'primal component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

axom::primal::clip() for polygons is unreliable.
6 participants