1use crate::{Matrix, Quaternion, Vector2, Vector3, Vector4};
2
3impl Vector2 {
6 pub const ZERO: Self = Self { x: 0.0, y: 0.0 };
8 pub const ONE: Self = Self { x: 1.0, y: 1.0 };
10
11 #[inline]
13 pub fn new(x: f32, y: f32) -> Self {
14 Self { x, y }
15 }
16
17 #[inline]
19 #[must_use]
20 pub fn zero() -> Self {
21 unsafe { crate::Vector2Zero() }
23 }
24
25 #[inline]
27 #[must_use]
28 pub fn one() -> Self {
29 unsafe { crate::Vector2One() }
31 }
32
33 #[inline]
35 #[must_use]
36 pub fn add_value(self, add: f32) -> Self {
37 unsafe { crate::Vector2AddValue(self, add) }
39 }
40
41 #[inline]
43 #[must_use]
44 pub fn sub_value(self, sub: f32) -> Self {
45 unsafe { crate::Vector2SubtractValue(self, sub) }
47 }
48
49 #[inline]
51 #[must_use]
52 pub fn length(self) -> f32 {
53 unsafe { crate::Vector2Length(self) }
55 }
56
57 #[inline]
59 #[must_use]
60 pub fn length_sqr(self) -> f32 {
61 unsafe { crate::Vector2LengthSqr(self) }
63 }
64
65 #[inline]
67 #[must_use]
68 pub fn dot(self, other: Vector2) -> f32 {
69 unsafe { crate::Vector2DotProduct(self, other) }
71 }
72
73 #[inline]
75 #[must_use]
76 pub fn cross(self, other: Vector2) -> f32 {
77 unsafe { crate::Vector2CrossProduct(self, other) }
79 }
80
81 #[inline]
83 #[must_use]
84 pub fn distance(self, other: Vector2) -> f32 {
85 unsafe { crate::Vector2Distance(self, other) }
87 }
88
89 #[inline]
91 #[must_use]
92 pub fn distance_sqr(self, other: Vector2) -> f32 {
93 unsafe { crate::Vector2DistanceSqr(self, other) }
95 }
96
97 #[inline]
99 #[must_use]
100 pub fn angle(self, other: Vector2) -> f32 {
101 unsafe { crate::Vector2Angle(self, other) }
103 }
104
105 #[inline]
107 #[must_use]
108 pub fn line_angle(start: Vector2, end: Vector2) -> f32 {
109 unsafe { crate::Vector2LineAngle(start, end) }
111 }
112
113 #[inline]
115 #[must_use]
116 pub fn scale(self, scale: f32) -> Self {
117 unsafe { crate::Vector2Scale(self, scale) }
119 }
120
121 #[inline]
123 #[must_use]
124 pub fn multiply(self, other: Vector2) -> Self {
125 unsafe { crate::Vector2Multiply(self, other) }
127 }
128
129 #[inline]
131 #[must_use]
132 pub fn negate(self) -> Self {
133 unsafe { crate::Vector2Negate(self) }
135 }
136
137 #[inline]
139 #[must_use]
140 pub fn divide(self, other: Vector2) -> Self {
141 unsafe { crate::Vector2Divide(self, other) }
143 }
144
145 #[inline]
147 #[must_use]
148 pub fn normalize(self) -> Self {
149 unsafe { crate::Vector2Normalize(self) }
151 }
152
153 #[inline]
155 #[must_use]
156 pub fn transform(self, mat: Matrix) -> Self {
157 unsafe { crate::Vector2Transform(self, mat) }
159 }
160
161 #[inline]
163 #[must_use]
164 pub fn lerp(self, other: Vector2, amount: f32) -> Self {
165 unsafe { crate::Vector2Lerp(self, other, amount) }
167 }
168
169 #[inline]
171 #[must_use]
172 pub fn reflect(self, normal: Vector2) -> Self {
173 unsafe { crate::Vector2Reflect(self, normal) }
175 }
176
177 #[inline]
179 #[must_use]
180 pub fn min(self, other: Vector2) -> Self {
181 unsafe { crate::Vector2Min(self, other) }
183 }
184
185 #[inline]
187 #[must_use]
188 pub fn max(self, other: Vector2) -> Self {
189 unsafe { crate::Vector2Max(self, other) }
191 }
192
193 #[inline]
195 #[must_use]
196 pub fn rotate(self, angle: f32) -> Self {
197 unsafe { crate::Vector2Rotate(self, angle) }
199 }
200
201 #[inline]
203 #[must_use]
204 pub fn move_towards(self, target: Vector2, max_distance: f32) -> Self {
205 unsafe { crate::Vector2MoveTowards(self, target, max_distance) }
207 }
208
209 #[inline]
211 #[must_use]
212 pub fn invert(self) -> Self {
213 unsafe { crate::Vector2Invert(self) }
215 }
216
217 #[inline]
219 #[must_use]
220 pub fn clamp(self, min: Vector2, max: Vector2) -> Self {
221 unsafe { crate::Vector2Clamp(self, min, max) }
223 }
224
225 #[inline]
227 #[must_use]
228 pub fn clamp_value(self, min: f32, max: f32) -> Self {
229 unsafe { crate::Vector2ClampValue(self, min, max) }
231 }
232
233 #[inline]
235 #[must_use]
236 pub fn equals(self, other: Vector2) -> bool {
237 unsafe { crate::Vector2Equals(self, other) != 0 }
239 }
240
241 #[inline]
243 #[must_use]
244 pub fn refract(self, n: Vector2, r: f32) -> Self {
245 unsafe { crate::Vector2Refract(self, n, r) }
247 }
248}
249
250impl From<(f32, f32)> for Vector2 {
251 #[inline]
253 fn from((x, y): (f32, f32)) -> Self {
254 Vector2 { x, y }
255 }
256}
257impl From<[f32; 2]> for Vector2 {
258 #[inline]
260 fn from([x, y]: [f32; 2]) -> Self {
261 Vector2 { x, y }
262 }
263}
264
265impl core::ops::Add for Vector2 {
266 type Output = Vector2;
267 #[inline]
268 fn add(self, rhs: Vector2) -> Vector2 {
269 unsafe { crate::Vector2Add(self, rhs) }
271 }
272}
273impl core::ops::AddAssign for Vector2 {
274 #[inline]
275 fn add_assign(&mut self, rhs: Vector2) {
276 *self = *self + rhs;
277 }
278}
279
280impl core::ops::Sub for Vector2 {
281 type Output = Vector2;
282 #[inline]
283 fn sub(self, rhs: Vector2) -> Vector2 {
284 unsafe { crate::Vector2Subtract(self, rhs) }
286 }
287}
288impl core::ops::SubAssign for Vector2 {
289 #[inline]
290 fn sub_assign(&mut self, rhs: Vector2) {
291 *self = *self - rhs;
292 }
293}
294
295impl core::ops::Mul<f32> for Vector2 {
296 type Output = Vector2;
297 #[inline]
298 fn mul(self, rhs: f32) -> Vector2 {
299 unsafe { crate::Vector2Scale(self, rhs) }
301 }
302}
303impl core::ops::MulAssign<f32> for Vector2 {
304 #[inline]
305 fn mul_assign(&mut self, rhs: f32) {
306 *self = *self * rhs;
307 }
308}
309
310impl core::ops::Mul<Vector2> for Vector2 {
311 type Output = Vector2;
312 #[inline]
313 fn mul(self, rhs: Vector2) -> Vector2 {
314 unsafe { crate::Vector2Multiply(self, rhs) }
316 }
317}
318
319impl core::ops::Div<Vector2> for Vector2 {
320 type Output = Vector2;
321 #[inline]
322 fn div(self, rhs: Vector2) -> Vector2 {
323 unsafe { crate::Vector2Divide(self, rhs) }
325 }
326}
327
328impl core::ops::Neg for Vector2 {
329 type Output = Vector2;
330 #[inline]
331 fn neg(self) -> Vector2 {
332 unsafe { crate::Vector2Negate(self) }
334 }
335}
336
337impl Vector3 {
340 pub const ZERO: Self = Self {
342 x: 0.0,
343 y: 0.0,
344 z: 0.0,
345 };
346 pub const ONE: Self = Self {
348 x: 1.0,
349 y: 1.0,
350 z: 1.0,
351 };
352 pub const X: Self = Self {
354 x: 1.0,
355 y: 0.0,
356 z: 0.0,
357 };
358 pub const Y: Self = Self {
360 x: 0.0,
361 y: 1.0,
362 z: 0.0,
363 };
364 pub const Z: Self = Self {
366 x: 0.0,
367 y: 0.0,
368 z: 1.0,
369 };
370
371 #[inline]
373 pub fn new(x: f32, y: f32, z: f32) -> Self {
374 Self { x, y, z }
375 }
376
377 #[inline]
379 #[must_use]
380 pub fn zero() -> Self {
381 unsafe { crate::Vector3Zero() }
383 }
384
385 #[inline]
387 #[must_use]
388 pub fn one() -> Self {
389 unsafe { crate::Vector3One() }
391 }
392
393 #[inline]
395 #[must_use]
396 pub fn add_value(self, add: f32) -> Self {
397 unsafe { crate::Vector3AddValue(self, add) }
399 }
400
401 #[inline]
403 #[must_use]
404 pub fn sub_value(self, sub: f32) -> Self {
405 unsafe { crate::Vector3SubtractValue(self, sub) }
407 }
408
409 #[inline]
411 #[must_use]
412 pub fn scale(self, scalar: f32) -> Self {
413 unsafe { crate::Vector3Scale(self, scalar) }
415 }
416
417 #[inline]
419 #[must_use]
420 pub fn multiply(self, other: Vector3) -> Self {
421 unsafe { crate::Vector3Multiply(self, other) }
423 }
424
425 #[inline]
427 #[must_use]
428 pub fn cross(self, other: Vector3) -> Self {
429 unsafe { crate::Vector3CrossProduct(self, other) }
431 }
432
433 #[inline]
435 #[must_use]
436 pub fn perpendicular(self) -> Self {
437 unsafe { crate::Vector3Perpendicular(self) }
439 }
440
441 #[inline]
443 #[must_use]
444 pub fn length(self) -> f32 {
445 unsafe { crate::Vector3Length(self) }
447 }
448
449 #[inline]
451 #[must_use]
452 pub fn length_sqr(self) -> f32 {
453 unsafe { crate::Vector3LengthSqr(self) }
455 }
456
457 #[inline]
459 #[must_use]
460 pub fn dot(self, other: Vector3) -> f32 {
461 unsafe { crate::Vector3DotProduct(self, other) }
463 }
464
465 #[inline]
467 #[must_use]
468 pub fn distance(self, other: Vector3) -> f32 {
469 unsafe { crate::Vector3Distance(self, other) }
471 }
472
473 #[inline]
475 #[must_use]
476 pub fn distance_sqr(self, other: Vector3) -> f32 {
477 unsafe { crate::Vector3DistanceSqr(self, other) }
479 }
480
481 #[inline]
483 #[must_use]
484 pub fn angle(self, other: Vector3) -> f32 {
485 unsafe { crate::Vector3Angle(self, other) }
487 }
488
489 #[inline]
491 #[must_use]
492 pub fn negate(self) -> Self {
493 unsafe { crate::Vector3Negate(self) }
495 }
496
497 #[inline]
499 #[must_use]
500 pub fn divide(self, other: Vector3) -> Self {
501 unsafe { crate::Vector3Divide(self, other) }
503 }
504
505 #[inline]
507 #[must_use]
508 pub fn normalize(self) -> Self {
509 unsafe { crate::Vector3Normalize(self) }
511 }
512
513 #[inline]
515 #[must_use]
516 pub fn project(self, other: Vector3) -> Self {
517 unsafe { crate::Vector3Project(self, other) }
519 }
520
521 #[inline]
523 #[must_use]
524 pub fn reject(self, other: Vector3) -> Self {
525 unsafe { crate::Vector3Reject(self, other) }
527 }
528
529 #[inline]
531 #[must_use]
532 pub fn transform(self, mat: Matrix) -> Self {
533 unsafe { crate::Vector3Transform(self, mat) }
535 }
536
537 #[inline]
539 #[must_use]
540 pub fn rotate_by_quaternion(self, q: Quaternion) -> Self {
541 unsafe { crate::Vector3RotateByQuaternion(self, q) }
543 }
544
545 #[inline]
547 #[must_use]
548 pub fn rotate_by_axis_angle(self, axis: Vector3, angle: f32) -> Self {
549 unsafe { crate::Vector3RotateByAxisAngle(self, axis, angle) }
551 }
552
553 #[inline]
555 #[must_use]
556 pub fn move_towards(self, target: Vector3, max_distance: f32) -> Self {
557 unsafe { crate::Vector3MoveTowards(self, target, max_distance) }
559 }
560
561 #[inline]
563 #[must_use]
564 pub fn lerp(self, other: Vector3, amount: f32) -> Self {
565 unsafe { crate::Vector3Lerp(self, other, amount) }
567 }
568
569 #[inline]
571 #[must_use]
572 pub fn cubic_hermite(
573 self,
574 tangent1: Vector3,
575 v2: Vector3,
576 tangent2: Vector3,
577 amount: f32,
578 ) -> Self {
579 unsafe { crate::Vector3CubicHermite(self, tangent1, v2, tangent2, amount) }
581 }
582
583 #[inline]
585 #[must_use]
586 pub fn reflect(self, normal: Vector3) -> Self {
587 unsafe { crate::Vector3Reflect(self, normal) }
589 }
590
591 #[inline]
593 #[must_use]
594 pub fn min(self, other: Vector3) -> Self {
595 unsafe { crate::Vector3Min(self, other) }
597 }
598
599 #[inline]
601 #[must_use]
602 pub fn max(self, other: Vector3) -> Self {
603 unsafe { crate::Vector3Max(self, other) }
605 }
606
607 #[inline]
609 #[must_use]
610 pub fn barycenter(p: Vector3, a: Vector3, b: Vector3, c: Vector3) -> Self {
611 unsafe { crate::Vector3Barycenter(p, a, b, c) }
613 }
614
615 #[inline]
617 #[must_use]
618 pub fn unproject(self, projection: Matrix, view: Matrix) -> Self {
619 unsafe { crate::Vector3Unproject(self, projection, view) }
621 }
622
623 #[inline]
625 #[must_use]
626 pub fn to_float_array(self) -> crate::float3 {
627 unsafe { crate::Vector3ToFloatV(self) }
629 }
630
631 #[inline]
633 #[must_use]
634 pub fn invert(self) -> Self {
635 unsafe { crate::Vector3Invert(self) }
637 }
638
639 #[inline]
641 #[must_use]
642 pub fn clamp(self, min: Vector3, max: Vector3) -> Self {
643 unsafe { crate::Vector3Clamp(self, min, max) }
645 }
646
647 #[inline]
649 #[must_use]
650 pub fn clamp_value(self, min: f32, max: f32) -> Self {
651 unsafe { crate::Vector3ClampValue(self, min, max) }
653 }
654
655 #[inline]
657 #[must_use]
658 pub fn equals(self, other: Vector3) -> bool {
659 unsafe { crate::Vector3Equals(self, other) != 0 }
661 }
662
663 #[inline]
665 #[must_use]
666 pub fn refract(self, n: Vector3, r: f32) -> Self {
667 unsafe { crate::Vector3Refract(self, n, r) }
669 }
670}
671
672pub fn vector3_ortho_normalize(v1: &mut Vector3, v2: &mut Vector3) {
674 unsafe { crate::Vector3OrthoNormalize(v1 as *mut _, v2 as *mut _) }
678}
679
680impl From<(f32, f32, f32)> for Vector3 {
681 #[inline]
683 fn from((x, y, z): (f32, f32, f32)) -> Self {
684 Vector3 { x, y, z }
685 }
686}
687impl From<[f32; 3]> for Vector3 {
688 #[inline]
690 fn from([x, y, z]: [f32; 3]) -> Self {
691 Vector3 { x, y, z }
692 }
693}
694
695impl core::ops::Add for Vector3 {
696 type Output = Vector3;
697 #[inline]
698 fn add(self, rhs: Vector3) -> Vector3 {
699 unsafe { crate::Vector3Add(self, rhs) }
701 }
702}
703impl core::ops::AddAssign for Vector3 {
704 #[inline]
705 fn add_assign(&mut self, rhs: Vector3) {
706 *self = *self + rhs;
707 }
708}
709
710impl core::ops::Sub for Vector3 {
711 type Output = Vector3;
712 #[inline]
713 fn sub(self, rhs: Vector3) -> Vector3 {
714 unsafe { crate::Vector3Subtract(self, rhs) }
716 }
717}
718impl core::ops::SubAssign for Vector3 {
719 #[inline]
720 fn sub_assign(&mut self, rhs: Vector3) {
721 *self = *self - rhs;
722 }
723}
724
725impl core::ops::Mul<f32> for Vector3 {
726 type Output = Vector3;
727 #[inline]
728 fn mul(self, rhs: f32) -> Vector3 {
729 unsafe { crate::Vector3Scale(self, rhs) }
731 }
732}
733impl core::ops::MulAssign<f32> for Vector3 {
734 #[inline]
735 fn mul_assign(&mut self, rhs: f32) {
736 *self = *self * rhs;
737 }
738}
739
740impl core::ops::Mul<Vector3> for Vector3 {
741 type Output = Vector3;
742 #[inline]
743 fn mul(self, rhs: Vector3) -> Vector3 {
744 unsafe { crate::Vector3Multiply(self, rhs) }
746 }
747}
748
749impl core::ops::Div<Vector3> for Vector3 {
750 type Output = Vector3;
751 #[inline]
752 fn div(self, rhs: Vector3) -> Vector3 {
753 unsafe { crate::Vector3Divide(self, rhs) }
755 }
756}
757
758impl core::ops::Neg for Vector3 {
759 type Output = Vector3;
760 #[inline]
761 fn neg(self) -> Vector3 {
762 unsafe { crate::Vector3Negate(self) }
764 }
765}
766
767impl Vector4 {
770 #[inline]
772 pub fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
773 Self { x, y, z, w }
774 }
775
776 #[inline]
778 #[must_use]
779 pub fn zero() -> Self {
780 unsafe { crate::Vector4Zero() }
782 }
783
784 #[inline]
786 #[must_use]
787 pub fn one() -> Self {
788 unsafe { crate::Vector4One() }
790 }
791
792 #[inline]
794 #[must_use]
795 pub fn add_value(self, add: f32) -> Self {
796 unsafe { crate::Vector4AddValue(self, add) }
798 }
799
800 #[inline]
802 #[must_use]
803 pub fn sub_value(self, sub: f32) -> Self {
804 unsafe { crate::Vector4SubtractValue(self, sub) }
806 }
807
808 #[inline]
810 #[must_use]
811 pub fn length(self) -> f32 {
812 unsafe { crate::Vector4Length(self) }
814 }
815
816 #[inline]
818 #[must_use]
819 pub fn length_sqr(self) -> f32 {
820 unsafe { crate::Vector4LengthSqr(self) }
822 }
823
824 #[inline]
826 #[must_use]
827 pub fn dot(self, other: Vector4) -> f32 {
828 unsafe { crate::Vector4DotProduct(self, other) }
830 }
831
832 #[inline]
834 #[must_use]
835 pub fn distance(self, other: Vector4) -> f32 {
836 unsafe { crate::Vector4Distance(self, other) }
838 }
839
840 #[inline]
842 #[must_use]
843 pub fn distance_sqr(self, other: Vector4) -> f32 {
844 unsafe { crate::Vector4DistanceSqr(self, other) }
846 }
847
848 #[inline]
850 #[must_use]
851 pub fn scale(self, scale: f32) -> Self {
852 unsafe { crate::Vector4Scale(self, scale) }
854 }
855
856 #[inline]
858 #[must_use]
859 pub fn multiply(self, other: Vector4) -> Self {
860 unsafe { crate::Vector4Multiply(self, other) }
862 }
863
864 #[inline]
866 #[must_use]
867 pub fn negate(self) -> Self {
868 unsafe { crate::Vector4Negate(self) }
870 }
871
872 #[inline]
874 #[must_use]
875 pub fn divide(self, other: Vector4) -> Self {
876 unsafe { crate::Vector4Divide(self, other) }
878 }
879
880 #[inline]
882 #[must_use]
883 pub fn normalize(self) -> Self {
884 unsafe { crate::Vector4Normalize(self) }
886 }
887
888 #[inline]
890 #[must_use]
891 pub fn min(self, other: Vector4) -> Self {
892 unsafe { crate::Vector4Min(self, other) }
894 }
895
896 #[inline]
898 #[must_use]
899 pub fn max(self, other: Vector4) -> Self {
900 unsafe { crate::Vector4Max(self, other) }
902 }
903
904 #[inline]
906 #[must_use]
907 pub fn lerp(self, other: Vector4, amount: f32) -> Self {
908 unsafe { crate::Vector4Lerp(self, other, amount) }
910 }
911
912 #[inline]
914 #[must_use]
915 pub fn move_towards(self, target: Vector4, max_distance: f32) -> Self {
916 unsafe { crate::Vector4MoveTowards(self, target, max_distance) }
918 }
919
920 #[inline]
922 #[must_use]
923 pub fn invert(self) -> Self {
924 unsafe { crate::Vector4Invert(self) }
926 }
927
928 #[inline]
930 #[must_use]
931 pub fn equals(self, other: Vector4) -> bool {
932 unsafe { crate::Vector4Equals(self, other) != 0 }
934 }
935}
936
937impl From<(f32, f32, f32, f32)> for Vector4 {
938 #[inline]
940 fn from((x, y, z, w): (f32, f32, f32, f32)) -> Self {
941 Vector4 { x, y, z, w }
942 }
943}
944impl From<[f32; 4]> for Vector4 {
945 #[inline]
947 fn from([x, y, z, w]: [f32; 4]) -> Self {
948 Vector4 { x, y, z, w }
949 }
950}
951
952impl core::ops::Add for Vector4 {
953 type Output = Vector4;
954 #[inline]
955 fn add(self, rhs: Vector4) -> Vector4 {
956 unsafe { crate::Vector4Add(self, rhs) }
958 }
959}
960impl core::ops::AddAssign for Vector4 {
961 #[inline]
962 fn add_assign(&mut self, rhs: Vector4) {
963 *self = *self + rhs;
964 }
965}
966
967impl core::ops::Sub for Vector4 {
968 type Output = Vector4;
969 #[inline]
970 fn sub(self, rhs: Vector4) -> Vector4 {
971 unsafe { crate::Vector4Subtract(self, rhs) }
973 }
974}
975impl core::ops::SubAssign for Vector4 {
976 #[inline]
977 fn sub_assign(&mut self, rhs: Vector4) {
978 *self = *self - rhs;
979 }
980}
981
982impl core::ops::Mul<f32> for Vector4 {
983 type Output = Vector4;
984 #[inline]
985 fn mul(self, rhs: f32) -> Vector4 {
986 unsafe { crate::Vector4Scale(self, rhs) }
988 }
989}
990impl core::ops::MulAssign<f32> for Vector4 {
991 #[inline]
992 fn mul_assign(&mut self, rhs: f32) {
993 *self = *self * rhs;
994 }
995}
996
997impl core::ops::Mul<Vector4> for Vector4 {
998 type Output = Vector4;
999 #[inline]
1000 fn mul(self, rhs: Vector4) -> Vector4 {
1001 unsafe { crate::Vector4Multiply(self, rhs) }
1003 }
1004}
1005
1006impl core::ops::Div<Vector4> for Vector4 {
1007 type Output = Vector4;
1008 #[inline]
1009 fn div(self, rhs: Vector4) -> Vector4 {
1010 unsafe { crate::Vector4Divide(self, rhs) }
1012 }
1013}
1014
1015impl core::ops::Neg for Vector4 {
1016 type Output = Vector4;
1017 #[inline]
1018 fn neg(self) -> Vector4 {
1019 unsafe { crate::Vector4Negate(self) }
1021 }
1022}