GCC Code Coverage Report


Directory: src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 0 / 34
Functions: -% 0 / 0 / 0
Branches: -% 0 / 0 / 0

geometry/point3d.hpp
Line Branch Exec Source
1 #pragma once
2
3 #include <bits/stdc++.h>
4
5 namespace wala {
6
7 const double PI = acos(-1.);
8 const double TAU = 2 * PI;
9
10 template <typename T, typename AreaT=T, typename VolT=T> struct Point3D {
11 using P = Point3D;
12
13 T x, y, z;
14 ✗ Point3D() : x(0), y(0), z(0) {}
15 ✗ Point3D(T x_, T y_, T z_) : x(x_), y(y_), z(z_) {}
16
17 ✗ template <typename U, typename V, typename W> explicit Point3D(const Point3D<U, V, W>& p) : x(T(p.x)), y(T(p.y)), z(T(p.z)) {}
18
19 ✗ friend std::istream& operator >> (std::istream& i, P& p) { return i >> p.x >> p.y >> p.z; }
20 ✗ friend std::ostream& operator << (std::ostream& o, const P& p) { return o << "(" << p.x << "," << p.y << "," << p.z << ")"; }
21
22 ✗ friend bool operator == (const P& a, const P& b) { return a.x == b.x && a.y == b.y && a.z == b.z; }
23 ✗ friend bool operator != (const P& a, const P& b) { return a.x != b.x || a.y != b.y || a.z != b.z; }
24
25 ✗ P& operator += (const P& o) { x += o.x, y += o.y, z += o.z; return *this; }
26 ✗ P& operator -= (const P& o) { x -= o.x, y -= o.y, z -= o.z; return *this; }
27 ✗ friend P operator + (const P& a, const P& b) { return P(a) += b; }
28 ✗ friend P operator - (const P& a, const P& b) { return P(a) -= b; }
29
30 ✗ P& operator *= (const T& t) { x *= t, y *= t, z *= t; return *this; }
31 ✗ P& operator /= (const T& t) { x /= t, y /= t, z /= t; return *this; }
32 ✗ friend P operator * (const P& p, const T& t) { return P(p) *= t; }
33 ✗ friend P operator * (const T& t, const P& p) { return P(p) *= t; }
34 ✗ friend P operator / (const P& a, const T& t) { return P(a) /= t; }
35
36 ✗ friend P operator + (const P& a) { return P(+a.x, +a.y, +a.z); }
37 ✗ friend P operator - (const P& a) { return P(-a.x, -a.y, -a.z); }
38
39 ✗ friend AreaT dot(const P& a, const P& b) { return AreaT(a.x) * AreaT(b.x) + AreaT(a.y) * AreaT(b.y) + AreaT(a.z) * AreaT(b.z); }
40 ✗ friend AreaT norm(const P& a) { return dot(a,a); }
41 // We're playing a little loose with this type, expliitly cast it if you need
42 ✗ friend Point3D<AreaT, VolT> cross(const P& a, const P& b) { return Point3D<AreaT, VolT>(AreaT(a.y) * AreaT(b.z) - AreaT(a.z) * AreaT(b.y), AreaT(a.z) * AreaT(b.x) - AreaT(a.x) * AreaT(b.z), AreaT(a.x) * AreaT(b.y) - AreaT(a.y) * AreaT(b.x)); }
43
44 ✗ friend T int_norm(const P& p) {
45 ✗ return std::gcd(std::gcd(abs(p.x), abs(p.y)), abs(p.z));
46 }
47 ✗ friend P int_unit(const P& p) {
48 ✗ T g = int_norm(p);
49 ✗ return g ? p / g : p;
50 }
51
52 ✗ friend T abs(const P& a) { return std::sqrt(std::max(T(0), norm(a))); }
53 ✗ friend P unit(const P& a) { return a / abs(a); }
54
55 ✗ friend VolT vol(const P& a, const P& b, const P& c, const P& d) { return dot(cross(b-a, c-a), Point3D<AreaT, VolT>(d-a)); }
56
57 ✗ friend bool lexLess(const P& a, const P& b) { return std::tie(a.x, a.y, a.z) < std::tie(b.x, b.y, b.z); }
58
59 ✗ friend bool parallelSame(const P& a, const P& b) {
60 ✗ assert(a != P());
61 ✗ assert(b != P());
62 ✗ return lexLess(a, P()) == lexLess(b, P());
63 }
64 };
65
66 } // namespace wala
67