src/geo2d/ains/ct_s/lib.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../../ang_pp/lib.hpp" | ||
| 4 | #include "../../dis/pp_p/lib.hpp" | ||
| 5 | #include "../../dot/lib.hpp" | ||
| 6 | #include "../../ins/cl/lib.hpp" | ||
| 7 | |||
| 8 | namespace tifa_libs { | ||
| 9 | |||
| 10 | // area of intersection of circle and triangle | ||
| 11 | //! WITH DIRECTION, sgn is cross(c.o, p1, p2) | ||
| 12 | //! the center ot circle is also a endpoint of triangle | ||
| 13 | template <class FP> | ||
| 14 | 733 | CEXP FP sarea_CT(circle<FP> CR c, point<FP> CR p1, point<FP> CR p2) NE { | |
| 15 |
2/2✓ Branch 2 taken 55 times.
✓ Branch 3 taken 678 times.
|
733 | if (is_zero(cross(c.o, p1, p2))) return FP{}; |
| 16 | 678 | const auto is = ins_CL(c, {p1, p2}); | |
| 17 |
2/2✓ Branch 1 taken 85 times.
✓ Branch 2 taken 593 times.
|
678 | if (!is) return c.area(ang_PP(p1 - c.o, p2 - c.o)); |
| 18 | 593 | bool b1 = comp_distp(p1, c.o, c.r) > 0, b2 = comp_distp(p2, c.o, c.r) > 0; | |
| 19 |
4/4✓ Branch 0 taken 142 times.
✓ Branch 1 taken 451 times.
✓ Branch 2 taken 73 times.
✓ Branch 3 taken 69 times.
|
593 | if (b1 && b2) { |
| 20 | 73 | FP res = c.area(ang_PP(p1 - c.o, p2 - c.o)); | |
| 21 |
2/2✓ Branch 3 taken 28 times.
✓ Branch 4 taken 45 times.
|
73 | if (!is_pos(dot(is->first, p1, p2))) res -= c.crown_area(ang_PP(is->first - c.o, is->second - c.o)); |
| 22 | 73 | return res; | |
| 23 | } | ||
| 24 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 451 times.
|
520 | if (b1) return c.area(ang_PP(p1 - c.o, is->first - c.o)) + cross(c.o, is->first, p2) / 2; |
| 25 |
2/2✓ Branch 0 taken 70 times.
✓ Branch 1 taken 381 times.
|
451 | if (b2) return c.area(ang_PP(is->second - c.o, p2 - c.o)) + cross(c.o, p1, is->second) / 2; |
| 26 | 381 | return cross(c.o, p1, p2) / 2; | |
| 27 | } | ||
| 28 | |||
| 29 | } // namespace tifa_libs | ||
| 30 |