1use std::{fmt, ops};
4
5use glib::translate::*;
6
7use crate::{ffi, Vec2, Vec3, Vec4};
8
9impl Vec4 {
10 #[doc(alias = "graphene_vec4_init")]
27 pub fn new(x: f32, y: f32, z: f32, w: f32) -> Self {
28 assert_initialized_main_thread!();
29 unsafe {
30 let mut vec = Self::uninitialized();
31 ffi::graphene_vec4_init(vec.to_glib_none_mut().0, x, y, z, w);
32 vec
33 }
34 }
35
36 #[doc(alias = "graphene_vec4_init_from_vec2")]
49 #[doc(alias = "init_from_vec2")]
50 pub fn from_vec2(src: &Vec2, z: f32, w: f32) -> Self {
51 assert_initialized_main_thread!();
52 unsafe {
53 let mut vec = Self::uninitialized();
54 ffi::graphene_vec4_init_from_vec2(vec.to_glib_none_mut().0, src.to_glib_none().0, z, w);
55 vec
56 }
57 }
58
59 #[doc(alias = "graphene_vec4_init_from_vec3")]
70 #[doc(alias = "init_from_vec3")]
71 pub fn from_vec3(src: &Vec3, w: f32) -> Self {
72 assert_initialized_main_thread!();
73 unsafe {
74 let mut vec = Self::uninitialized();
75 ffi::graphene_vec4_init_from_vec3(vec.to_glib_none_mut().0, src.to_glib_none().0, w);
76 vec
77 }
78 }
79
80 #[doc(alias = "graphene_vec4_init_from_float")]
88 #[doc(alias = "init_from_float")]
89 pub fn from_float(src: [f32; 4]) -> Self {
90 assert_initialized_main_thread!();
91 unsafe {
92 let mut vec = Self::uninitialized();
93 ffi::graphene_vec4_init_from_float(vec.to_glib_none_mut().0, src.as_ptr() as *const _);
94 vec
95 }
96 }
97
98 #[doc(alias = "graphene_vec4_to_float")]
108 pub fn to_float(&self) -> [f32; 4] {
109 unsafe {
110 let mut out = std::mem::MaybeUninit::uninit();
111 ffi::graphene_vec4_to_float(self.to_glib_none().0, out.as_mut_ptr());
112 out.assume_init()
113 }
114 }
115}
116
117impl fmt::Debug for Vec4 {
118 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
119 f.debug_struct("Vec4")
120 .field("x", &self.x())
121 .field("y", &self.y())
122 .field("z", &self.z())
123 .field("w", &self.w())
124 .finish()
125 }
126}
127
128impl Default for Vec4 {
129 fn default() -> Self {
130 Self::zero()
131 }
132}
133
134impl ops::Add<Vec4> for Vec4 {
136 type Output = Vec4;
137
138 fn add(self, rhs: Vec4) -> Self::Output {
139 Vec4::add(&self, &rhs)
140 }
141}
142impl ops::AddAssign<Vec4> for Vec4 {
143 fn add_assign(&mut self, rhs: Vec4) {
144 *self = *self + rhs;
145 }
146}
147impl ops::Sub<Vec4> for Vec4 {
148 type Output = Vec4;
149
150 fn sub(self, rhs: Vec4) -> Self::Output {
151 Vec4::subtract(&self, &rhs)
152 }
153}
154impl ops::SubAssign<Vec4> for Vec4 {
155 fn sub_assign(&mut self, rhs: Vec4) {
156 *self = *self - rhs;
157 }
158}
159impl ops::Neg for Vec4 {
160 type Output = Vec4;
161
162 fn neg(self) -> Self::Output {
163 Vec4::negate(&self)
164 }
165}
166
167impl ops::Mul<f32> for Vec4 {
169 type Output = Vec4;
170
171 fn mul(self, rhs: f32) -> Self::Output {
172 Vec4::scale(&self, rhs)
173 }
174}
175impl ops::MulAssign<f32> for Vec4 {
176 fn mul_assign(&mut self, rhs: f32) {
177 *self = *self * rhs;
178 }
179}
180impl ops::Mul<Vec4> for f32 {
181 type Output = Vec4;
182
183 fn mul(self, rhs: Vec4) -> Self::Output {
184 rhs * self
185 }
186}
187
188impl ops::Mul<Vec4> for Vec4 {
190 type Output = Vec4;
191
192 fn mul(self, rhs: Vec4) -> Self::Output {
193 Vec4::multiply(&self, &rhs)
194 }
195}
196impl ops::MulAssign<Vec4> for Vec4 {
197 fn mul_assign(&mut self, rhs: Vec4) {
198 *self = *self * rhs;
199 }
200}
201impl ops::Div<Vec4> for Vec4 {
202 type Output = Vec4;
203
204 fn div(self, rhs: Vec4) -> Self::Output {
205 Vec4::divide(&self, &rhs)
206 }
207}
208impl ops::DivAssign<Vec4> for Vec4 {
209 fn div_assign(&mut self, rhs: Vec4) {
210 *self = *self / rhs;
211 }
212}