Loading...
Searching...
No Matches
Geometry.h
Go to the documentation of this file.
1/**************************************************************************************************
2 * This file is a part of Ultralight. *
3 * *
4 * See <https://ultralig.ht> for licensing and more. *
5 * *
6 * (C) 2024 Ultralight, Inc. *
7 **************************************************************************************************/
8#pragma once
10#include <memory.h>
11#include <cmath>
12#include <cstring>
13#include <algorithm>
14
15namespace ultralight {
16
17///
18/// 2D Vector Helper
19///
20struct UExport vec2 {
21 float x, y;
22
23 inline vec2() : x(0.0f), y(0.0f) { }
24
25 inline vec2(float x, float y) : x(x), y(y) {}
26
27 inline vec2(float x) : x(x), y(x) {}
28
29 inline vec2 yx() const { return { y, x }; }
30
31 inline vec2 xx() const { return { x, x }; }
32
33 inline vec2 yy() const { return { y, y }; }
34
35 inline friend vec2 operator+(vec2 lhs, const vec2& rhs) { lhs += rhs; return lhs; }
36
37 inline friend vec2 operator-(vec2 lhs, const vec2& rhs) { lhs -= rhs; return lhs; }
38
39 inline friend vec2 operator*(vec2 lhs, const vec2& rhs) { lhs *= rhs; return lhs; }
40
41 inline friend vec2 operator/(vec2 lhs, const vec2& rhs) { lhs /= rhs; return lhs; }
42
43 inline friend vec2 operator+(vec2 lhs, float rhs) { lhs += rhs; return lhs; }
44
45 inline friend vec2 operator-(vec2 lhs, float rhs) { lhs -= rhs; return lhs; }
46
47 inline friend vec2 operator*(vec2 lhs, float rhs) { lhs *= rhs; return lhs; }
48
49 inline friend vec2 operator/(vec2 lhs, float rhs) { lhs /= rhs; return lhs; }
50
51 inline vec2& operator+=(const vec2& rhs) {
52 x += rhs.x;
53 y += rhs.y;
54 return *this;
55 }
56
57 inline vec2& operator-=(const vec2& rhs) {
58 x -= rhs.x;
59 y -= rhs.y;
60 return *this;
61 }
62
63 inline vec2& operator*=(const vec2& rhs) {
64 x *= rhs.x;
65 y *= rhs.y;
66 return *this;
67 }
68
69 inline vec2& operator/=(const vec2& rhs) {
70 x /= rhs.x;
71 y /= rhs.y;
72 return *this;
73 }
74
75 inline vec2& operator+=(float rhs) {
76 x += rhs;
77 y += rhs;
78 return *this;
79 }
80
81 inline vec2& operator-=(float rhs) {
82 x -= rhs;
83 y -= rhs;
84 return *this;
85 }
86
87 inline vec2& operator*=(float rhs) {
88 x *= rhs;
89 y *= rhs;
90 return *this;
91 }
92
93 inline vec2& operator/=(float rhs) {
94 x /= rhs;
95 y /= rhs;
96 return *this;
97 }
98
99 inline friend bool operator==(const vec2& a, const vec2& b) {
100 return !memcmp(&a, &b, sizeof(a));
101 }
102
103 inline friend bool operator!=(const vec2& a, const vec2& b) {
104 return !(a == b);
105 }
106
107 inline friend vec2 min_(const vec2& a, const vec2& b) {
108 return{ (b.x < a.x) ? b.x : a.x,
109 (b.y < a.y) ? b.y : a.y };
110 }
111
112 inline friend vec2 max_(const vec2& a, const vec2& b) {
113 return{ (a.x < b.x) ? b.x : a.x,
114 (a.y < b.y) ? b.y : a.y };
115 }
116
117 inline friend vec2 clamp(const vec2& x, const vec2& minVal, const vec2& maxVal) {
118 return min_(max_(x, minVal), maxVal);
119 }
120
121 inline friend vec2 mix(const vec2& a, const vec2& b, float t) {
122 return a * (1.0f - t) + b * t;
123 }
124
125 inline friend float length(const vec2& a) {
126 return sqrtf(a.x * a.x + a.y * a.y);
127 }
128
129 // squared length
130 inline friend float length2(const vec2& a) {
131 return dot(a, a);
132 }
133
134 inline friend float distance(const vec2& a, const vec2& b) {
135 return length(a - b);
136 }
137
138 // squared distance
139 inline friend float distance2(const vec2& a, const vec2& b) {
140 return length2(a - b);
141 }
142
143 inline friend vec2 normalize(const vec2& a) {
144 return a / length(a);
145 }
146
147 inline friend float dot(const vec2& a, const vec2& b) {
148 return a.x * b.x + a.y * b.y;
149 }
150};
151
152///
153/// 3D Vector Helper
154///
155struct UExport vec3 {
156 float x, y, z;
157
158 inline vec3() : x(0.0f), y(0.0f), z(0.0f) { }
159
160 inline vec3(float x, float y, float z) : x(x), y(y), z(z) {}
161
162 inline vec3(float x) : x(x), y(x), z(x) {}
163
164 inline friend vec3 operator+(vec3 lhs, const vec3& rhs) { lhs += rhs; return lhs; }
165
166 inline friend vec3 operator-(vec3 lhs, const vec3& rhs) { lhs -= rhs; return lhs; }
167
168 inline friend vec3 operator*(vec3 lhs, const vec3& rhs) { lhs *= rhs; return lhs; }
169
170 inline friend vec3 operator/(vec3 lhs, const vec3& rhs) { lhs /= rhs; return lhs; }
171
172 inline friend vec3 operator+(vec3 lhs, float rhs) { lhs += rhs; return lhs; }
173
174 inline friend vec3 operator-(vec3 lhs, float rhs) { lhs -= rhs; return lhs; }
175
176 inline friend vec3 operator*(vec3 lhs, float rhs) { lhs *= rhs; return lhs; }
177
178 inline friend vec3 operator/(vec3 lhs, float rhs) { lhs /= rhs; return lhs; }
179
180 inline vec3& operator+=(const vec3& rhs) {
181 x += rhs.x;
182 y += rhs.y;
183 z += rhs.z;
184 return *this;
185 }
186
187 inline vec3& operator-=(const vec3& rhs) {
188 x -= rhs.x;
189 y -= rhs.y;
190 z -= rhs.z;
191 return *this;
192 }
193
194 inline vec3& operator*=(const vec3& rhs) {
195 x *= rhs.x;
196 y *= rhs.y;
197 z *= rhs.z;
198 return *this;
199 }
200
201 inline vec3& operator/=(const vec3& rhs) {
202 x /= rhs.x;
203 y /= rhs.y;
204 z /= rhs.z;
205 return *this;
206 }
207
208 inline vec3& operator+=(float rhs) {
209 x += rhs;
210 y += rhs;
211 z += rhs;
212 return *this;
213 }
214
215 inline vec3& operator-=(float rhs) {
216 x -= rhs;
217 y -= rhs;
218 z -= rhs;
219 return *this;
220 }
221
222 inline vec3& operator*=(float rhs) {
223 x *= rhs;
224 y *= rhs;
225 z *= rhs;
226 return *this;
227 }
228
229 inline vec3& operator/=(float rhs) {
230 x /= rhs;
231 y /= rhs;
232 z /= rhs;
233 return *this;
234 }
235
236 inline friend bool operator==(const vec3& a, const vec3& b) {
237 return !memcmp(&a, &b, sizeof(a));
238 }
239
240 inline friend bool operator!=(const vec3& a, const vec3& b) {
241 return !(a == b);
242 }
243
244 inline friend vec3 min_(const vec3& a, const vec3& b) {
245 return{ (b.x < a.x) ? b.x : a.x,
246 (b.y < a.y) ? b.y : a.y,
247 (b.z < a.z) ? b.z : a.z };
248 }
249
250 inline friend vec3 max_(const vec3& a, const vec3& b) {
251 return{ (a.x < b.x) ? b.x : a.x,
252 (a.y < b.y) ? b.y : a.y,
253 (a.z < b.z) ? b.z : a.z };
254 }
255 inline friend vec3 clamp(const vec3& x, const vec3& minVal, const vec3& maxVal) {
256 return min_(max_(x, minVal), maxVal);
257 }
258
259 inline friend vec3 mix(const vec3& a, const vec3& b, float t) {
260 return a * (1.0f - t) + b * t;
261 }
262
263 inline friend float length(const vec3& a) {
264 return sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
265 }
266
267 inline friend float distance(const vec3& a, const vec3& b) {
268 return length(a - b);
269 }
270
271 inline friend vec3 normalize(const vec3& a) {
272 return a / length(a);
273 }
274
275 inline friend float dot(const vec3& a, const vec3& b) {
276 return a.x * b.x + a.y * b.y + a.z * b.z;
277 }
278};
279
280///
281/// 4D Vector Helper
282///
283struct UExport vec4 {
284 float x, y, z, w;
285
286 inline vec4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) { }
287
288 inline vec4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
289
290 inline vec4(float x) : x(x), y(x), z(x), w(x) {}
291
292 inline vec4(const float val[4]) : x(val[0]), y(val[1]), z(val[2]), w(val[3]) { }
293
294 inline friend bool operator==(const vec4& a, const vec4& b) {
295 return !memcmp(&a, &b, sizeof(a));
296 }
297
298 inline friend bool operator!=(const vec4& a, const vec4& b) {
299 return !(a == b);
300 }
301
302 inline friend vec4 operator+(vec4 lhs, const vec4& rhs) { lhs += rhs; return lhs; }
303
304 inline friend vec4 operator-(vec4 lhs, const vec4& rhs) { lhs -= rhs; return lhs; }
305
306 inline friend vec4 operator*(vec4 lhs, const vec4& rhs) { lhs *= rhs; return lhs; }
307
308 inline friend vec4 operator/(vec4 lhs, const vec4& rhs) { lhs /= rhs; return lhs; }
309
310 inline friend vec4 operator+(vec4 lhs, float rhs) { lhs += rhs; return lhs; }
311
312 inline friend vec4 operator-(vec4 lhs, float rhs) { lhs -= rhs; return lhs; }
313
314 inline friend vec4 operator*(vec4 lhs, float rhs) { lhs *= rhs; return lhs; }
315
316 inline friend vec4 operator/(vec4 lhs, float rhs) { lhs /= rhs; return lhs; }
317
318 inline vec4& operator+=(const vec4& rhs) {
319 x += rhs.x;
320 y += rhs.y;
321 z += rhs.z;
322 w += rhs.w;
323 return *this;
324 }
325
326 inline vec4& operator-=(const vec4& rhs) {
327 x -= rhs.x;
328 y -= rhs.y;
329 z -= rhs.z;
330 w -= rhs.w;
331 return *this;
332 }
333
334 inline vec4& operator*=(const vec4& rhs) {
335 x *= rhs.x;
336 y *= rhs.y;
337 z *= rhs.z;
338 w *= rhs.w;
339 return *this;
340 }
341
342 inline vec4& operator/=(const vec4& rhs) {
343 x /= rhs.x;
344 y /= rhs.y;
345 z /= rhs.z;
346 w /= rhs.w;
347 return *this;
348 }
349
350 inline vec4& operator+=(float rhs) {
351 x += rhs;
352 y += rhs;
353 z += rhs;
354 w += rhs;
355 return *this;
356 }
357
358 inline vec4& operator-=(float rhs) {
359 x -= rhs;
360 y -= rhs;
361 z -= rhs;
362 w -= rhs;
363 return *this;
364 }
365
366 inline vec4& operator*=(float rhs) {
367 x *= rhs;
368 y *= rhs;
369 z *= rhs;
370 w *= rhs;
371 return *this;
372 }
373
374 inline vec4& operator/=(float rhs) {
375 x /= rhs;
376 y /= rhs;
377 z /= rhs;
378 w /= rhs;
379 return *this;
380 }
381
382 inline friend vec4 min_(const vec4& a, const vec4& b) {
383 return{ (b.x < a.x) ? b.x : a.x,
384 (b.y < a.y) ? b.y : a.y,
385 (b.z < a.z) ? b.z : a.z,
386 (b.w < a.w) ? b.w : a.w };
387 }
388
389 inline friend vec4 max_(const vec4& a, const vec4& b) {
390 return{ (a.x < b.x) ? b.x : a.x,
391 (a.y < b.y) ? b.y : a.y,
392 (a.z < b.z) ? b.z : a.z,
393 (a.w < b.w) ? b.w : a.w };
394 }
395
396 inline void load(const float* val) {
397 x = val[0];
398 y = val[1];
399 z = val[2];
400 w = val[3];
401 }
402
403 inline void store(float* val) const {
404 val[0] = x;
405 val[1] = y;
406 val[2] = z;
407 val[3] = w;
408 }
409};
410
411///
412/// Point is typedef'd to a 2D vector
413///
414typedef vec2 Point;
415
416///
417/// Float Rectangle Helper
418///
419struct UExport Rect {
420 float left, top, right, bottom;
421
422 static constexpr Rect MakeEmpty() { return Rect{ 0.0f, 0.0f, 0.0f, 0.0f }; }
423
424 inline float width() const { return right - left; }
425 inline float height() const { return bottom - top; }
426 inline float x() const { return left; }
427 inline float y() const { return top; }
428 inline float center_x() const { return (left + right) * 0.5f; }
429 inline float center_y() const { return (top + bottom) * 0.5f; }
430
431 inline Point origin() const { return { left, top }; }
432
433 inline void SetEmpty() { *this = MakeEmpty(); }
434
435 inline bool IsEmpty() const {
436 return *this == MakeEmpty();
437 }
438
439 inline bool IsValid() const {
440 return width() > 0 && height() > 0;
441 }
442
443 inline void Inset(float dx, float dy) {
444 left += dx;
445 top += dy;
446 right -= dx;
447 bottom -= dy;
448 }
449
450 inline void Outset(float dx, float dy) {
451 Inset(-dx, -dy);
452 }
453
454 inline void Move(float dx, float dy) {
455 left += dx;
456 top += dy;
457 right += dx;
458 bottom += dy;
459 }
460
461 inline float area() const {
462 return width() * height();
463 }
464
465 inline void Join(const Rect& rhs) {
466 // if we are empty, just assign
467 if (IsEmpty()) {
468 *this = rhs;
469 }
470 else {
471 if (rhs.left < left) left = rhs.left;
472 if (rhs.top < top) top = rhs.top;
473 if (rhs.right > right) right = rhs.right;
474 if (rhs.bottom > bottom) bottom = rhs.bottom;
475 }
476 }
477
478 inline void Join(const Point& p) {
479 // if we are empty, just assign
480 if (IsEmpty()) {
481 *this = { p.x, p.y, p.x, p.y };
482 }
483 else {
484 if (p.x < left) left = p.x;
485 if (p.y < top) top = p.y;
486 if (p.x > right) right = p.x;
487 if (p.y > bottom) bottom = p.y;
488 }
489 }
490
491 inline bool Contains(const Point& p) const {
492 return p.x >= left && p.x <= right &&
493 p.y >= top && p.y <= bottom;
494 }
495
496 inline bool Contains(const Rect& r) const {
497 return left <= r.left && top <= r.top &&
498 right >= r.right && bottom >= r.bottom;
499 }
500
501 inline bool Intersects(const Rect& rhs) const {
502 return !(rhs.left > right ||
503 rhs.right < left ||
504 rhs.top > bottom ||
505 rhs.bottom < top);
506 }
507
508 inline Rect Intersect(const Rect& other) const {
509 return{ (left < other.left) ? other.left : left,
510 (top < other.top) ? other.top : top,
511 (other.right < right) ? other.right : right,
512 (other.bottom < bottom) ? other.bottom : bottom };
513 }
514
515 friend inline bool operator==(const Rect& a, const Rect& b) {
516 return !memcmp(&a, &b, sizeof(a));
517 }
518
519 friend inline bool operator!=(const Rect& a, const Rect& b) {
520 return !(a == b);
521 }
522
523 inline vec4 ToVec4() { return vec4 { left, top, right, bottom }; }
524};
525
526///
527/// Integer Rectangle Helper
528///
530 int left, top, right, bottom;
531
532 static constexpr IntRect MakeEmpty() { return IntRect{ 0, 0, 0, 0 }; }
533
534 inline int width() const { return right - left; }
535 inline int height() const { return bottom - top; }
536 inline int x() const { return left; }
537 inline int y() const { return top; }
538 inline int center_x() const { return (int)std::round((left + right) * 0.5f); }
539 inline int center_y() const { return (int)std::round((top + bottom) * 0.5f); }
540
541 inline Point origin() const { return Point{ (float)left, (float)top }; }
542
543 inline void SetEmpty() { *this = MakeEmpty(); }
544
545 inline bool IsEmpty() const {
546 return *this == MakeEmpty();
547 }
548
549 inline bool IsValid() const {
550 return width() > 0 && height() > 0;
551 }
552
553 inline void Inset(int dx, int dy) {
554 left += dx;
555 top += dy;
556 right -= dx;
557 bottom -= dy;
558 }
559
560 inline void Outset(int dx, int dy) {
561 Inset(-dx, -dy);
562 }
563
564 inline void Move(int dx, int dy) {
565 left += dx;
566 top += dy;
567 right += dx;
568 bottom += dy;
569 }
570
571 inline int area() const {
572 return width() * height();
573 }
574
575 inline void Join(const IntRect& rhs) {
576 // if we are empty, just assign
577 if (IsEmpty()) {
578 *this = rhs;
579 }
580 else {
581 if (rhs.left < left) left = rhs.left;
582 if (rhs.top < top) top = rhs.top;
583 if (rhs.right > right) right = rhs.right;
584 if (rhs.bottom > bottom) bottom = rhs.bottom;
585 }
586 }
587
588 inline void Join(const Point& p) {
589 // if we are empty, just assign
590 if (IsEmpty()) {
591 *this = { (int)std::floor(p.x), (int)std::floor(p.y), (int)std::ceil(p.x), (int)std::ceil(p.y) };
592 }
593 else {
594 if ((int)std::floor(p.x) < left) left = (int)std::floor(p.x);
595 if ((int)std::floor(p.y) < top) top = (int)std::floor(p.y);
596 if ((int)std::ceil(p.x) > right) right = (int)std::ceil(p.x);
597 if ((int)std::ceil(p.y) > bottom) bottom = (int)std::ceil(p.y);
598 }
599 }
600
601 inline bool Contains(const Point& p) const {
602 return p.x >= left && p.x <= right &&
603 p.y >= top && p.y <= bottom;
604 }
605
606 inline bool Contains(const IntRect& r) const {
607 return left <= r.left && top <= r.top &&
608 right >= r.right && bottom >= r.bottom;
609 }
610
611 inline bool Intersects(const IntRect& rhs) const {
612 // Since this is mostly used for pixel operations, we only count
613 // intersections that have width and height >= 1.
614 return !(rhs.left > right - 1 ||
615 rhs.right < left ||
616 rhs.top > bottom - 1 ||
617 rhs.bottom < top);
618 }
619
620 inline IntRect Intersect(const IntRect& other) const {
621 return{ (left < other.left) ? other.left : left,
622 (top < other.top) ? other.top : top,
623 (other.right < right) ? other.right : right,
624 (other.bottom < bottom) ? other.bottom : bottom };
625 }
626
627 friend inline bool operator==(const IntRect& a, const IntRect& b) {
628 return !memcmp(&a, &b, sizeof(a));
629 }
630
631 friend inline bool operator!=(const IntRect& a, const IntRect& b) {
632 return !(a == b);
633 }
634};
635
636///
637/// Rounded Rectangle Helper
638///
641 float radii_x[4];
642 float radii_y[4];
643
644 void SetEmpty();
645
646 bool IsRounded() const;
647
648 // Negative is inside, positive is outside.
649 float GetSignedDistance(const Point& p) const;
650
651 // Returns whether or not intersection is found. Can fail if the resulting
652 // geometry is not a rounded rectangle.
653 bool Intersect(const RoundedRect& other, RoundedRect& result) const;
654
656
658};
659
660} // namespace ultralight
#define UExport
Definition Exports.h:25
Definition App.h:14
vec2 Point
Point is typedef'd to a 2D vector.
Definition Geometry.h:414
Integer Rectangle Helper.
Definition Geometry.h:529
void Join(const IntRect &rhs)
Definition Geometry.h:575
friend bool operator==(const IntRect &a, const IntRect &b)
Definition Geometry.h:627
int x() const
Definition Geometry.h:536
bool Contains(const IntRect &r) const
Definition Geometry.h:606
void Outset(int dx, int dy)
Definition Geometry.h:560
int right
Definition Geometry.h:530
int bottom
Definition Geometry.h:530
void Join(const Point &p)
Definition Geometry.h:588
Point origin() const
Definition Geometry.h:541
friend bool operator!=(const IntRect &a, const IntRect &b)
Definition Geometry.h:631
int y() const
Definition Geometry.h:537
bool IsEmpty() const
Definition Geometry.h:545
bool Intersects(const IntRect &rhs) const
Definition Geometry.h:611
void Move(int dx, int dy)
Definition Geometry.h:564
int center_x() const
Definition Geometry.h:538
void Inset(int dx, int dy)
Definition Geometry.h:553
IntRect Intersect(const IntRect &other) const
Definition Geometry.h:620
void SetEmpty()
Definition Geometry.h:543
bool IsValid() const
Definition Geometry.h:549
bool Contains(const Point &p) const
Definition Geometry.h:601
int height() const
Definition Geometry.h:535
int width() const
Definition Geometry.h:534
int left
Definition Geometry.h:530
int center_y() const
Definition Geometry.h:539
static constexpr IntRect MakeEmpty()
Definition Geometry.h:532
int top
Definition Geometry.h:530
int area() const
Definition Geometry.h:571
Float Rectangle Helper.
Definition Geometry.h:419
void Inset(float dx, float dy)
Definition Geometry.h:443
float y() const
Definition Geometry.h:427
void Move(float dx, float dy)
Definition Geometry.h:454
Rect Intersect(const Rect &other) const
Definition Geometry.h:508
void Join(const Point &p)
Definition Geometry.h:478
float bottom
Definition Geometry.h:420
friend bool operator==(const Rect &a, const Rect &b)
Definition Geometry.h:515
bool Contains(const Rect &r) const
Definition Geometry.h:496
friend bool operator!=(const Rect &a, const Rect &b)
Definition Geometry.h:519
float height() const
Definition Geometry.h:425
Point origin() const
Definition Geometry.h:431
float center_x() const
Definition Geometry.h:428
float right
Definition Geometry.h:420
float area() const
Definition Geometry.h:461
float left
Definition Geometry.h:420
float center_y() const
Definition Geometry.h:429
bool IsEmpty() const
Definition Geometry.h:435
vec4 ToVec4()
Definition Geometry.h:523
static constexpr Rect MakeEmpty()
Definition Geometry.h:422
float x() const
Definition Geometry.h:426
float width() const
Definition Geometry.h:424
void Join(const Rect &rhs)
Definition Geometry.h:465
bool Intersects(const Rect &rhs) const
Definition Geometry.h:501
void SetEmpty()
Definition Geometry.h:433
bool IsValid() const
Definition Geometry.h:439
void Outset(float dx, float dy)
Definition Geometry.h:450
bool Contains(const Point &p) const
Definition Geometry.h:491
float top
Definition Geometry.h:420
Rounded Rectangle Helper.
Definition Geometry.h:639
float GetSignedDistance(const Point &p) const
Rect rect
Definition Geometry.h:640
bool Intersect(const RoundedRect &other, RoundedRect &result) const
Rect CalculateInterior() const
2D Vector Helper
Definition Geometry.h:20
vec2 & operator+=(const vec2 &rhs)
Definition Geometry.h:51
vec2 & operator+=(float rhs)
Definition Geometry.h:75
friend float length2(const vec2 &a)
Definition Geometry.h:130
vec2 yy() const
Definition Geometry.h:33
vec2 xx() const
Definition Geometry.h:31
friend vec2 mix(const vec2 &a, const vec2 &b, float t)
Definition Geometry.h:121
vec2 yx() const
Definition Geometry.h:29
friend float dot(const vec2 &a, const vec2 &b)
Definition Geometry.h:147
friend float distance(const vec2 &a, const vec2 &b)
Definition Geometry.h:134
friend float distance2(const vec2 &a, const vec2 &b)
Definition Geometry.h:139
vec2 & operator/=(float rhs)
Definition Geometry.h:93
vec2 & operator/=(const vec2 &rhs)
Definition Geometry.h:69
friend vec2 operator-(vec2 lhs, const vec2 &rhs)
Definition Geometry.h:37
vec2()
Definition Geometry.h:23
vec2 & operator-=(const vec2 &rhs)
Definition Geometry.h:57
friend vec2 operator+(vec2 lhs, const vec2 &rhs)
Definition Geometry.h:35
friend vec2 operator*(vec2 lhs, const vec2 &rhs)
Definition Geometry.h:39
friend vec2 normalize(const vec2 &a)
Definition Geometry.h:143
vec2(float x, float y)
Definition Geometry.h:25
vec2 & operator*=(const vec2 &rhs)
Definition Geometry.h:63
friend vec2 clamp(const vec2 &x, const vec2 &minVal, const vec2 &maxVal)
Definition Geometry.h:117
friend vec2 max_(const vec2 &a, const vec2 &b)
Definition Geometry.h:112
friend vec2 operator/(vec2 lhs, float rhs)
Definition Geometry.h:49
friend bool operator==(const vec2 &a, const vec2 &b)
Definition Geometry.h:99
float y
Definition Geometry.h:21
friend bool operator!=(const vec2 &a, const vec2 &b)
Definition Geometry.h:103
friend vec2 operator+(vec2 lhs, float rhs)
Definition Geometry.h:43
friend vec2 operator*(vec2 lhs, float rhs)
Definition Geometry.h:47
friend vec2 min_(const vec2 &a, const vec2 &b)
Definition Geometry.h:107
vec2 & operator*=(float rhs)
Definition Geometry.h:87
friend vec2 operator/(vec2 lhs, const vec2 &rhs)
Definition Geometry.h:41
float x
Definition Geometry.h:21
vec2 & operator-=(float rhs)
Definition Geometry.h:81
friend vec2 operator-(vec2 lhs, float rhs)
Definition Geometry.h:45
friend float length(const vec2 &a)
Definition Geometry.h:125
vec2(float x)
Definition Geometry.h:27
3D Vector Helper
Definition Geometry.h:155
friend float distance(const vec3 &a, const vec3 &b)
Definition Geometry.h:267
vec3 & operator/=(float rhs)
Definition Geometry.h:229
friend float length(const vec3 &a)
Definition Geometry.h:263
friend vec3 operator/(vec3 lhs, float rhs)
Definition Geometry.h:178
vec3 & operator*=(float rhs)
Definition Geometry.h:222
friend vec3 operator/(vec3 lhs, const vec3 &rhs)
Definition Geometry.h:170
friend vec3 operator*(vec3 lhs, float rhs)
Definition Geometry.h:176
vec3 & operator*=(const vec3 &rhs)
Definition Geometry.h:194
friend vec3 operator+(vec3 lhs, const vec3 &rhs)
Definition Geometry.h:164
vec3 & operator/=(const vec3 &rhs)
Definition Geometry.h:201
friend vec3 max_(const vec3 &a, const vec3 &b)
Definition Geometry.h:250
vec3 & operator+=(const vec3 &rhs)
Definition Geometry.h:180
vec3 & operator+=(float rhs)
Definition Geometry.h:208
vec3(float x, float y, float z)
Definition Geometry.h:160
friend vec3 normalize(const vec3 &a)
Definition Geometry.h:271
friend vec3 operator-(vec3 lhs, const vec3 &rhs)
Definition Geometry.h:166
friend vec3 operator-(vec3 lhs, float rhs)
Definition Geometry.h:174
friend vec3 operator*(vec3 lhs, const vec3 &rhs)
Definition Geometry.h:168
friend vec3 mix(const vec3 &a, const vec3 &b, float t)
Definition Geometry.h:259
float y
Definition Geometry.h:156
friend vec3 clamp(const vec3 &x, const vec3 &minVal, const vec3 &maxVal)
Definition Geometry.h:255
vec3 & operator-=(const vec3 &rhs)
Definition Geometry.h:187
vec3 & operator-=(float rhs)
Definition Geometry.h:215
friend bool operator!=(const vec3 &a, const vec3 &b)
Definition Geometry.h:240
vec3(float x)
Definition Geometry.h:162
float x
Definition Geometry.h:156
friend float dot(const vec3 &a, const vec3 &b)
Definition Geometry.h:275
friend bool operator==(const vec3 &a, const vec3 &b)
Definition Geometry.h:236
friend vec3 min_(const vec3 &a, const vec3 &b)
Definition Geometry.h:244
friend vec3 operator+(vec3 lhs, float rhs)
Definition Geometry.h:172
float z
Definition Geometry.h:156
vec3()
Definition Geometry.h:158
4D Vector Helper
Definition Geometry.h:283
vec4(float x)
Definition Geometry.h:290
void load(const float *val)
Definition Geometry.h:396
vec4()
Definition Geometry.h:286
vec4 & operator+=(const vec4 &rhs)
Definition Geometry.h:318
void store(float *val) const
Definition Geometry.h:403
vec4 & operator*=(const vec4 &rhs)
Definition Geometry.h:334
vec4 & operator-=(const vec4 &rhs)
Definition Geometry.h:326
vec4 & operator+=(float rhs)
Definition Geometry.h:350
friend vec4 operator-(vec4 lhs, float rhs)
Definition Geometry.h:312
vec4(const float val[4])
Definition Geometry.h:292
vec4 & operator*=(float rhs)
Definition Geometry.h:366
float w
Definition Geometry.h:284
friend vec4 operator/(vec4 lhs, float rhs)
Definition Geometry.h:316
vec4 & operator/=(float rhs)
Definition Geometry.h:374
friend vec4 min_(const vec4 &a, const vec4 &b)
Definition Geometry.h:382
vec4(float x, float y, float z, float w)
Definition Geometry.h:288
friend vec4 operator-(vec4 lhs, const vec4 &rhs)
Definition Geometry.h:304
friend vec4 operator*(vec4 lhs, const vec4 &rhs)
Definition Geometry.h:306
friend vec4 operator+(vec4 lhs, const vec4 &rhs)
Definition Geometry.h:302
float y
Definition Geometry.h:284
friend vec4 operator/(vec4 lhs, const vec4 &rhs)
Definition Geometry.h:308
vec4 & operator/=(const vec4 &rhs)
Definition Geometry.h:342
vec4 & operator-=(float rhs)
Definition Geometry.h:358
friend bool operator==(const vec4 &a, const vec4 &b)
Definition Geometry.h:294
float x
Definition Geometry.h:284
friend vec4 operator+(vec4 lhs, float rhs)
Definition Geometry.h:310
friend bool operator!=(const vec4 &a, const vec4 &b)
Definition Geometry.h:298
friend vec4 max_(const vec4 &a, const vec4 &b)
Definition Geometry.h:389
float z
Definition Geometry.h:284
friend vec4 operator*(vec4 lhs, float rhs)
Definition Geometry.h:314