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

intersectを実装 #63

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/atcoder/extra/geometry/geometry_template.nim
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ when not declared ATCODER_GEOMETRY_TEMPLATE_HPP:

# intersect function {{{
proc intersect*[Real](l, m: Line[Real]):bool =
abs(cross(l.b - l.a, m.b - m.a)) >~ 0.Real or abs(cross(l.b - l.a, m.b - l.a)) <~ 0.Real
cross(l.b - l.a, m.b - m.a) >~ 0 or cross(l.b - l.a, m.b - l.a) <~ 0

swappableProc intersect(l: Line[Real], p: Point[Real]):
cross(l.a-l.b, p-l.b) =~ 0 or cross(l.b-l.a, p-l.a) =~ 0

swappableProc intersect(s: Segment[Real], p: Point[Real]):
let dotp = dot(s.a-s.b, p-s.b)
intersect(Line[Real](s), p) and (0 <=~ dotp) and (dotp <=~ norm(s.a-s.b))

swappableProc intersect(l: Line[Real], s: Segment[Real]):
cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) <~ 0.Real
Expand Down