GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 32 / 0 / 32
Functions: 100.0% 22 / 0 / 22
Branches: 87.5% 28 / 0 / 32

src/geo2d/ds/l/lib.hpp
Line Branch Exec Source
1 #pragma once
2
3 #include "../../cross/lib.hpp"
4 #include "../p/lib.hpp"
5
6 namespace tifa_libs {
7
8 template <class FP>
9 struct line {
10 point<FP> l, r;
11
12 CEXP line() = default;
13 288502379 CEXP line(point<FP> CR s, point<FP> CR t) NE : l(s), r(t) {}
14 CEXP line(point<FP> CR s, FP angle_x) NE : l(s), r(s + is_eq(angle_x, pi_v<FP> / 2) ? point<FP>{0, 1} : point<FP>{1, std::tan(angle_x)}) { assert(angle_x > 0 && angle_x < pi_v<FP>); }
15 // ax + by + c = 0
16 CEXP line(FP a, FP b, FP c) NE {
17 if (is_zero(a)) l = {0, -c / b}, r = {1, -c / b};
18 else if (is_zero(b)) l = {-c / a, 0}, r = {-c / a, 1};
19 else l = {0, -c / b}, r = {1, -(c + a) / b};
20 }
21 157189 CEXP line(FP s_x, FP s_y, FP t_x, FP t_y) NE : l{s_x, s_y}, r{t_x, t_y} {}
22
23 75389 friend std::istream& operator>>(std::istream& is, line& l) NE { return is >> l.l >> l.r; }
24 friend std::ostream& operator<<(std::ostream& os, line CR l) NE { return os << l.l << ' ' << l.r; }
25 141878318 CEXP point<FP> direction() CNE { return r - l; }
26 36245274 CEXP bool is_parallel(line CR r) CNE { return is_zero(direction() ^ r.direction()); }
27 101 friend CEXP bool is_parallel(line CR l, line CR r) NE { return l.is_parallel(r); }
28
8/8
tifa_libs::line<double>::is_same_dir(tifa_libs::line<double> const&) const:
✓ Branch 1 taken 98922 times.
✓ Branch 2 taken 8542353 times.
✓ Branch 7 taken 94479 times.
✓ Branch 8 taken 4443 times.
tifa_libs::line<long double>::is_same_dir(tifa_libs::line<long double> const&) const:
✓ Branch 1 taken 4351992 times.
✓ Branch 2 taken 23236084 times.
✓ Branch 7 taken 4334550 times.
✓ Branch 8 taken 17442 times.
36229351 CEXP bool is_same_dir(line CR r) CNE { return is_parallel(r) && is_pos(direction() * r.direction()); }
29 2038836 friend CEXP bool is_same_dir(line CR l, line CR r) NE { return l.is_same_dir(r); }
30
6/8
tifa_libs::operator==(tifa_libs::line<double> const&, tifa_libs::line<double> const&):
✓ Branch 1 taken 107913 times.
✓ Branch 2 taken 8533362 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 107913 times.
tifa_libs::operator==(tifa_libs::line<long double> const&, tifa_libs::line<long double> const&):
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 27588067 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
36229351 friend CEXP bool operator==(line CR l, line CR r) NE { return l.l == r.l && l.r == r.r; }
31 34190515 friend CEXP auto operator<=>(line CR l, line CR r) NE {
32
2/4
tifa_libs::operator<=>(tifa_libs::line<double> const&, tifa_libs::line<double> const&):
✗ Branch 1 not taken.
✓ Branch 2 taken 8640563 times.
tifa_libs::operator<=>(tifa_libs::line<long double> const&, tifa_libs::line<long double> const&):
✗ Branch 1 not taken.
✓ Branch 2 taken 25549952 times.
34190515 if (l == r) return 0;
33
4/4
tifa_libs::operator<=>(tifa_libs::line<double> const&, tifa_libs::line<double> const&):
✓ Branch 1 taken 94338 times.
✓ Branch 2 taken 8546225 times.
tifa_libs::operator<=>(tifa_libs::line<long double> const&, tifa_libs::line<long double> const&):
✓ Branch 1 taken 3918246 times.
✓ Branch 2 taken 21631706 times.
34190515 if (l.is_same_dir(r)) {
34
4/4
tifa_libs::operator<=>(tifa_libs::line<double> const&, tifa_libs::line<double> const&):
✓ Branch 1 taken 50796 times.
✓ Branch 2 taken 43542 times.
tifa_libs::operator<=>(tifa_libs::line<long double> const&, tifa_libs::line<long double> const&):
✓ Branch 1 taken 2740803 times.
✓ Branch 2 taken 1177443 times.
4012584 retif_((r.is_include_strict(l.l)), -1, 1);
35
4/4
tifa_libs::operator<=>(tifa_libs::line<double> const&, tifa_libs::line<double> const&):
✓ Branch 4 taken 1162647 times.
✓ Branch 5 taken 7383578 times.
tifa_libs::operator<=>(tifa_libs::line<long double> const&, tifa_libs::line<long double> const&):
✓ Branch 4 taken 3567625 times.
✓ Branch 5 taken 18064081 times.
30177931 } else if (const auto vl = l.direction(), vr = r.direction(); vl.quad() != vr.quad()) return (i32)vl.quad() - (i32)vr.quad();
36 25447659 else return -sgn(vl ^ vr);
37 }
38 984393287 CEXP int toleft(point<FP> CR p) CNE { return sgn_cross(l, r, p); }
39 // half plane
40 8825972 CEXP bool is_include_strict(point<FP> CR p) CNE { return toleft(p) > 0; }
41 // half plane
42 CEXP bool is_include(point<FP> CR p) CNE { return toleft(p) >= 0; }
43 // translate @dist along the direction of half plane
44 CEXP line& do_push(FP dist) NE {
45 const point delta = direction().do_rot90().do_unit() * dist;
46 l += delta, r += delta;
47 return *this;
48 }
49 };
50
51 } // namespace tifa_libs
52