1use std::{fmt, ops};
4
5use glib::translate::*;
6
7use crate::{ffi, Vec3};
8
9impl Vec3 {
10 #[doc(alias = "graphene_vec3_init")]
11 pub fn new(x: f32, y: f32, z: f32) -> Self {
12 assert_initialized_main_thread!();
13 unsafe {
14 let mut vec = Self::uninitialized();
15 ffi::graphene_vec3_init(vec.to_glib_none_mut().0, x, y, z);
16 vec
17 }
18 }
19
20 #[doc(alias = "graphene_vec3_init_from_float")]
21 #[doc(alias = "init_from_float")]
22 pub fn from_float(src: [f32; 3]) -> Self {
23 assert_initialized_main_thread!();
24 unsafe {
25 let mut vec = Self::uninitialized();
26 ffi::graphene_vec3_init_from_float(vec.to_glib_none_mut().0, src.as_ptr() as *const _);
27 vec
28 }
29 }
30
31 #[doc(alias = "graphene_vec3_to_float")]
32 pub fn to_float(&self) -> [f32; 3] {
33 unsafe {
34 let mut out = std::mem::MaybeUninit::uninit();
35 ffi::graphene_vec3_to_float(self.to_glib_none().0, out.as_mut_ptr());
36 out.assume_init()
37 }
38 }
39}
40
41impl fmt::Debug for Vec3 {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 f.debug_struct("Vec3")
44 .field("x", &self.x())
45 .field("y", &self.y())
46 .field("z", &self.z())
47 .finish()
48 }
49}
50
51impl Default for Vec3 {
52 fn default() -> Self {
53 Self::zero()
54 }
55}
56
57impl ops::Add<Vec3> for Vec3 {
59 type Output = Vec3;
60
61 fn add(self, rhs: Vec3) -> Self::Output {
62 Vec3::add(&self, &rhs)
63 }
64}
65impl ops::AddAssign<Vec3> for Vec3 {
66 fn add_assign(&mut self, rhs: Vec3) {
67 *self = *self + rhs;
68 }
69}
70impl ops::Sub<Vec3> for Vec3 {
71 type Output = Vec3;
72
73 fn sub(self, rhs: Vec3) -> Self::Output {
74 Vec3::subtract(&self, &rhs)
75 }
76}
77impl ops::SubAssign<Vec3> for Vec3 {
78 fn sub_assign(&mut self, rhs: Vec3) {
79 *self = *self - rhs;
80 }
81}
82impl ops::Neg for Vec3 {
83 type Output = Vec3;
84
85 fn neg(self) -> Self::Output {
86 Vec3::negate(&self)
87 }
88}
89
90impl ops::Mul<f32> for Vec3 {
92 type Output = Vec3;
93
94 fn mul(self, rhs: f32) -> Self::Output {
95 Vec3::scale(&self, rhs)
96 }
97}
98impl ops::MulAssign<f32> for Vec3 {
99 fn mul_assign(&mut self, rhs: f32) {
100 *self = *self * rhs;
101 }
102}
103impl ops::Mul<Vec3> for f32 {
104 type Output = Vec3;
105
106 fn mul(self, rhs: Vec3) -> Self::Output {
107 rhs * self
108 }
109}
110
111impl ops::Mul<Vec3> for Vec3 {
113 type Output = Vec3;
114
115 fn mul(self, rhs: Vec3) -> Self::Output {
116 Vec3::multiply(&self, &rhs)
117 }
118}
119impl ops::MulAssign<Vec3> for Vec3 {
120 fn mul_assign(&mut self, rhs: Vec3) {
121 *self = *self * rhs;
122 }
123}
124impl ops::Div<Vec3> for Vec3 {
125 type Output = Vec3;
126
127 fn div(self, rhs: Vec3) -> Self::Output {
128 Vec3::divide(&self, &rhs)
129 }
130}
131impl ops::DivAssign<Vec3> for Vec3 {
132 fn div_assign(&mut self, rhs: Vec3) {
133 *self = *self / rhs;
134 }
135}