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