src/geo2d/ds/p/lib.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../../../util/func_fp/lib.hpp" | ||
| 4 | #include "../../../util/traits/others/lib.hpp" | ||
| 5 | |||
| 6 | namespace tifa_libs { | ||
| 7 | |||
| 8 | template <class FP> | ||
| 9 | struct point { | ||
| 10 | using FP_t = FP; | ||
| 11 | |||
| 12 | FP x, y; | ||
| 13 | CEXP point() = default; | ||
| 14 | 803612 | CEXP point(FP x, FP y) NE : x{x}, y{y} {} | |
| 15 | |||
| 16 | 57007062 | friend auto& operator>>(istream_c auto& is, point& p) NE { return is >> p.x >> p.y; } | |
| 17 | 6420267 | friend auto& operator<<(ostream_c auto& os, point CR p) NE { return os << p.x << ' ' << p.y; } | |
| 18 | // s + (t - s) * r | ||
| 19 | template <std::floating_point T> | ||
| 20 | 1839502 | friend CEXP point lerp(point CR s, point CR t, T r) NE { return s + (t - s) * r; } | |
| 21 | 1839502 | friend CEXP point mid_point(point CR s, point CR t) NE { return lerp(s, t, .5); } | |
| 22 | CEXP point& operator+=(arithm_c auto n) NE { | ||
| 23 | this->x += n, this->y += n; | ||
| 24 | return *this; | ||
| 25 | } | ||
| 26 | CEXP point& operator-=(arithm_c auto n) NE { | ||
| 27 | this->x -= n, this->y -= n; | ||
| 28 | return *this; | ||
| 29 | } | ||
| 30 | 122127612 | CEXP point& operator*=(arithm_c auto n) NE { | |
| 31 | 122127612 | this->x *= n, this->y *= n; | |
| 32 | 122127612 | return *this; | |
| 33 | } | ||
| 34 | 2186950090 | CEXP point& operator/=(arithm_c auto n) NE { | |
| 35 | 2186950090 | this->x /= n, this->y /= n; | |
| 36 | 2186950090 | return *this; | |
| 37 | } | ||
| 38 | friend CEXP point operator+(point x, arithm_c auto n) NE { return x += n; } | ||
| 39 | friend CEXP point operator+(arithm_c auto n, point x) NE { return x += n; } | ||
| 40 | friend CEXP point operator-(point x, arithm_c auto n) NE { return x -= n; } | ||
| 41 | friend CEXP point operator-(arithm_c auto n, point x) NE { return x -= n; } | ||
| 42 | 122126611 | friend CEXP point operator*(point x, arithm_c auto n) NE { return x *= n; } | |
| 43 | 720 | friend CEXP point operator*(arithm_c auto n, point x) NE { return x *= n; } | |
| 44 | 57270214 | friend CEXP point operator/(point x, arithm_c auto n) NE { return x /= n; } | |
| 45 | friend CEXP point operator/(arithm_c auto n, point x) NE { return x /= n; } | ||
| 46 | 67078697 | CEXP point& operator+=(point CR p) NE { | |
| 47 | 67078697 | this->x += p.x, this->y += p.y; | |
| 48 | 67078697 | return *this; | |
| 49 | } | ||
| 50 | 2699273339 | CEXP point& operator-=(point CR p) NE { | |
| 51 | 2699273339 | this->x -= p.x, this->y -= p.y; | |
| 52 | 2699273339 | return *this; | |
| 53 | } | ||
| 54 | 67078697 | CEXP point operator+(point CR p) CNE { return point(*this) += p; } | |
| 55 | 2699273339 | CEXP point operator-(point CR p) CNE { return point(*this) -= p; } | |
| 56 | CEXP point operator-() CNE { return point{-x, -y}; } | ||
| 57 | 2801956761 | CEXP auto operator<=>(point CR p) CNE { | |
| 58 |
6/6tifa_libs::point<double>::operator<=>(tifa_libs::point<double> const&) const:
✓ Branch 1 taken 95866617 times.
✓ Branch 2 taken 46995959 times.
tifa_libs::point<long double>::operator<=>(tifa_libs::point<long double> const&) const:
✓ Branch 1 taken 1507917737 times.
✓ Branch 2 taken 659884179 times.
tifa_libs::point<long>::operator<=>(tifa_libs::point<long> const&) const:
✓ Branch 1 taken 378192620 times.
✓ Branch 2 taken 113099649 times.
|
2801956761 | if (auto CR c = comp(x, p.x); c) return c; |
| 59 | 819979787 | return comp(y, p.y); | |
| 60 | } | ||
| 61 | 160093983 | CEXP bool operator==(point CR p) CNE { return (*this <=> p) == 0; } | |
| 62 | 5251826 | CEXP FP operator*(point CR p) CNE { return x * p.x + y * p.y; } | |
| 63 | 1364505126 | CEXP FP operator^(point CR p) CNE { return x * p.y - y * p.x; } | |
| 64 | 5591862 | CEXP FP arg() CNE { | |
| 65 | static_assert(std::is_floating_point_v<FP>); | ||
| 66 | 5591862 | return std::atan2(y, x); | |
| 67 | } | ||
| 68 | CEXP FP arg_2pi() CNE { | ||
| 69 | FP res = arg(); | ||
| 70 | retif_((is_neg(res)), res + 2 * pi_v<FP>, res); | ||
| 71 | } | ||
| 72 | 5201471 | CEXP FP norm2() CNE { return x * x + y * y; } | |
| 73 | 2210586628 | CEXP FP norm() CNE { | |
| 74 | static_assert(std::is_floating_point_v<FP>); | ||
| 75 | 2210586628 | return std::hypot(x, y); | |
| 76 | } | ||
| 77 | 2129679876 | CEXP point& do_unit() NE { | |
| 78 | static_assert(std::is_floating_point_v<FP>); | ||
| 79 | 2129679876 | return *this /= norm(); | |
| 80 | } | ||
| 81 | static CEXP arr<u32, 9> QUAD__{6, 7, 8, 5, 0, 1, 4, 3, 2}; | ||
| 82 | // 4 3 2 | ||
| 83 | // 5 0 1 | ||
| 84 | // 6 7 8 | ||
| 85 | 213039320 | ND CEXP u32 quad() CNE { return QUAD__[(sgn(y) + 1) * 3 + sgn(x) + 1]; } | |
| 86 | CEXP int toleft(point CR p) CNE { return sgn(*this ^ p); } | ||
| 87 | 207464 | CEXP point& do_rot(FP theta) NE { | |
| 88 | 207464 | const FP x0 = x, y0 = y, ct = std::cos(theta), st = std::sin(theta); | |
| 89 | 207464 | x = x0 * ct - y0 * st, y = x0 * st + y0 * ct; | |
| 90 | 207464 | return *this; | |
| 91 | } | ||
| 92 | 120836 | friend CEXP point rot(point p, FP theta) NE { return p.do_rot(theta); } | |
| 93 | 4637559 | CEXP point& do_rot90() NE { | |
| 94 | 4637559 | const FP _ = x; | |
| 95 | 4637559 | x = -y, y = _; | |
| 96 | 4637559 | return *this; | |
| 97 | } | ||
| 98 | 4515230 | friend CEXP point rot90(point p) NE { return p.do_rot90(); } | |
| 99 | 281 | CEXP point& do_rot270() NE { | |
| 100 | 281 | const FP _ = y; | |
| 101 | 281 | y = -x, x = _; | |
| 102 | 281 | return *this; | |
| 103 | } | ||
| 104 | 281 | friend CEXP point rot270(point p) NE { return p.do_rot270(); } | |
| 105 | }; | ||
| 106 | |||
| 107 | } // namespace tifa_libs | ||
| 108 |