GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/math/Vec2.h
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 30 31 96.8%
Functions: 3 5 60.0%
Branches: 172 1032 16.7%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #ifndef OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
6
7 #include <openvdb/Exceptions.h>
8 #include "Math.h"
9 #include "Tuple.h"
10 #include <algorithm>
11 #include <cmath>
12 #include <type_traits>
13
14
15 namespace openvdb {
16 OPENVDB_USE_VERSION_NAMESPACE
17 namespace OPENVDB_VERSION_NAME {
18 namespace math {
19
20 template<typename T> class Mat2;
21
22 template<typename T>
23 class Vec2: public Tuple<2, T>
24 {
25 public:
26 using value_type = T;
27 using ValueType = T;
28
29 /// Trivial constructor, the vector is NOT initialized
30 #if OPENVDB_ABI_VERSION_NUMBER >= 8
31 /// @note destructor, copy constructor, assignment operator and
32 /// move constructor are left to be defined by the compiler (default)
33 Vec2() = default;
34 #else
35 Vec2() {}
36 #endif
37
38 /// @brief Construct a vector all of whose components have the given value.
39
1/39
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✓ Branch 37 taken 98 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
1244 explicit Vec2(T val) { this->mm[0] = this->mm[1] = val; }
40
41 /// Constructor with two arguments, e.g. Vec2f v(1,2,3);
42 1126 Vec2(T x, T y)
43 {
44 1126 this->mm[0] = x;
45
33/62
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 7 times.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 6 times.
✓ Branch 14 taken 1 times.
✓ Branch 16 taken 6 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 3 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 3 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 3 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 3 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 3 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 2 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 2 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 2 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 64 taken 1 times.
✗ Branch 65 not taken.
✓ Branch 67 taken 1 times.
✗ Branch 68 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 76 taken 1 times.
✗ Branch 77 not taken.
✓ Branch 79 taken 1 times.
✗ Branch 80 not taken.
✓ Branch 82 taken 1 times.
✗ Branch 83 not taken.
✓ Branch 85 taken 1 times.
✗ Branch 86 not taken.
1121 this->mm[1] = y;
46 }
47
48 /// Constructor with array argument, e.g. float a[2]; Vec2f v(a);
49 template <typename Source>
50 Vec2(Source *a)
51 {
52 this->mm[0] = static_cast<T>(a[0]);
53 this->mm[1] = static_cast<T>(a[1]);
54 } // trivial
55
56 /// Conversion constructor
57 template<typename Source>
58
1/2
✓ Branch 1 taken 524288 times.
✗ Branch 2 not taken.
2621440 explicit Vec2(const Tuple<2, Source> &t)
59 {
60 2621440 this->mm[0] = static_cast<T>(t[0]);
61
1/2
✓ Branch 1 taken 524288 times.
✗ Branch 2 not taken.
2621440 this->mm[1] = static_cast<T>(t[1]);
62 }
63
64 /// @brief Construct a vector all of whose components have the given value,
65 /// which may be of an arithmetic type different from this vector's value type.
66 /// @details Type conversion warnings are suppressed.
67 template<typename Other>
68 5181 explicit Vec2(Other val,
69 typename std::enable_if<std::is_arithmetic<Other>::value, Conversion>::type = Conversion{})
70 {
71
7/71
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 65 taken 512 times.
✗ Branch 66 not taken.
✓ Branch 68 taken 512 times.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✓ Branch 71 taken 512 times.
✗ Branch 72 not taken.
✓ Branch 73 taken 98 times.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✓ Branch 77 taken 512 times.
✗ Branch 78 not taken.
✓ Branch 79 taken 98 times.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
4529 this->mm[0] = this->mm[1] = static_cast<T>(val);
72 }
73
74 /// Reference to the component, e.g. v.x() = 4.5f;
75 T& x() {return this->mm[0];}
76 T& y() {return this->mm[1];}
77
78 /// Get the component, e.g. float f = v.y();
79
5/18
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 49 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 49 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 49140 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 49140 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 49189 times.
✗ Branch 17 not taken.
147567 T x() const {return this->mm[0];}
80
6/18
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 49 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 49 times.
✓ Branch 12 taken 49140 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 49140 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 49140 times.
✓ Branch 17 taken 49 times.
147567 T y() const {return this->mm[1];}
81
82 /// Alternative indexed reference to the elements
83 T& operator()(int i) {return this->mm[i];}
84
85 /// Alternative indexed constant reference to the elements,
86 T operator()(int i) const {return this->mm[i];}
87
88 T* asPointer() {return this->mm;}
89 const T* asPointer() const {return this->mm;}
90
91 /// "this" vector gets initialized to [x, y, z],
92 /// calling v.init(); has same effect as calling v = Vec2::zero();
93 const Vec2<T>& init(T x=0, T y=0)
94 {
95 this->mm[0] = x; this->mm[1] = y;
96 return *this;
97 }
98
99 /// Set "this" vector to zero
100 const Vec2<T>& setZero()
101 {
102 this->mm[0] = 0; this->mm[1] = 0;
103 return *this;
104 }
105
106 /// Assignment operator
107 template<typename Source>
108 1048576 const Vec2<T>& operator=(const Vec2<Source> &v)
109 {
110 // note: don't static_cast because that suppresses warnings
111 1048576 this->mm[0] = v[0];
112 1048576 this->mm[1] = v[1];
113
114 1048576 return *this;
115 }
116
117 /// Equality operator, does exact floating point comparisons
118 bool operator==(const Vec2<T> &v) const
119 {
120
91/654
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 1 times.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 1 times.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 1 times.
✓ Branch 32 taken 1 times.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✓ Branch 35 taken 1 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 1 times.
✓ Branch 38 taken 1 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 82 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 88 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 91 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✗ Branch 94 not taken.
✗ Branch 95 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 98 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 101 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 104 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 107 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 110 not taken.
✗ Branch 111 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 114 not taken.
✓ Branch 115 taken 3 times.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
✗ Branch 118 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✗ Branch 121 not taken.
✗ Branch 122 not taken.
✓ Branch 123 taken 1 times.
✗ Branch 124 not taken.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✗ Branch 127 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 130 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✗ Branch 133 not taken.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✗ Branch 136 not taken.
✗ Branch 137 not taken.
✓ Branch 138 taken 15 times.
✗ Branch 139 not taken.
✓ Branch 140 taken 15 times.
✗ Branch 141 not taken.
✗ Branch 142 not taken.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✗ Branch 145 not taken.
✗ Branch 146 not taken.
✗ Branch 147 not taken.
✗ Branch 148 not taken.
✗ Branch 149 not taken.
✗ Branch 150 not taken.
✗ Branch 151 not taken.
✗ Branch 152 not taken.
✗ Branch 153 not taken.
✗ Branch 154 not taken.
✗ Branch 155 not taken.
✗ Branch 156 not taken.
✗ Branch 157 not taken.
✗ Branch 158 not taken.
✗ Branch 159 not taken.
✗ Branch 160 not taken.
✗ Branch 161 not taken.
✗ Branch 162 not taken.
✗ Branch 163 not taken.
✗ Branch 164 not taken.
✗ Branch 165 not taken.
✗ Branch 166 not taken.
✗ Branch 167 not taken.
✗ Branch 168 not taken.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 171 not taken.
✗ Branch 172 not taken.
✗ Branch 173 not taken.
✗ Branch 174 not taken.
✗ Branch 175 not taken.
✗ Branch 176 not taken.
✗ Branch 177 not taken.
✗ Branch 178 not taken.
✗ Branch 179 not taken.
✗ Branch 180 not taken.
✗ Branch 181 not taken.
✗ Branch 182 not taken.
✗ Branch 183 not taken.
✗ Branch 184 not taken.
✗ Branch 185 not taken.
✗ Branch 186 not taken.
✗ Branch 187 not taken.
✗ Branch 188 not taken.
✗ Branch 189 not taken.
✗ Branch 190 not taken.
✗ Branch 191 not taken.
✗ Branch 192 not taken.
✗ Branch 193 not taken.
✗ Branch 194 not taken.
✗ Branch 195 not taken.
✗ Branch 196 not taken.
✗ Branch 197 not taken.
✗ Branch 198 not taken.
✗ Branch 199 not taken.
✗ Branch 200 not taken.
✗ Branch 201 not taken.
✗ Branch 202 not taken.
✗ Branch 203 not taken.
✗ Branch 204 not taken.
✗ Branch 205 not taken.
✗ Branch 206 not taken.
✗ Branch 207 not taken.
✗ Branch 208 not taken.
✗ Branch 209 not taken.
✗ Branch 210 not taken.
✗ Branch 211 not taken.
✗ Branch 212 not taken.
✗ Branch 213 not taken.
✗ Branch 214 not taken.
✗ Branch 215 not taken.
✗ Branch 216 not taken.
✗ Branch 217 not taken.
✗ Branch 218 not taken.
✗ Branch 219 not taken.
✗ Branch 220 not taken.
✗ Branch 221 not taken.
✗ Branch 222 not taken.
✗ Branch 223 not taken.
✗ Branch 224 not taken.
✗ Branch 225 not taken.
✗ Branch 226 not taken.
✗ Branch 227 not taken.
✗ Branch 228 not taken.
✗ Branch 229 not taken.
✗ Branch 230 not taken.
✗ Branch 231 not taken.
✗ Branch 232 not taken.
✗ Branch 233 not taken.
✗ Branch 234 not taken.
✗ Branch 235 not taken.
✗ Branch 236 not taken.
✗ Branch 237 not taken.
✗ Branch 238 not taken.
✗ Branch 239 not taken.
✗ Branch 240 not taken.
✗ Branch 241 not taken.
✗ Branch 242 not taken.
✗ Branch 243 not taken.
✗ Branch 244 not taken.
✗ Branch 245 not taken.
✗ Branch 246 not taken.
✗ Branch 247 not taken.
✗ Branch 248 not taken.
✗ Branch 249 not taken.
✗ Branch 250 not taken.
✗ Branch 251 not taken.
✗ Branch 252 not taken.
✗ Branch 253 not taken.
✗ Branch 254 not taken.
✗ Branch 255 not taken.
✗ Branch 256 not taken.
✗ Branch 257 not taken.
✗ Branch 258 not taken.
✗ Branch 259 not taken.
✗ Branch 260 not taken.
✗ Branch 261 not taken.
✗ Branch 262 not taken.
✗ Branch 263 not taken.
✗ Branch 264 not taken.
✗ Branch 265 not taken.
✗ Branch 266 not taken.
✗ Branch 267 not taken.
✗ Branch 268 not taken.
✗ Branch 269 not taken.
✗ Branch 270 not taken.
✗ Branch 271 not taken.
✗ Branch 272 not taken.
✗ Branch 273 not taken.
✗ Branch 274 not taken.
✗ Branch 275 not taken.
✗ Branch 276 not taken.
✗ Branch 277 not taken.
✗ Branch 278 not taken.
✗ Branch 279 not taken.
✗ Branch 280 not taken.
✗ Branch 281 not taken.
✗ Branch 282 not taken.
✗ Branch 283 not taken.
✗ Branch 284 not taken.
✗ Branch 285 not taken.
✗ Branch 286 not taken.
✗ Branch 287 not taken.
✗ Branch 288 not taken.
✗ Branch 289 not taken.
✗ Branch 290 not taken.
✗ Branch 291 not taken.
✗ Branch 292 not taken.
✗ Branch 293 not taken.
✗ Branch 294 not taken.
✗ Branch 295 not taken.
✗ Branch 296 not taken.
✗ Branch 297 not taken.
✗ Branch 298 not taken.
✗ Branch 299 not taken.
✗ Branch 300 not taken.
✗ Branch 301 not taken.
✗ Branch 302 not taken.
✗ Branch 303 not taken.
✗ Branch 304 not taken.
✗ Branch 305 not taken.
✗ Branch 306 not taken.
✗ Branch 307 not taken.
✗ Branch 308 not taken.
✗ Branch 309 not taken.
✗ Branch 310 not taken.
✗ Branch 311 not taken.
✗ Branch 312 not taken.
✗ Branch 313 not taken.
✗ Branch 314 not taken.
✗ Branch 315 not taken.
✗ Branch 316 not taken.
✗ Branch 317 not taken.
✗ Branch 318 not taken.
✗ Branch 319 not taken.
✗ Branch 320 not taken.
✗ Branch 321 not taken.
✗ Branch 322 not taken.
✗ Branch 323 not taken.
✗ Branch 324 not taken.
✗ Branch 325 not taken.
✗ Branch 326 not taken.
✗ Branch 327 not taken.
✗ Branch 328 not taken.
✗ Branch 329 not taken.
✗ Branch 330 not taken.
✗ Branch 331 not taken.
✗ Branch 332 not taken.
✗ Branch 333 not taken.
✗ Branch 334 not taken.
✗ Branch 335 not taken.
✗ Branch 336 not taken.
✗ Branch 337 not taken.
✗ Branch 338 not taken.
✗ Branch 339 not taken.
✗ Branch 340 not taken.
✗ Branch 341 not taken.
✓ Branch 342 taken 114 times.
✓ Branch 343 taken 82 times.
✓ Branch 344 taken 6 times.
✓ Branch 345 taken 76 times.
✓ Branch 346 taken 122 times.
✓ Branch 347 taken 74 times.
✗ Branch 348 not taken.
✓ Branch 349 taken 74 times.
✓ Branch 350 taken 122 times.
✓ Branch 351 taken 74 times.
✗ Branch 352 not taken.
✓ Branch 353 taken 74 times.
✗ Branch 354 not taken.
✗ Branch 355 not taken.
✗ Branch 356 not taken.
✗ Branch 357 not taken.
✗ Branch 358 not taken.
✗ Branch 359 not taken.
✗ Branch 360 not taken.
✗ Branch 361 not taken.
✗ Branch 362 not taken.
✗ Branch 363 not taken.
✗ Branch 364 not taken.
✗ Branch 365 not taken.
✗ Branch 366 not taken.
✗ Branch 367 not taken.
✗ Branch 368 not taken.
✗ Branch 369 not taken.
✗ Branch 370 not taken.
✗ Branch 371 not taken.
✗ Branch 372 not taken.
✗ Branch 373 not taken.
✗ Branch 374 not taken.
✗ Branch 375 not taken.
✗ Branch 376 not taken.
✗ Branch 377 not taken.
✗ Branch 378 not taken.
✗ Branch 379 not taken.
✗ Branch 380 not taken.
✗ Branch 381 not taken.
✗ Branch 382 not taken.
✗ Branch 383 not taken.
✗ Branch 384 not taken.
✗ Branch 385 not taken.
✗ Branch 386 not taken.
✗ Branch 387 not taken.
✗ Branch 388 not taken.
✗ Branch 389 not taken.
✗ Branch 390 not taken.
✗ Branch 391 not taken.
✗ Branch 392 not taken.
✗ Branch 393 not taken.
✓ Branch 394 taken 6245352 times.
✗ Branch 395 not taken.
✓ Branch 396 taken 6245352 times.
✗ Branch 397 not taken.
✓ Branch 398 taken 6245352 times.
✗ Branch 399 not taken.
✓ Branch 400 taken 6245352 times.
✗ Branch 401 not taken.
✓ Branch 402 taken 6245352 times.
✗ Branch 403 not taken.
✓ Branch 404 taken 6245352 times.
✗ Branch 405 not taken.
✓ Branch 406 taken 6245352 times.
✗ Branch 407 not taken.
✓ Branch 408 taken 6245352 times.
✗ Branch 409 not taken.
✓ Branch 410 taken 49176 times.
✗ Branch 411 not taken.
✓ Branch 412 taken 49176 times.
✗ Branch 413 not taken.
✓ Branch 414 taken 49176 times.
✗ Branch 415 not taken.
✓ Branch 416 taken 49176 times.
✗ Branch 417 not taken.
✓ Branch 418 taken 49176 times.
✗ Branch 419 not taken.
✗ Branch 420 not taken.
✓ Branch 421 taken 49176 times.
✗ Branch 422 not taken.
✗ Branch 423 not taken.
✗ Branch 424 not taken.
✗ Branch 425 not taken.
✗ Branch 426 not taken.
✗ Branch 427 not taken.
✗ Branch 428 not taken.
✗ Branch 429 not taken.
✗ Branch 430 not taken.
✗ Branch 431 not taken.
✗ Branch 432 not taken.
✗ Branch 433 not taken.
✗ Branch 434 not taken.
✗ Branch 435 not taken.
✗ Branch 436 not taken.
✗ Branch 437 not taken.
✗ Branch 438 not taken.
✗ Branch 439 not taken.
✗ Branch 440 not taken.
✗ Branch 441 not taken.
✗ Branch 442 not taken.
✗ Branch 443 not taken.
✗ Branch 444 not taken.
✗ Branch 445 not taken.
✗ Branch 446 not taken.
✗ Branch 447 not taken.
✗ Branch 448 not taken.
✗ Branch 449 not taken.
✓ Branch 450 taken 6245352 times.
✗ Branch 451 not taken.
✓ Branch 452 taken 6245352 times.
✗ Branch 453 not taken.
✓ Branch 454 taken 6245352 times.
✗ Branch 455 not taken.
✓ Branch 456 taken 6245352 times.
✗ Branch 457 not taken.
✓ Branch 458 taken 6245352 times.
✗ Branch 459 not taken.
✓ Branch 460 taken 6245352 times.
✗ Branch 461 not taken.
✓ Branch 462 taken 6245352 times.
✗ Branch 463 not taken.
✓ Branch 464 taken 6245352 times.
✗ Branch 465 not taken.
✓ Branch 466 taken 49176 times.
✗ Branch 467 not taken.
✓ Branch 468 taken 49176 times.
✗ Branch 469 not taken.
✓ Branch 470 taken 49176 times.
✗ Branch 471 not taken.
✓ Branch 472 taken 49176 times.
✗ Branch 473 not taken.
✓ Branch 474 taken 49176 times.
✗ Branch 475 not taken.
✗ Branch 476 not taken.
✓ Branch 477 taken 49176 times.
✗ Branch 478 not taken.
✗ Branch 479 not taken.
✗ Branch 480 not taken.
✗ Branch 481 not taken.
✗ Branch 482 not taken.
✗ Branch 483 not taken.
✗ Branch 484 not taken.
✗ Branch 485 not taken.
✗ Branch 486 not taken.
✗ Branch 487 not taken.
✗ Branch 488 not taken.
✗ Branch 489 not taken.
✗ Branch 490 not taken.
✗ Branch 491 not taken.
✗ Branch 492 not taken.
✗ Branch 493 not taken.
✗ Branch 494 not taken.
✗ Branch 495 not taken.
✗ Branch 496 not taken.
✗ Branch 497 not taken.
✗ Branch 498 not taken.
✗ Branch 499 not taken.
✗ Branch 500 not taken.
✗ Branch 501 not taken.
✗ Branch 502 not taken.
✗ Branch 503 not taken.
✗ Branch 504 not taken.
✗ Branch 505 not taken.
✗ Branch 506 not taken.
✗ Branch 507 not taken.
✗ Branch 508 not taken.
✗ Branch 509 not taken.
✗ Branch 510 not taken.
✗ Branch 511 not taken.
✗ Branch 512 not taken.
✗ Branch 513 not taken.
✓ Branch 514 taken 6245352 times.
✗ Branch 515 not taken.
✓ Branch 516 taken 6245352 times.
✗ Branch 517 not taken.
✓ Branch 518 taken 6245352 times.
✗ Branch 519 not taken.
✓ Branch 520 taken 6245352 times.
✗ Branch 521 not taken.
✓ Branch 522 taken 6245352 times.
✗ Branch 523 not taken.
✓ Branch 524 taken 6245352 times.
✗ Branch 525 not taken.
✓ Branch 526 taken 6245352 times.
✗ Branch 527 not taken.
✓ Branch 528 taken 6245352 times.
✗ Branch 529 not taken.
✓ Branch 530 taken 49176 times.
✗ Branch 531 not taken.
✓ Branch 532 taken 49176 times.
✗ Branch 533 not taken.
✓ Branch 534 taken 49176 times.
✗ Branch 535 not taken.
✓ Branch 536 taken 49176 times.
✗ Branch 537 not taken.
✓ Branch 538 taken 49176 times.
✗ Branch 539 not taken.
✗ Branch 540 not taken.
✓ Branch 541 taken 49176 times.
✗ Branch 542 not taken.
✗ Branch 543 not taken.
✗ Branch 544 not taken.
✗ Branch 545 not taken.
✗ Branch 546 not taken.
✗ Branch 547 not taken.
✗ Branch 548 not taken.
✗ Branch 549 not taken.
✗ Branch 550 not taken.
✗ Branch 551 not taken.
✗ Branch 552 not taken.
✗ Branch 553 not taken.
✓ Branch 554 taken 20490 times.
✓ Branch 555 taken 28686 times.
✓ Branch 556 taken 4098 times.
✓ Branch 557 taken 16392 times.
✓ Branch 558 taken 5 times.
✓ Branch 559 taken 7 times.
✓ Branch 560 taken 1 times.
✓ Branch 561 taken 4 times.
✗ Branch 562 not taken.
✗ Branch 563 not taken.
✗ Branch 564 not taken.
✗ Branch 565 not taken.
✗ Branch 566 not taken.
✗ Branch 567 not taken.
✗ Branch 568 not taken.
✗ Branch 569 not taken.
✗ Branch 570 not taken.
✗ Branch 571 not taken.
✗ Branch 572 not taken.
✗ Branch 573 not taken.
✗ Branch 574 not taken.
✗ Branch 575 not taken.
✗ Branch 576 not taken.
✗ Branch 577 not taken.
✓ Branch 578 taken 16392 times.
✓ Branch 579 taken 32784 times.
✗ Branch 580 not taken.
✓ Branch 581 taken 16392 times.
✓ Branch 582 taken 4 times.
✓ Branch 583 taken 8 times.
✗ Branch 584 not taken.
✓ Branch 585 taken 4 times.
✗ Branch 586 not taken.
✗ Branch 587 not taken.
✗ Branch 588 not taken.
✗ Branch 589 not taken.
✗ Branch 590 not taken.
✗ Branch 591 not taken.
✗ Branch 592 not taken.
✗ Branch 593 not taken.
✗ Branch 594 not taken.
✗ Branch 595 not taken.
✗ Branch 596 not taken.
✗ Branch 597 not taken.
✓ Branch 598 taken 16392 times.
✓ Branch 599 taken 32784 times.
✗ Branch 600 not taken.
✓ Branch 601 taken 16392 times.
✓ Branch 602 taken 4 times.
✓ Branch 603 taken 8 times.
✗ Branch 604 not taken.
✓ Branch 605 taken 4 times.
✗ Branch 606 not taken.
✗ Branch 607 not taken.
✗ Branch 608 not taken.
✗ Branch 609 not taken.
✗ Branch 610 not taken.
✗ Branch 611 not taken.
✗ Branch 612 not taken.
✗ Branch 613 not taken.
✗ Branch 614 not taken.
✗ Branch 615 not taken.
✗ Branch 616 not taken.
✗ Branch 617 not taken.
✗ Branch 618 not taken.
✗ Branch 619 not taken.
✗ Branch 620 not taken.
✗ Branch 621 not taken.
✗ Branch 622 not taken.
✗ Branch 623 not taken.
✗ Branch 624 not taken.
✗ Branch 625 not taken.
✗ Branch 626 not taken.
✗ Branch 627 not taken.
✗ Branch 628 not taken.
✗ Branch 629 not taken.
✗ Branch 630 not taken.
✗ Branch 631 not taken.
✗ Branch 632 not taken.
✗ Branch 633 not taken.
✗ Branch 634 not taken.
✗ Branch 635 not taken.
✗ Branch 636 not taken.
✗ Branch 637 not taken.
✗ Branch 638 not taken.
✗ Branch 639 not taken.
✗ Branch 640 not taken.
✗ Branch 641 not taken.
✗ Branch 642 not taken.
✗ Branch 643 not taken.
✗ Branch 644 not taken.
✗ Branch 645 not taken.
✗ Branch 646 not taken.
✗ Branch 647 not taken.
✗ Branch 648 not taken.
✗ Branch 649 not taken.
✗ Branch 650 not taken.
✗ Branch 651 not taken.
✗ Branch 652 not taken.
✗ Branch 653 not taken.
19326820 return (isExactlyEqual(this->mm[0], v.mm[0]) && isExactlyEqual(this->mm[1], v.mm[1]));
121 }
122
123 /// Inequality operator, does exact floating point comparisons
124 bool operator!=(const Vec2<T> &v) const { return !(*this==v); }
125
126 /// Test if "this" vector is equivalent to vector v with tolerance of eps
127 bool eq(const Vec2<T> &v, T eps = static_cast<T>(1.0e-7)) const
128 {
129 return isApproxEqual(this->mm[0], v.mm[0], eps) &&
130 isApproxEqual(this->mm[1], v.mm[1], eps);
131 } // trivial
132
133 /// Negation operator, for e.g. v1 = -v2;
134
4/54
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 1 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
1030 Vec2<T> operator-() const {return Vec2<T>(-this->mm[0], -this->mm[1]);}
135
136 /// this = v1 + v2
137 /// "this", v1 and v2 need not be distinct objects, e.g. v.add(v1,v);
138 template <typename T0, typename T1>
139 const Vec2<T>& add(const Vec2<T0> &v1, const Vec2<T1> &v2)
140 {
141 this->mm[0] = v1[0] + v2[0];
142 this->mm[1] = v1[1] + v2[1];
143
144 return *this;
145 }
146
147 /// this = v1 - v2
148 /// "this", v1 and v2 need not be distinct objects, e.g. v.sub(v1,v);
149 template <typename T0, typename T1>
150 const Vec2<T>& sub(const Vec2<T0> &v1, const Vec2<T1> &v2)
151 {
152 this->mm[0] = v1[0] - v2[0];
153 this->mm[1] = v1[1] - v2[1];
154
155 return *this;
156 }
157
158 /// this = scalar*v, v need not be a distinct object from "this",
159 /// e.g. v.scale(1.5,v1);
160 template <typename T0, typename T1>
161 const Vec2<T>& scale(T0 scalar, const Vec2<T1> &v)
162 {
163 this->mm[0] = scalar * v[0];
164 this->mm[1] = scalar * v[1];
165
166 return *this;
167 }
168
169 template <typename T0, typename T1>
170 const Vec2<T> &div(T0 scalar, const Vec2<T1> &v)
171 {
172 this->mm[0] = v[0] / scalar;
173 this->mm[1] = v[1] / scalar;
174
175 return *this;
176 }
177
178 /// Dot product
179 T dot(const Vec2<T> &v) const { return this->mm[0]*v[0] + this->mm[1]*v[1]; } // trivial
180
181 /// Length of the vector
182 T length() const
183 {
184 return static_cast<T>(sqrt(double(this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1])));
185 }
186
187 /// Squared length of the vector, much faster than length() as it
188 /// does not involve square root
189 T lengthSqr() const { return (this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1]); }
190
191 /// Return a reference to itsef after the exponent has been
192 /// applied to all the vector components.
193 inline const Vec2<T>& exp()
194 {
195 this->mm[0] = std::exp(this->mm[0]);
196 this->mm[1] = std::exp(this->mm[1]);
197 return *this;
198 }
199
200 /// Return a reference to itself after log has been
201 /// applied to all the vector components.
202 inline const Vec2<T>& log()
203 {
204 this->mm[0] = std::log(this->mm[0]);
205 this->mm[1] = std::log(this->mm[1]);
206 return *this;
207 }
208
209 /// Return the sum of all the vector components.
210 inline T sum() const
211 {
212 return this->mm[0] + this->mm[1];
213 }
214
215 /// Return the product of all the vector components.
216 inline T product() const
217 {
218 return this->mm[0] * this->mm[1];
219 }
220
221 /// this = normalized this
222 bool normalize(T eps = static_cast<T>(1.0e-8))
223 {
224 T d = length();
225 if (isApproxEqual(d, T(0), eps)) {
226 return false;
227 }
228 *this *= (T(1) / d);
229 return true;
230 }
231
232 /// return normalized this, throws if null vector
233 Vec2<T> unit(T eps=0) const
234 {
235 T d;
236 return unit(eps, d);
237 }
238
239 /// return normalized this and length, throws if null vector
240 Vec2<T> unit(T eps, T& len) const
241 {
242 len = length();
243 if (isApproxEqual(len, T(0), eps)) {
244 OPENVDB_THROW(ArithmeticError, "Normalizing null 2-vector");
245 }
246 return *this / len;
247 }
248
249 /// return normalized this, or (1, 0) if this is null vector
250 Vec2<T> unitSafe() const
251 {
252 T l2 = lengthSqr();
253 return l2 ? *this/static_cast<T>(sqrt(l2)) : Vec2<T>(1,0);
254 }
255
256 /// Multiply each element of this vector by @a scalar.
257 template <typename S>
258 const Vec2<T> &operator*=(S scalar)
259 {
260 this->mm[0] *= scalar;
261 this->mm[1] *= scalar;
262 return *this;
263 }
264
265 /// Multiply each element of this vector by the corresponding element of the given vector.
266 template <typename S>
267 const Vec2<T> &operator*=(const Vec2<S> &v1)
268 {
269 this->mm[0] *= v1[0];
270 this->mm[1] *= v1[1];
271 return *this;
272 }
273
274 /// Divide each element of this vector by @a scalar.
275 template <typename S>
276 const Vec2<T> &operator/=(S scalar)
277 {
278 this->mm[0] /= scalar;
279 this->mm[1] /= scalar;
280 return *this;
281 }
282
283 /// Divide each element of this vector by the corresponding element of the given vector.
284 template <typename S>
285 const Vec2<T> &operator/=(const Vec2<S> &v1)
286 {
287 this->mm[0] /= v1[0];
288 this->mm[1] /= v1[1];
289 return *this;
290 }
291
292 /// Add @a scalar to each element of this vector.
293 template <typename S>
294 const Vec2<T> &operator+=(S scalar)
295 {
296 524290 this->mm[0] += scalar;
297 524290 this->mm[1] += scalar;
298 return *this;
299 }
300
301 /// Add each element of the given vector to the corresponding element of this vector.
302 template <typename S>
303 const Vec2<T> &operator+=(const Vec2<S> &v1)
304 {
305 4 this->mm[0] += v1[0];
306 4 this->mm[1] += v1[1];
307 return *this;
308 }
309
310 /// Subtract @a scalar from each element of this vector.
311 template <typename S>
312 const Vec2<T> &operator-=(S scalar)
313 {
314 this->mm[0] -= scalar;
315 this->mm[1] -= scalar;
316 return *this;
317 }
318
319 /// Subtract each element of the given vector from the corresponding element of this vector.
320 template <typename S>
321 const Vec2<T> &operator-=(const Vec2<S> &v1)
322 {
323 2 this->mm[0] -= v1[0];
324 2 this->mm[1] -= v1[1];
325 return *this;
326 }
327
328 // Number of cols, rows, elements
329 static unsigned numRows() { return 1; }
330 static unsigned numColumns() { return 2; }
331 static unsigned numElements() { return 2; }
332
333 /// Returns the scalar component of v in the direction of onto, onto need
334 /// not be unit. e.g float c = Vec2f::component(v1,v2);
335 T component(const Vec2<T> &onto, T eps = static_cast<T>(1.0e-8)) const
336 {
337 T l = onto.length();
338 if (isApproxEqual(l, T(0), eps)) return 0;
339
340 return dot(onto)*(T(1)/l);
341 }
342
343 /// Return the projection of v onto the vector, onto need not be unit
344 /// e.g. Vec2f v = Vec2f::projection(v,n);
345 Vec2<T> projection(const Vec2<T> &onto, T eps = static_cast<T>(1.0e-8)) const
346 {
347 T l = onto.lengthSqr();
348 if (isApproxEqual(l, T(0), eps)) return Vec2::zero();
349
350 return onto*(dot(onto)*(T(1)/l));
351 }
352
353 /// Return an arbitrary unit vector perpendicular to v
354 /// Vector v must be a unit vector
355 /// e.g. v.normalize(); Vec2f n = Vec2f::getArbPerpendicular(v);
356 Vec2<T> getArbPerpendicular() const { return Vec2<T>(-this->mm[1], this->mm[0]); }
357
358 /// Predefined constants, e.g. Vec2f v = Vec2f::xNegAxis();
359 static Vec2<T> zero() { return Vec2<T>(0, 0); }
360 static Vec2<T> ones() { return Vec2<T>(1, 1); }
361 };
362
363 /// Multiply each element of the given vector by @a scalar and return the result.
364 template <typename S, typename T>
365 inline Vec2<typename promote<S, T>::type> operator*(S scalar, const Vec2<T> &v)
366 {
367 return v * scalar;
368 }
369
370 /// Multiply each element of the given vector by @a scalar and return the result.
371 template <typename S, typename T>
372 inline Vec2<typename promote<S, T>::type> operator*(const Vec2<T> &v, S scalar)
373 {
374 Vec2<typename promote<S, T>::type> result(v);
375 result *= scalar;
376 return result;
377 }
378
379 /// Multiply corresponding elements of @a v0 and @a v1 and return the result.
380 template <typename T0, typename T1>
381 inline Vec2<typename promote<T0, T1>::type> operator*(const Vec2<T0> &v0, const Vec2<T1> &v1)
382 {
383 Vec2<typename promote<T0, T1>::type> result(v0[0] * v1[0], v0[1] * v1[1]);
384
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 return result;
385 }
386
387 /// Divide @a scalar by each element of the given vector and return the result.
388 template <typename S, typename T>
389 inline Vec2<typename promote<S, T>::type> operator/(S scalar, const Vec2<T> &v)
390 {
391 return Vec2<typename promote<S, T>::type>(scalar/v[0], scalar/v[1]);
392 }
393
394 /// Divide each element of the given vector by @a scalar and return the result.
395 template <typename S, typename T>
396 inline Vec2<typename promote<S, T>::type> operator/(const Vec2<T> &v, S scalar)
397 {
398 Vec2<typename promote<S, T>::type> result(v);
399 result /= scalar;
400 return result;
401 }
402
403 /// Divide corresponding elements of @a v0 and @a v1 and return the result.
404 template <typename T0, typename T1>
405 inline Vec2<typename promote<T0, T1>::type> operator/(const Vec2<T0> &v0, const Vec2<T1> &v1)
406 {
407 Vec2<typename promote<T0, T1>::type> result(v0[0] / v1[0], v0[1] / v1[1]);
408
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 return result;
409 }
410
411 /// Add corresponding elements of @a v0 and @a v1 and return the result.
412 template <typename T0, typename T1>
413 inline Vec2<typename promote<T0, T1>::type> operator+(const Vec2<T0> &v0, const Vec2<T1> &v1)
414 {
415 Vec2<typename promote<T0, T1>::type> result(v0);
416 result += v1;
417
4/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
4 return result;
418 }
419
420 /// Add @a scalar to each element of the given vector and return the result.
421 template <typename S, typename T>
422 inline Vec2<typename promote<S, T>::type> operator+(const Vec2<T> &v, S scalar)
423 {
424 524288 Vec2<typename promote<S, T>::type> result(v);
425 result += scalar;
426
2/8
✓ Branch 2 taken 262144 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 262144 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
524290 return result;
427 }
428
429 /// Subtract corresponding elements of @a v0 and @a v1 and return the result.
430 template <typename T0, typename T1>
431 inline Vec2<typename promote<T0, T1>::type> operator-(const Vec2<T0> &v0, const Vec2<T1> &v1)
432 {
433 Vec2<typename promote<T0, T1>::type> result(v0);
434 result -= v1;
435
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 return result;
436 }
437
438 /// Subtract @a scalar from each element of the given vector and return the result.
439 template <typename S, typename T>
440 inline Vec2<typename promote<S, T>::type> operator-(const Vec2<T> &v, S scalar)
441 {
442 Vec2<typename promote<S, T>::type> result(v);
443 result -= scalar;
444 return result;
445 }
446
447 /// Angle between two vectors, the result is between [0, pi],
448 /// e.g. float a = Vec2f::angle(v1,v2);
449 template <typename T>
450 inline T angle(const Vec2<T> &v1, const Vec2<T> &v2)
451 {
452 T c = v1.dot(v2);
453 return acos(c);
454 }
455
456 template <typename T>
457 inline bool
458 isApproxEqual(const Vec2<T>& a, const Vec2<T>& b)
459 {
460 return a.eq(b);
461 }
462 template <typename T>
463 inline bool
464 isApproxEqual(const Vec2<T>& a, const Vec2<T>& b, const Vec2<T>& eps)
465 {
466
11/36
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 49 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 49 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 49 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 49 times.
✓ Branch 24 taken 49140 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 49140 times.
✗ Branch 27 not taken.
✓ Branch 28 taken 49140 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 49140 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 49189 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 49140 times.
✓ Branch 35 taken 49 times.
147567 return isApproxEqual(a.x(), b.x(), eps.x()) &&
467 isApproxEqual(a.y(), b.y(), eps.y());
468 }
469
470 template<typename T>
471 inline Vec2<T>
472 Abs(const Vec2<T>& v)
473 {
474 return Vec2<T>(Abs(v[0]), Abs(v[1]));
475 }
476
477 /// Orthonormalize vectors v1 and v2 and store back the resulting basis
478 /// e.g. Vec2f::orthonormalize(v1,v2);
479 template <typename T>
480 inline void orthonormalize(Vec2<T> &v1, Vec2<T> &v2)
481 {
482 // If the input vectors are v0, v1, and v2, then the Gram-Schmidt
483 // orthonormalization produces vectors u0, u1, and u2 as follows,
484 //
485 // u0 = v0/|v0|
486 // u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0|
487 //
488 // where |A| indicates length of vector A and A*B indicates dot
489 // product of vectors A and B.
490
491 // compute u0
492 v1.normalize();
493
494 // compute u1
495 T d0 = v1.dot(v2);
496 v2 -= v1*d0;
497 v2.normalize();
498 }
499
500
501 /// \remark We are switching to a more explicit name because the semantics
502 /// are different from std::min/max. In that case, the function returns a
503 /// reference to one of the objects based on a comparator. Here, we must
504 /// fabricate a new object which might not match either of the inputs.
505
506 /// Return component-wise minimum of the two vectors.
507 template <typename T>
508 inline Vec2<T> minComponent(const Vec2<T> &v1, const Vec2<T> &v2)
509 {
510 return Vec2<T>(
511 std::min(v1.x(), v2.x()),
512 std::min(v1.y(), v2.y()));
513 }
514
515 /// Return component-wise maximum of the two vectors.
516 template <typename T>
517 inline Vec2<T> maxComponent(const Vec2<T> &v1, const Vec2<T> &v2)
518 {
519 return Vec2<T>(
520 std::max(v1.x(), v2.x()),
521 std::max(v1.y(), v2.y()));
522 }
523
524 /// @brief Return a vector with the exponent applied to each of
525 /// the components of the input vector.
526 template <typename T>
527 inline Vec2<T> Exp(Vec2<T> v) { return v.exp(); }
528
529 /// @brief Return a vector with log applied to each of
530 /// the components of the input vector.
531 template <typename T>
532 inline Vec2<T> Log(Vec2<T> v) { return v.log(); }
533
534 using Vec2i = Vec2<int32_t>;
535 using Vec2ui = Vec2<uint32_t>;
536 using Vec2s = Vec2<float>;
537 using Vec2d = Vec2<double>;
538
539 #if OPENVDB_ABI_VERSION_NUMBER >= 8
540 OPENVDB_IS_POD(Vec2i)
541 OPENVDB_IS_POD(Vec2ui)
542 OPENVDB_IS_POD(Vec2s)
543 OPENVDB_IS_POD(Vec2d)
544 #endif
545
546 } // namespace math
547 } // namespace OPENVDB_VERSION_NAME
548 } // namespace openvdb
549
550 #endif // OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
551