src/geo2d/ins/cl/lib.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../../dis/pp/lib.hpp" | ||
| 4 | #include "../../ds/c/lib.hpp" | ||
| 5 | #include "../../ds/l/lib.hpp" | ||
| 6 | |||
| 7 | namespace tifa_libs { | ||
| 8 | |||
| 9 | // intersection point of circle and line | ||
| 10 | // maybe duplicate | ||
| 11 | template <class FP> | ||
| 12 | 1301 | CEXP auto ins_CL(circle<FP> CR c, line<FP> CR l) NE { | |
| 13 | 1301 | std::optional<ptt<point<FP>>> ret; | |
| 14 |
2/2✓ Branch 7 taken 120 times.
✓ Branch 8 taken 1181 times.
|
1301 | if (is_gt(abs((c.o - l.l) ^ (l.r - l.l) / dist_PP(l.l, l.r)), c.r)) return ret; |
| 15 | 1181 | const FP x = (l.l - c.o) * (l.r - l.l), | |
| 16 | 1181 | y = l.direction().norm2(), | |
| 17 | 1181 | d = max(x * x - y * ((l.l - c.o).norm2() - c.r * c.r), FP{}); | |
| 18 | 1181 | const point m = l.l - l.direction() * (x / y), dr = l.direction() * (std::sqrt(d) / y); | |
| 19 | 1181 | ret.emplace(m - dr, m + dr); | |
| 20 | 1181 | return ret; | |
| 21 | } | ||
| 22 | |||
| 23 | } // namespace tifa_libs | ||
| 24 |