Skip to content

Commit

Permalink
Fix some issues that may cause floating point issues (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
user202729 authored Jan 31, 2025
1 parent 7b89431 commit 2610659
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion content/geometry/CirclePolygonIntersection.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ double circlePoly(P c, double r, vector<P> ps) {
if (det <= 0) return arg(p, q) * r2;
auto s = max(0., -a-sqrt(det)), t = min(1., -a+sqrt(det));
if (t < 0 || 1 <= s) return arg(p, q) * r2;
P u = p + d * s, v = p + d * t;
P u = p + d * s, v = q + d * (t-1);
return arg(p,u) * r2 + u.cross(v)/2 + arg(v,q) * r2;
};
auto sum = 0.0;
Expand Down
8 changes: 4 additions & 4 deletions content/geometry/PolygonCut.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ vector<P> polygonCut(const vector<P>& poly, P s, P e) {
vector<P> res;
rep(i,0,sz(poly)) {
P cur = poly[i], prev = i ? poly[i-1] : poly.back();
bool side = s.cross(e, cur) < 0;
if (side != (s.cross(e, prev) < 0))
res.push_back(lineInter(s, e, cur, prev).second);
if (side)
auto a = s.cross(e, cur), b = s.cross(e, prev);
if ((a < 0) != (b < 0))
res.push_back(cur + (prev - cur) * (a / (a - b)));
if (a < 0)
res.push_back(cur);
}
return res;
Expand Down

0 comments on commit 2610659

Please sign in to comment.