-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de420e5
commit 5f8e8a2
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
int TangentDir(vector<pll> &C, pll dir) { | ||
return cyc_tsearch(SZ(C), [&](int a, int b) { | ||
return cross(dir, C[a]) > cross(dir, C[b]); | ||
}); | ||
} | ||
#define cmpL(i) sign(cross(C[i] - a, b - a)) | ||
pii lineHull(pll a, pll b, vector<pll> &C) { | ||
int A = TangentDir(C, a - b); | ||
int B = TangentDir(C, b - a); | ||
int n = SZ(C); | ||
if (cmpL(A) < 0 || cmpL(B) > 0) | ||
return pii(-1, -1); // no collision | ||
auto gao = [&](int l, int r) { | ||
for (int t = l; (l + 1) % n != r; ) { | ||
int m = ((l + r + (l < r ? 0 : n)) / 2) % n; | ||
(cmpL(m) == cmpL(t) ? l : r) = m; | ||
} | ||
return (l + !cmpL(r)) % n; | ||
}; | ||
pii res = pii(gao(B, A), gao(A, B)); // (i, j) | ||
if (res.X == res.Y) // touching the corner i | ||
return pii(res.X, -1); | ||
if (!cmpL(res.X) && !cmpL(res.Y)) // along side i, i+1 | ||
switch ((res.X - res.Y + n + 1) % n) { | ||
case 0: return pii(res.X, res.X); | ||
case 2: return pii(res.Y, res.Y); | ||
} | ||
/* crossing sides (i, i+1) and (j, j+1) | ||
crossing corner i is treated as side (i, i+1) | ||
returned in the same order as the line hits the convex */ | ||
return res; | ||
} // convex cut: (r, l] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters