-
Notifications
You must be signed in to change notification settings - Fork 1
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
2208598
commit 7fedbab
Showing
1 changed file
with
16 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,16 @@ | ||
//overflow를 대비해서 cross 부분은 양수 또는 음수에 따라 1, 0, -1로 전처리해주는게 좋습니다. | ||
template <typename T> | ||
bool line_cross(const pt<T>& a, const pt<T>& b, const pt<T>& c, const pt<T>& d) { | ||
T abc = a.cross(b, c), abd = a.cross(b, d); | ||
T cda = c.cross(d, a), cdb = c.cross(d, b); | ||
|
||
if (abc * abd <= 0 && cda * cdb <= 0) { | ||
if (abc * abd == 0 && cda * cdb == 0) { | ||
if (std::max(a.x, b.x) >= std::min(c.x, d.x) && std::max(c.x, d.x) >= std::min(a.x, b.x) && | ||
std::max(a.y, b.y) >= std::min(c.y, d.y) && std::max(c.y, d.y) >= std::min(a.y, b.y)) return true; | ||
return false; | ||
} | ||
return true; | ||
} | ||
return false; | ||
} |