Skip to content

Commit

Permalink
WIP: Fixing curved polygon intersection algorithm for special cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyweiss committed Nov 29, 2021
1 parent 8115436 commit 633fff0
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 103 deletions.
21 changes: 10 additions & 11 deletions src/axom/primal/operators/detail/intersect_bezier_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ bool intersect_bezier_curves(const BezierCurve<T, NDIMS> &c1,

s_scale *= scaleFac;

// Note: we want to find all intersections, so don't short-circuit
if(intersect_bezier_curves(c2,
c3,
tp,
Expand Down Expand Up @@ -185,11 +186,11 @@ bool intersect_bezier_curves(const BezierCurve<T, NDIMS> &c1,
return foundIntersection;
}

template <typename T, int NDIMS>
bool intersect_2d_linear(const Point<T, NDIMS> &a,
const Point<T, NDIMS> &b,
const Point<T, NDIMS> &c,
const Point<T, NDIMS> &d,
template <typename T>
bool intersect_2d_linear(const Point<T, 2> &a,
const Point<T, 2> &b,
const Point<T, 2> &c,
const Point<T, 2> &d,
T &s,
T &t)
{
Expand All @@ -199,18 +200,16 @@ bool intersect_2d_linear(const Point<T, NDIMS> &a,
// Note: Uses exact floating point comparisons since the subdivision algorithm
// provides both sides of the line segments for interior curve points.

AXOM_STATIC_ASSERT(NDIMS == 2);

// compute signed areas of endpoints of segment (c,d) w.r.t. segment (a,b)
auto area1 = twoDcross(a, b, c);
auto area2 = twoDcross(a, b, d);
const auto area1 = twoDcross(a, b, c);
const auto area2 = twoDcross(a, b, d);

// early return if both have same orientation, or if d is collinear w/ (a,b)
if(area2 == 0. || (area1 * area2) > 0.) return false;

// compute signed areas of endpoints of segment (a,b) w.r.t. segment (c,d)
auto area3 = twoDcross(c, d, a);
auto area4 = area3 + area1 - area2; // equivalent to twoDcross(c,d,b)
const auto area3 = twoDcross(c, d, a);
const auto area4 = area3 + area1 - area2; // equivalent to twoDcross(c,d,b)

// early return if both have same orientation, or if b is collinear w/ (c,d)
if(area4 == 0. || (area3 * area4) > 0.) return false;
Expand Down
Loading

0 comments on commit 633fff0

Please sign in to comment.