token_value_map/
data_types.rs

1use crate::{DataTypeOps, *};
2use anyhow::Result;
3use std::{
4    fmt::Debug,
5    hash::{Hash, Hasher},
6    ops::{Add, Div, Mul, Sub},
7};
8
9// Macro to implement DataTypeOps for each variant
10macro_rules! impl_data_ops {
11    ($type:ty, $name:expr, $data_type:expr) => {
12        impl DataTypeOps for $type {
13            fn type_name(&self) -> &'static str {
14                $name
15            }
16
17            fn data_type(&self) -> DataType {
18                $data_type
19            }
20        }
21    };
22}
23
24// AIDEV-NOTE: Macro to reduce duplication for nalgebra-based types.
25// Implements Add, Sub, Mul<f32>, and Mul<f64> for wrapper types.
26macro_rules! impl_nalgebra_arithmetic {
27    // For f32-based types
28    ($type:ty) => {
29        impl Add for $type {
30            type Output = $type;
31
32            fn add(self, other: $type) -> $type {
33                Self(self.0 + other.0)
34            }
35        }
36
37        impl Sub for $type {
38            type Output = $type;
39
40            fn sub(self, other: $type) -> $type {
41                Self(self.0 - other.0)
42            }
43        }
44
45        impl Mul<f32> for $type {
46            type Output = $type;
47
48            fn mul(self, scalar: f32) -> $type {
49                Self(self.0 * scalar)
50            }
51        }
52
53        impl Mul<f64> for $type {
54            type Output = $type;
55
56            fn mul(self, scalar: f64) -> $type {
57                Self(self.0 * scalar as f32)
58            }
59        }
60    };
61
62    // For f64-based types
63    ($type:ty, f64) => {
64        impl Add for $type {
65            type Output = $type;
66
67            fn add(self, other: $type) -> $type {
68                Self(self.0 + other.0)
69            }
70        }
71
72        impl Sub for $type {
73            type Output = $type;
74
75            fn sub(self, other: $type) -> $type {
76                Self(self.0 - other.0)
77            }
78        }
79
80        impl Mul<f32> for $type {
81            type Output = $type;
82
83            fn mul(self, scalar: f32) -> $type {
84                Self(self.0 * scalar as f64)
85            }
86        }
87
88        impl Mul<f64> for $type {
89            type Output = $type;
90
91            fn mul(self, scalar: f64) -> $type {
92                Self(self.0 * scalar)
93            }
94        }
95    };
96}
97
98/// A boolean value wrapper.
99#[derive(Clone, Debug, PartialEq, Eq, Hash)]
100#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
101#[cfg_attr(feature = "facet", derive(Facet))]
102pub struct Boolean(pub bool);
103
104impl From<Data> for Boolean {
105    fn from(data: Data) -> Self {
106        match data {
107            Data::Boolean(b) => b,
108            Data::Real(r) => Boolean(r.0 != 0.0),
109            Data::Integer(i) => Boolean(i.0 != 0),
110            Data::String(s) => Boolean(s.0.parse::<bool>().unwrap_or(false)),
111            _ => panic!("Cannot convert {data:?} to Boolean"),
112        }
113    }
114}
115
116/// A 64-bit signed integer wrapper.
117#[derive(Clone, Debug, PartialEq, Eq, Hash)]
118#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
119#[cfg_attr(feature = "facet", derive(Facet))]
120pub struct Integer(pub i64);
121
122impl From<Data> for Integer {
123    fn from(data: Data) -> Self {
124        match data {
125            Data::Boolean(b) => Integer(if b.0 { 1 } else { 0 }),
126            Data::Real(r) => Integer(r.0 as i64),
127            Data::Integer(i) => i,
128            Data::String(s) => Integer(s.0.parse::<i64>().unwrap_or(0)),
129            _ => panic!("Cannot convert {data:?} to Integer"),
130        }
131    }
132}
133
134/// A 64-bit floating-point number wrapper.
135#[derive(Clone, Debug, PartialEq)]
136#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
137#[cfg_attr(feature = "facet", derive(Facet))]
138pub struct Real(pub f64);
139
140impl Eq for Real {}
141
142impl From<Data> for Real {
143    fn from(data: Data) -> Self {
144        match data {
145            Data::Boolean(b) => Real(if b.0 { 1.0 } else { 0.0 }),
146            Data::Real(r) => r,
147            Data::Integer(i) => Real(i.0 as f64),
148            Data::String(s) => Real(s.0.parse::<f64>().unwrap_or(0.0)),
149            _ => panic!("Cannot convert {data:?} to Real"),
150        }
151    }
152}
153
154impl From<f64> for Real {
155    fn from(value: f64) -> Self {
156        Real(value)
157    }
158}
159
160impl From<f32> for Real {
161    fn from(value: f32) -> Self {
162        Real(value as f64)
163    }
164}
165
166/// A UTF-8 string wrapper.
167#[derive(Clone, Debug, PartialEq, Eq, Hash)]
168#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
169#[cfg_attr(feature = "facet", derive(Facet))]
170pub struct String(pub std::string::String);
171
172impl From<Data> for String {
173    fn from(data: Data) -> Self {
174        match data {
175            Data::Boolean(b) => String(b.0.to_string()),
176            Data::Real(r) => String(r.0.to_string()),
177            Data::Integer(i) => String(i.0.to_string()),
178            Data::String(s) => s,
179            Data::Color(c) => String(format!("{c:?}")),
180            #[cfg(feature = "vector2")]
181            Data::Vector2(v) => String(format!("{v:?}")),
182            #[cfg(feature = "vector3")]
183            Data::Vector3(v) => String(format!("{v:?}")),
184            #[cfg(feature = "matrix3")]
185            Data::Matrix3(m) => String(format!("{m:?}")),
186            #[cfg(feature = "normal3")]
187            Data::Normal3(n) => String(format!("{n:?}")),
188            #[cfg(feature = "point3")]
189            Data::Point3(p) => String(format!("{p:?}")),
190            #[cfg(feature = "matrix4")]
191            Data::Matrix4(m) => String(format!("{m:?}")),
192            Data::BooleanVec(v) => String(format!("{v:?}")),
193            Data::RealVec(v) => String(format!("{v:?}")),
194            Data::IntegerVec(v) => String(format!("{v:?}")),
195            Data::StringVec(v) => String(format!("{v:?}")),
196            Data::ColorVec(v) => String(format!("{v:?}")),
197            #[cfg(all(feature = "vector2", feature = "vec_variants"))]
198            Data::Vector2Vec(v) => String(format!("{v:?}")),
199            #[cfg(all(feature = "vector3", feature = "vec_variants"))]
200            Data::Vector3Vec(v) => String(format!("{v:?}")),
201            #[cfg(all(feature = "matrix3", feature = "vec_variants"))]
202            Data::Matrix3Vec(v) => String(format!("{v:?}")),
203            #[cfg(all(feature = "normal3", feature = "vec_variants"))]
204            Data::Normal3Vec(v) => String(format!("{v:?}")),
205            #[cfg(all(feature = "point3", feature = "vec_variants"))]
206            Data::Point3Vec(v) => String(format!("{v:?}")),
207            #[cfg(all(feature = "matrix4", feature = "vec_variants"))]
208            Data::Matrix4Vec(v) => String(format!("{v:?}")),
209        }
210    }
211}
212
213/// A 4-component RGBA color value.
214#[derive(Clone, Debug, PartialEq)]
215#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
216#[cfg_attr(feature = "facet", derive(Facet))]
217pub struct Color(pub [f32; 4]);
218
219impl Eq for Color {}
220
221impl From<[f32; 4]> for Color {
222    fn from(array: [f32; 4]) -> Self {
223        Color(array)
224    }
225}
226
227impl From<Data> for Color {
228    fn from(data: Data) -> Self {
229        match data {
230            Data::Boolean(b) => Color([b.0.into(), b.0.into(), b.0.into(), 1.0]),
231            Data::Real(r) => Color([r.0 as _, r.0 as _, r.0 as _, 1.0]),
232            Data::Integer(i) => Color([i.0 as _, i.0 as _, i.0 as _, 1.0]),
233            Data::String(s) => Color([s.0.parse::<f32>().unwrap_or(0.0); 4]),
234            Data::Color(c) => c,
235            #[cfg(feature = "vector2")]
236            Data::Vector2(v) => Color([v.0.x, v.0.y, 0.0, 1.0]),
237            #[cfg(feature = "vector3")]
238            Data::Vector3(v) => Color([v.0.x, v.0.y, v.0.z, 1.0]),
239            Data::BooleanVec(v) => Color([v.0[0].into(), v.0[1].into(), v.0[2].into(), 1.0]),
240            Data::RealVec(v) => Color([v.0[0] as _, v.0[1] as _, v.0[2] as _, 1.0]),
241            Data::IntegerVec(v) => Color([v.0[0] as _, v.0[1] as _, v.0[2] as _, 1.0]),
242            Data::StringVec(v) => Color([v.0[0].parse::<f32>().unwrap_or(0.0); 4]),
243            Data::ColorVec(v) => Color([v.0[0][0], v.0[0][1], v.0[0][2], v.0[0][3]]),
244            _ => panic!("Cannot convert {data:?} to Color"),
245        }
246    }
247}
248
249/// A 2D vector.
250#[cfg(feature = "vector2")]
251#[derive(Clone, Debug, PartialEq)]
252#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
253#[cfg_attr(feature = "facet", derive(Facet))]
254#[cfg_attr(feature = "facet", facet(opaque))]
255pub struct Vector2(pub nalgebra::Vector2<f32>);
256
257#[cfg(feature = "vector2")]
258impl Eq for Vector2 {}
259
260/// A 3D vector.
261#[cfg(feature = "vector3")]
262#[derive(Clone, Debug, PartialEq)]
263#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
264#[cfg_attr(feature = "facet", derive(Facet))]
265#[cfg_attr(feature = "facet", facet(opaque))]
266pub struct Vector3(pub nalgebra::Vector3<f32>);
267
268#[cfg(feature = "vector3")]
269impl Eq for Vector3 {}
270
271/// A 3×3 transformation matrix.
272#[cfg(feature = "matrix3")]
273#[derive(Clone, Debug, PartialEq)]
274#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
275#[cfg_attr(feature = "facet", derive(Facet))]
276#[cfg_attr(feature = "facet", facet(opaque))]
277pub struct Matrix3(pub nalgebra::Matrix3<f32>);
278
279#[cfg(feature = "matrix3")]
280impl Eq for Matrix3 {}
281
282#[cfg(feature = "matrix3")]
283impl From<Vec<f32>> for Matrix3 {
284    fn from(vec: Vec<f32>) -> Self {
285        assert_eq!(vec.len(), 9, "Matrix3 requires exactly 9 elements");
286        Matrix3(nalgebra::Matrix3::from_row_slice(&vec))
287    }
288}
289
290#[cfg(feature = "matrix3")]
291impl From<Vec<f64>> for Matrix3 {
292    fn from(vec: Vec<f64>) -> Self {
293        assert_eq!(vec.len(), 9, "Matrix3 requires exactly 9 elements");
294        let vec_f32: Vec<f32> = vec.into_iter().map(|v| v as f32).collect();
295        Matrix3(nalgebra::Matrix3::from_row_slice(&vec_f32))
296    }
297}
298
299#[cfg(feature = "matrix3")]
300impl From<[f32; 9]> for Matrix3 {
301    fn from(arr: [f32; 9]) -> Self {
302        Matrix3(nalgebra::Matrix3::from_row_slice(&arr))
303    }
304}
305
306/// A 3D normal vector.
307#[cfg(feature = "normal3")]
308#[derive(Clone, Debug, PartialEq)]
309#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
310#[cfg_attr(feature = "facet", derive(Facet))]
311#[cfg_attr(feature = "facet", facet(opaque))]
312pub struct Normal3(pub nalgebra::Vector3<f32>);
313
314#[cfg(feature = "normal3")]
315impl Eq for Normal3 {}
316
317/// A 3D point.
318#[cfg(feature = "point3")]
319#[derive(Clone, Debug, PartialEq)]
320#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
321#[cfg_attr(feature = "facet", derive(Facet))]
322#[cfg_attr(feature = "facet", facet(opaque))]
323pub struct Point3(pub nalgebra::Point3<f32>);
324
325#[cfg(feature = "point3")]
326impl Eq for Point3 {}
327
328/// A 4×4 transformation matrix.
329#[cfg(feature = "matrix4")]
330#[derive(Clone, Debug, PartialEq)]
331#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
332#[cfg_attr(feature = "facet", derive(Facet))]
333#[cfg_attr(feature = "facet", facet(opaque))]
334pub struct Matrix4(pub nalgebra::Matrix4<f64>);
335
336#[cfg(feature = "matrix4")]
337impl Eq for Matrix4 {}
338
339/// A vector of integer values.
340#[derive(Clone, Debug, PartialEq, Eq, Hash)]
341#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
342#[cfg_attr(feature = "facet", derive(Facet))]
343pub struct IntegerVec(pub Vec<i64>);
344
345impl IntegerVec {
346    pub fn new(vec: Vec<i64>) -> Result<Self> {
347        if vec.is_empty() {
348            return Err(anyhow!("IntegerVec cannot be empty"));
349        }
350        Ok(IntegerVec(vec))
351    }
352}
353
354impl From<Vec<i64>> for IntegerVec {
355    fn from(vec: Vec<i64>) -> Self {
356        IntegerVec(vec)
357    }
358}
359
360impl From<Vec<i32>> for IntegerVec {
361    fn from(vec: Vec<i32>) -> Self {
362        IntegerVec(vec.into_iter().map(|v| v as i64).collect())
363    }
364}
365
366/// A vector of real values.
367#[derive(Clone, Debug, PartialEq)]
368#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
369#[cfg_attr(feature = "facet", derive(Facet))]
370pub struct RealVec(pub Vec<f64>);
371
372impl RealVec {
373    pub fn new(vec: Vec<f64>) -> Result<Self> {
374        if vec.is_empty() {
375            return Err(anyhow!("RealVec cannot be empty"));
376        }
377        Ok(RealVec(vec))
378    }
379}
380
381impl From<Vec<f64>> for RealVec {
382    fn from(vec: Vec<f64>) -> Self {
383        RealVec(vec)
384    }
385}
386
387impl From<Vec<f32>> for RealVec {
388    fn from(vec: Vec<f32>) -> Self {
389        RealVec(vec.into_iter().map(|v| v as f64).collect())
390    }
391}
392
393impl Eq for RealVec {}
394
395/// A vector of boolean values.
396#[derive(Clone, Debug, PartialEq, Eq, Hash)]
397#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
398#[cfg_attr(feature = "facet", derive(Facet))]
399pub struct BooleanVec(pub Vec<bool>);
400
401impl BooleanVec {
402    pub fn new(vec: Vec<bool>) -> Result<Self> {
403        if vec.is_empty() {
404            return Err(anyhow!("BooleanVec cannot be empty"));
405        }
406        Ok(BooleanVec(vec))
407    }
408}
409
410/// A vector of string values.
411#[derive(Clone, Debug, PartialEq, Eq, Hash)]
412#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
413#[cfg_attr(feature = "facet", derive(Facet))]
414pub struct StringVec(pub Vec<std::string::String>);
415
416impl StringVec {
417    pub fn new(vec: Vec<std::string::String>) -> Result<Self> {
418        if vec.is_empty() {
419            return Err(anyhow!("StringVec cannot be empty"));
420        }
421        Ok(StringVec(vec))
422    }
423}
424
425/// A vector of color values.
426#[derive(Clone, Debug, PartialEq)]
427#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
428#[cfg_attr(feature = "facet", derive(Facet))]
429pub struct ColorVec(pub Vec<[f32; 4]>);
430
431impl ColorVec {
432    pub fn new(vec: Vec<[f32; 4]>) -> Result<Self> {
433        if vec.is_empty() {
434            return Err(anyhow!("ColorVec cannot be empty"));
435        }
436        Ok(ColorVec(vec))
437    }
438}
439
440impl Eq for ColorVec {}
441
442/// A vector of 2D vectors.
443#[cfg(all(feature = "vector2", feature = "vec_variants"))]
444#[derive(Clone, Debug, PartialEq)]
445#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
446#[cfg_attr(feature = "facet", derive(Facet))]
447#[cfg_attr(feature = "facet", facet(opaque))]
448pub struct Vector2Vec(pub Vec<nalgebra::Vector2<f32>>);
449
450#[cfg(all(feature = "vector2", feature = "vec_variants"))]
451impl Vector2Vec {
452    pub fn new(vec: Vec<nalgebra::Vector2<f32>>) -> Result<Self> {
453        if vec.is_empty() {
454            return Err(anyhow!("Vector2Vec cannot be empty"));
455        }
456        Ok(Vector2Vec(vec))
457    }
458}
459
460#[cfg(all(feature = "vector2", feature = "vec_variants"))]
461impl Eq for Vector2Vec {}
462
463/// A vector of 3D vectors.
464#[cfg(all(feature = "vector3", feature = "vec_variants"))]
465#[derive(Clone, Debug, PartialEq)]
466#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
467#[cfg_attr(feature = "facet", derive(Facet))]
468#[cfg_attr(feature = "facet", facet(opaque))]
469pub struct Vector3Vec(pub Vec<nalgebra::Vector3<f32>>);
470
471#[cfg(all(feature = "vector3", feature = "vec_variants"))]
472impl Vector3Vec {
473    pub fn new(vec: Vec<nalgebra::Vector3<f32>>) -> Result<Self> {
474        if vec.is_empty() {
475            return Err(anyhow!("Vector3Vec cannot be empty"));
476        }
477        Ok(Vector3Vec(vec))
478    }
479}
480
481#[cfg(all(feature = "vector3", feature = "vec_variants"))]
482impl Eq for Vector3Vec {}
483
484/// A vector of transformation matrices.
485#[cfg(all(feature = "matrix3", feature = "vec_variants"))]
486#[derive(Clone, Debug, PartialEq)]
487#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
488#[cfg_attr(feature = "facet", derive(Facet))]
489#[cfg_attr(feature = "facet", facet(opaque))]
490pub struct Matrix3Vec(pub Vec<nalgebra::Matrix3<f32>>);
491
492#[cfg(all(feature = "matrix3", feature = "vec_variants"))]
493impl Matrix3Vec {
494    pub fn new(vec: Vec<nalgebra::Matrix3<f32>>) -> Result<Self> {
495        if vec.is_empty() {
496            return Err(anyhow!("Matrix3Vec cannot be empty"));
497        }
498        Ok(Matrix3Vec(vec))
499    }
500}
501
502#[cfg(all(feature = "matrix3", feature = "vec_variants"))]
503impl Eq for Matrix3Vec {}
504
505/// A vector of 3D normals.
506#[cfg(all(feature = "normal3", feature = "vec_variants"))]
507#[derive(Clone, Debug, PartialEq)]
508#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
509#[cfg_attr(feature = "facet", derive(Facet))]
510#[cfg_attr(feature = "facet", facet(opaque))]
511pub struct Normal3Vec(pub Vec<nalgebra::Vector3<f32>>);
512
513#[cfg(all(feature = "normal3", feature = "vec_variants"))]
514impl Normal3Vec {
515    pub fn new(vec: Vec<nalgebra::Vector3<f32>>) -> Result<Self> {
516        if vec.is_empty() {
517            return Err(anyhow!("Normal3Vec cannot be empty"));
518        }
519        Ok(Normal3Vec(vec))
520    }
521}
522
523#[cfg(all(feature = "normal3", feature = "vec_variants"))]
524impl Eq for Normal3Vec {}
525
526/// A vector of 3D points.
527#[cfg(all(feature = "point3", feature = "vec_variants"))]
528#[derive(Clone, Debug, PartialEq)]
529#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
530#[cfg_attr(feature = "facet", derive(Facet))]
531#[cfg_attr(feature = "facet", facet(opaque))]
532pub struct Point3Vec(pub Vec<nalgebra::Point3<f32>>);
533
534#[cfg(all(feature = "point3", feature = "vec_variants"))]
535impl Point3Vec {
536    pub fn new(vec: Vec<nalgebra::Point3<f32>>) -> Result<Self> {
537        if vec.is_empty() {
538            return Err(anyhow!("Point3Vec cannot be empty"));
539        }
540        Ok(Point3Vec(vec))
541    }
542}
543
544#[cfg(all(feature = "point3", feature = "vec_variants"))]
545impl Eq for Point3Vec {}
546
547/// A vector of 4×4 transformation matrices.
548#[cfg(all(feature = "matrix4", feature = "vec_variants"))]
549#[derive(Clone, Debug, PartialEq)]
550#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
551#[cfg_attr(feature = "facet", derive(Facet))]
552#[cfg_attr(feature = "facet", facet(opaque))]
553pub struct Matrix4Vec(pub Vec<nalgebra::Matrix4<f64>>);
554
555#[cfg(all(feature = "matrix4", feature = "vec_variants"))]
556impl Matrix4Vec {
557    pub fn new(vec: Vec<nalgebra::Matrix4<f64>>) -> Result<Self> {
558        if vec.is_empty() {
559            return Err(anyhow!("Matrix4Vec cannot be empty"));
560        }
561        Ok(Matrix4Vec(vec))
562    }
563}
564
565#[cfg(all(feature = "matrix4", feature = "vec_variants"))]
566impl Eq for Matrix4Vec {}
567
568// Arithmetic operations for new types
569#[cfg(feature = "normal3")]
570impl_nalgebra_arithmetic!(Normal3);
571
572#[cfg(feature = "point3")]
573impl Add for Point3 {
574    type Output = Point3;
575
576    fn add(self, other: Point3) -> Point3 {
577        Point3(self.0 + other.0.coords)
578    }
579}
580
581#[cfg(feature = "point3")]
582impl Sub for Point3 {
583    type Output = Point3;
584
585    fn sub(self, other: Point3) -> Point3 {
586        Point3(nalgebra::Point3::from(self.0.coords - other.0.coords))
587    }
588}
589
590#[cfg(feature = "point3")]
591impl Mul<f32> for Point3 {
592    type Output = Point3;
593
594    fn mul(self, scalar: f32) -> Point3 {
595        Point3(self.0 * scalar)
596    }
597}
598
599#[cfg(feature = "point3")]
600impl Mul<f64> for Point3 {
601    type Output = Point3;
602
603    fn mul(self, scalar: f64) -> Point3 {
604        Point3(self.0 * scalar as f32)
605    }
606}
607
608#[cfg(feature = "matrix4")]
609impl_nalgebra_arithmetic!(Matrix4, f64);
610
611// Arithmetic trait implementations for interpolation
612impl Add for Real {
613    type Output = Real;
614
615    fn add(self, other: Real) -> Real {
616        Real(self.0 + other.0)
617    }
618}
619
620impl Sub for Real {
621    type Output = Real;
622
623    fn sub(self, other: Real) -> Real {
624        Real(self.0 - other.0)
625    }
626}
627
628impl Mul<f32> for Real {
629    type Output = Real;
630
631    fn mul(self, scalar: f32) -> Real {
632        Real(self.0 * scalar as f64)
633    }
634}
635
636impl Mul<f64> for Real {
637    type Output = Real;
638
639    fn mul(self, scalar: f64) -> Real {
640        Real(self.0 * scalar)
641    }
642}
643
644impl Add for Integer {
645    type Output = Integer;
646
647    fn add(self, other: Integer) -> Integer {
648        Integer(self.0 + other.0)
649    }
650}
651
652impl Sub for Integer {
653    type Output = Integer;
654
655    fn sub(self, other: Integer) -> Integer {
656        Integer(self.0 - other.0)
657    }
658}
659
660impl Mul<f32> for Integer {
661    type Output = Integer;
662
663    fn mul(self, scalar: f32) -> Integer {
664        Integer((self.0 as f64 * scalar as f64) as i64)
665    }
666}
667
668impl Mul<f64> for Integer {
669    type Output = Integer;
670
671    fn mul(self, scalar: f64) -> Integer {
672        Integer((self.0 as f64 * scalar) as i64)
673    }
674}
675
676// Boolean arithmetic operations (treat as 0.0 and 1.0)
677impl Add for Boolean {
678    type Output = Boolean;
679
680    fn add(self, other: Boolean) -> Boolean {
681        Boolean(self.0 || other.0)
682    }
683}
684
685impl Sub for Boolean {
686    type Output = Boolean;
687
688    fn sub(self, other: Boolean) -> Boolean {
689        Boolean(self.0 && !other.0)
690    }
691}
692
693impl Mul<f32> for Boolean {
694    type Output = Boolean;
695
696    fn mul(self, _scalar: f32) -> Boolean {
697        self
698    }
699}
700
701impl Mul<f64> for Boolean {
702    type Output = Boolean;
703
704    fn mul(self, _scalar: f64) -> Boolean {
705        self
706    }
707}
708
709// String arithmetic operations (concatenation for add, identity for others)
710impl Add for String {
711    type Output = String;
712
713    fn add(self, _other: String) -> String {
714        self
715    }
716}
717
718impl Sub for String {
719    type Output = String;
720
721    fn sub(self, _other: String) -> String {
722        self
723    }
724}
725
726impl Mul<f32> for String {
727    type Output = String;
728
729    fn mul(self, _scalar: f32) -> String {
730        self
731    }
732}
733
734impl Mul<f64> for String {
735    type Output = String;
736
737    fn mul(self, _scalar: f64) -> String {
738        self
739    }
740}
741
742// BooleanVec arithmetic operations
743impl Add for BooleanVec {
744    type Output = BooleanVec;
745
746    fn add(self, other: BooleanVec) -> BooleanVec {
747        if self.0.len() != other.0.len() {
748            panic!("Vector lengths must match for addition");
749        }
750        BooleanVec(
751            self.0
752                .into_iter()
753                .zip(other.0)
754                .map(|(a, b)| a || b)
755                .collect(),
756        )
757    }
758}
759
760impl Sub for BooleanVec {
761    type Output = BooleanVec;
762
763    fn sub(self, other: BooleanVec) -> BooleanVec {
764        if self.0.len() != other.0.len() {
765            panic!("Vector lengths must match for subtraction");
766        }
767        BooleanVec(
768            self.0
769                .into_iter()
770                .zip(other.0)
771                .map(|(a, b)| a && !b)
772                .collect(),
773        )
774    }
775}
776
777impl Mul<f32> for BooleanVec {
778    type Output = BooleanVec;
779
780    fn mul(self, _scalar: f32) -> BooleanVec {
781        self
782    }
783}
784
785impl Mul<f64> for BooleanVec {
786    type Output = BooleanVec;
787
788    fn mul(self, _scalar: f64) -> BooleanVec {
789        self
790    }
791}
792
793// StringVec arithmetic operations
794impl Add for StringVec {
795    type Output = StringVec;
796
797    fn add(self, other: StringVec) -> StringVec {
798        if self.0.len() != other.0.len() {
799            panic!("Vector lengths must match for addition");
800        }
801        StringVec(
802            self.0
803                .into_iter()
804                .zip(other.0)
805                .map(|(a, b)| format!("{a}{b}"))
806                .collect(),
807        )
808    }
809}
810
811impl Sub for StringVec {
812    type Output = StringVec;
813
814    fn sub(self, _other: StringVec) -> StringVec {
815        self
816    }
817}
818
819impl Mul<f32> for StringVec {
820    type Output = StringVec;
821
822    fn mul(self, _scalar: f32) -> StringVec {
823        self
824    }
825}
826
827impl Mul<f64> for StringVec {
828    type Output = StringVec;
829
830    fn mul(self, _scalar: f64) -> StringVec {
831        self
832    }
833}
834
835// Color arithmetic operations
836impl Add for Color {
837    type Output = Color;
838
839    fn add(self, other: Color) -> Color {
840        Color([
841            self.0[0] + other.0[0],
842            self.0[1] + other.0[1],
843            self.0[2] + other.0[2],
844            self.0[3] + other.0[3],
845        ])
846    }
847}
848
849impl Sub for Color {
850    type Output = Color;
851
852    fn sub(self, other: Color) -> Color {
853        Color([
854            self.0[0] - other.0[0],
855            self.0[1] - other.0[1],
856            self.0[2] - other.0[2],
857            self.0[3] - other.0[3],
858        ])
859    }
860}
861
862impl Mul<f32> for Color {
863    type Output = Color;
864
865    fn mul(self, scalar: f32) -> Color {
866        Color([
867            self.0[0] * scalar,
868            self.0[1] * scalar,
869            self.0[2] * scalar,
870            self.0[3] * scalar,
871        ])
872    }
873}
874
875impl Mul<f64> for Color {
876    type Output = Color;
877
878    fn mul(self, scalar: f64) -> Color {
879        let scalar = scalar as f32;
880        Color([
881            self.0[0] * scalar,
882            self.0[1] * scalar,
883            self.0[2] * scalar,
884            self.0[3] * scalar,
885        ])
886    }
887}
888
889// Vector2 arithmetic operations
890#[cfg(feature = "vector2")]
891impl_nalgebra_arithmetic!(Vector2);
892
893// Vector3 arithmetic operations
894#[cfg(feature = "vector3")]
895impl_nalgebra_arithmetic!(Vector3);
896
897// Matrix3 arithmetic operations
898#[cfg(feature = "matrix3")]
899impl_nalgebra_arithmetic!(Matrix3);
900
901// Matrix3 multiplication (matrix * matrix)
902#[cfg(feature = "matrix3")]
903impl Mul for Matrix3 {
904    type Output = Matrix3;
905
906    fn mul(self, other: Matrix3) -> Matrix3 {
907        Matrix3(self.0 * other.0)
908    }
909}
910
911#[cfg(feature = "matrix3")]
912impl Mul<&Matrix3> for Matrix3 {
913    type Output = Matrix3;
914
915    fn mul(self, other: &Matrix3) -> Matrix3 {
916        Matrix3(self.0 * other.0)
917    }
918}
919
920#[cfg(feature = "matrix3")]
921impl Mul<Matrix3> for &Matrix3 {
922    type Output = Matrix3;
923
924    fn mul(self, other: Matrix3) -> Matrix3 {
925        Matrix3(self.0 * other.0)
926    }
927}
928
929#[cfg(feature = "matrix3")]
930impl Mul<&Matrix3> for &Matrix3 {
931    type Output = Matrix3;
932
933    fn mul(self, other: &Matrix3) -> Matrix3 {
934        Matrix3(self.0 * other.0)
935    }
936}
937
938// Vector types arithmetic operations
939impl Add for RealVec {
940    type Output = RealVec;
941
942    fn add(self, other: RealVec) -> RealVec {
943        if self.0.len() != other.0.len() {
944            panic!("Vector lengths must match for addition");
945        }
946        RealVec(
947            self.0
948                .into_iter()
949                .zip(other.0)
950                .map(|(a, b)| a + b)
951                .collect(),
952        )
953    }
954}
955
956impl Sub for RealVec {
957    type Output = RealVec;
958
959    fn sub(self, other: RealVec) -> RealVec {
960        if self.0.len() != other.0.len() {
961            panic!("Vector lengths must match for subtraction");
962        }
963        RealVec(
964            self.0
965                .into_iter()
966                .zip(other.0)
967                .map(|(a, b)| a - b)
968                .collect(),
969        )
970    }
971}
972
973impl Mul<f32> for RealVec {
974    type Output = RealVec;
975
976    fn mul(self, scalar: f32) -> RealVec {
977        RealVec(self.0.into_iter().map(|x| x * scalar as f64).collect())
978    }
979}
980
981impl Mul<f64> for RealVec {
982    type Output = RealVec;
983
984    fn mul(self, scalar: f64) -> RealVec {
985        RealVec(self.0.into_iter().map(|x| x * scalar).collect())
986    }
987}
988
989impl Add for IntegerVec {
990    type Output = IntegerVec;
991
992    fn add(self, other: IntegerVec) -> IntegerVec {
993        if self.0.len() != other.0.len() {
994            panic!("Vector lengths must match for addition");
995        }
996        IntegerVec(
997            self.0
998                .into_iter()
999                .zip(other.0)
1000                .map(|(a, b)| a + b)
1001                .collect(),
1002        )
1003    }
1004}
1005
1006impl Sub for IntegerVec {
1007    type Output = IntegerVec;
1008
1009    fn sub(self, other: IntegerVec) -> IntegerVec {
1010        if self.0.len() != other.0.len() {
1011            panic!("Vector lengths must match for subtraction");
1012        }
1013        IntegerVec(
1014            self.0
1015                .into_iter()
1016                .zip(other.0)
1017                .map(|(a, b)| a - b)
1018                .collect(),
1019        )
1020    }
1021}
1022
1023impl Mul<f32> for IntegerVec {
1024    type Output = IntegerVec;
1025
1026    fn mul(self, scalar: f32) -> IntegerVec {
1027        IntegerVec(
1028            self.0
1029                .into_iter()
1030                .map(|x| (x as f64 * scalar as f64) as i64)
1031                .collect(),
1032        )
1033    }
1034}
1035
1036impl Mul<f64> for IntegerVec {
1037    type Output = IntegerVec;
1038
1039    fn mul(self, scalar: f64) -> IntegerVec {
1040        IntegerVec(
1041            self.0
1042                .into_iter()
1043                .map(|x| (x as f64 * scalar) as i64)
1044                .collect(),
1045        )
1046    }
1047}
1048
1049impl Add for ColorVec {
1050    type Output = ColorVec;
1051
1052    fn add(self, other: ColorVec) -> ColorVec {
1053        if self.0.len() != other.0.len() {
1054            panic!("Vector lengths must match for addition");
1055        }
1056        ColorVec(
1057            self.0
1058                .into_iter()
1059                .zip(other.0)
1060                .map(|(a, b)| [a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]])
1061                .collect(),
1062        )
1063    }
1064}
1065
1066impl Sub for ColorVec {
1067    type Output = ColorVec;
1068
1069    fn sub(self, other: ColorVec) -> ColorVec {
1070        if self.0.len() != other.0.len() {
1071            panic!("Vector lengths must match for subtraction");
1072        }
1073        ColorVec(
1074            self.0
1075                .into_iter()
1076                .zip(other.0)
1077                .map(|(a, b)| [a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]])
1078                .collect(),
1079        )
1080    }
1081}
1082
1083impl Mul<f32> for ColorVec {
1084    type Output = ColorVec;
1085
1086    fn mul(self, scalar: f32) -> ColorVec {
1087        ColorVec(
1088            self.0
1089                .into_iter()
1090                .map(|color| {
1091                    [
1092                        color[0] * scalar,
1093                        color[1] * scalar,
1094                        color[2] * scalar,
1095                        color[3] * scalar,
1096                    ]
1097                })
1098                .collect(),
1099        )
1100    }
1101}
1102
1103impl Mul<f64> for ColorVec {
1104    type Output = ColorVec;
1105
1106    fn mul(self, scalar: f64) -> ColorVec {
1107        let scalar = scalar as f32;
1108        ColorVec(
1109            self.0
1110                .into_iter()
1111                .map(|color| {
1112                    [
1113                        color[0] * scalar,
1114                        color[1] * scalar,
1115                        color[2] * scalar,
1116                        color[3] * scalar,
1117                    ]
1118                })
1119                .collect(),
1120        )
1121    }
1122}
1123
1124#[cfg(all(feature = "vector2", feature = "vec_variants"))]
1125impl Add for Vector2Vec {
1126    type Output = Vector2Vec;
1127
1128    fn add(self, other: Vector2Vec) -> Vector2Vec {
1129        if self.0.len() != other.0.len() {
1130            panic!("Vector lengths must match for addition");
1131        }
1132        Vector2Vec(
1133            self.0
1134                .into_iter()
1135                .zip(other.0)
1136                .map(|(a, b)| a + b)
1137                .collect(),
1138        )
1139    }
1140}
1141
1142#[cfg(all(feature = "vector2", feature = "vec_variants"))]
1143impl Sub for Vector2Vec {
1144    type Output = Vector2Vec;
1145
1146    fn sub(self, other: Vector2Vec) -> Vector2Vec {
1147        if self.0.len() != other.0.len() {
1148            panic!("Vector lengths must match for subtraction");
1149        }
1150        Vector2Vec(
1151            self.0
1152                .into_iter()
1153                .zip(other.0)
1154                .map(|(a, b)| a - b)
1155                .collect(),
1156        )
1157    }
1158}
1159
1160#[cfg(all(feature = "vector2", feature = "vec_variants"))]
1161impl Mul<f32> for Vector2Vec {
1162    type Output = Vector2Vec;
1163
1164    fn mul(self, scalar: f32) -> Vector2Vec {
1165        Vector2Vec(self.0.into_iter().map(|vec| vec * scalar).collect())
1166    }
1167}
1168
1169#[cfg(all(feature = "vector2", feature = "vec_variants"))]
1170impl Mul<f64> for Vector2Vec {
1171    type Output = Vector2Vec;
1172
1173    fn mul(self, scalar: f64) -> Vector2Vec {
1174        let scalar = scalar as f32;
1175        Vector2Vec(self.0.into_iter().map(|vec| vec * scalar).collect())
1176    }
1177}
1178
1179#[cfg(all(feature = "vector3", feature = "vec_variants"))]
1180impl Add for Vector3Vec {
1181    type Output = Vector3Vec;
1182
1183    fn add(self, other: Vector3Vec) -> Vector3Vec {
1184        if self.0.len() != other.0.len() {
1185            panic!("Vector lengths must match for addition");
1186        }
1187        Vector3Vec(
1188            self.0
1189                .into_iter()
1190                .zip(other.0)
1191                .map(|(a, b)| a + b)
1192                .collect(),
1193        )
1194    }
1195}
1196
1197#[cfg(all(feature = "vector3", feature = "vec_variants"))]
1198impl Sub for Vector3Vec {
1199    type Output = Vector3Vec;
1200
1201    fn sub(self, other: Vector3Vec) -> Vector3Vec {
1202        if self.0.len() != other.0.len() {
1203            panic!("Vector lengths must match for subtraction");
1204        }
1205        Vector3Vec(
1206            self.0
1207                .into_iter()
1208                .zip(other.0)
1209                .map(|(a, b)| a - b)
1210                .collect(),
1211        )
1212    }
1213}
1214
1215#[cfg(all(feature = "vector3", feature = "vec_variants"))]
1216impl Mul<f32> for Vector3Vec {
1217    type Output = Vector3Vec;
1218
1219    fn mul(self, scalar: f32) -> Vector3Vec {
1220        Vector3Vec(self.0.into_iter().map(|vec| vec * scalar).collect())
1221    }
1222}
1223
1224#[cfg(all(feature = "vector3", feature = "vec_variants"))]
1225impl Mul<f64> for Vector3Vec {
1226    type Output = Vector3Vec;
1227
1228    fn mul(self, scalar: f64) -> Vector3Vec {
1229        let scalar = scalar as f32;
1230        Vector3Vec(self.0.into_iter().map(|vec| vec * scalar).collect())
1231    }
1232}
1233
1234#[cfg(all(feature = "matrix3", feature = "vec_variants"))]
1235impl Add for Matrix3Vec {
1236    type Output = Matrix3Vec;
1237
1238    fn add(self, other: Matrix3Vec) -> Matrix3Vec {
1239        if self.0.len() != other.0.len() {
1240            panic!("Vector lengths must match for addition");
1241        }
1242        Matrix3Vec(
1243            self.0
1244                .into_iter()
1245                .zip(other.0)
1246                .map(|(a, b)| a + b)
1247                .collect(),
1248        )
1249    }
1250}
1251
1252#[cfg(all(feature = "matrix3", feature = "vec_variants"))]
1253impl Sub for Matrix3Vec {
1254    type Output = Matrix3Vec;
1255
1256    fn sub(self, other: Matrix3Vec) -> Matrix3Vec {
1257        if self.0.len() != other.0.len() {
1258            panic!("Vector lengths must match for subtraction");
1259        }
1260        Matrix3Vec(
1261            self.0
1262                .into_iter()
1263                .zip(other.0)
1264                .map(|(a, b)| a - b)
1265                .collect(),
1266        )
1267    }
1268}
1269
1270#[cfg(all(feature = "matrix3", feature = "vec_variants"))]
1271impl Mul<f32> for Matrix3Vec {
1272    type Output = Matrix3Vec;
1273
1274    fn mul(self, scalar: f32) -> Matrix3Vec {
1275        Matrix3Vec(self.0.into_iter().map(|mat| mat * scalar).collect())
1276    }
1277}
1278
1279#[cfg(all(feature = "matrix3", feature = "vec_variants"))]
1280impl Mul<f64> for Matrix3Vec {
1281    type Output = Matrix3Vec;
1282
1283    fn mul(self, scalar: f64) -> Matrix3Vec {
1284        let scalar = scalar as f32;
1285        Matrix3Vec(self.0.into_iter().map(|mat| mat * scalar).collect())
1286    }
1287}
1288
1289// Normal3Vec arithmetic operations
1290#[cfg(all(feature = "normal3", feature = "vec_variants"))]
1291impl Add for Normal3Vec {
1292    type Output = Normal3Vec;
1293
1294    fn add(self, other: Normal3Vec) -> Self::Output {
1295        Normal3Vec(
1296            self.0
1297                .into_iter()
1298                .zip(other.0)
1299                .map(|(a, b)| a + b)
1300                .collect(),
1301        )
1302    }
1303}
1304
1305#[cfg(all(feature = "normal3", feature = "vec_variants"))]
1306impl Sub for Normal3Vec {
1307    type Output = Normal3Vec;
1308
1309    fn sub(self, other: Normal3Vec) -> Self::Output {
1310        Normal3Vec(
1311            self.0
1312                .into_iter()
1313                .zip(other.0)
1314                .map(|(a, b)| a - b)
1315                .collect(),
1316        )
1317    }
1318}
1319
1320#[cfg(all(feature = "normal3", feature = "vec_variants"))]
1321impl Mul<f32> for Normal3Vec {
1322    type Output = Normal3Vec;
1323
1324    fn mul(self, scalar: f32) -> Self::Output {
1325        Normal3Vec(self.0.into_iter().map(|v| v * scalar).collect())
1326    }
1327}
1328
1329#[cfg(all(feature = "normal3", feature = "vec_variants"))]
1330impl Mul<f64> for Normal3Vec {
1331    type Output = Normal3Vec;
1332
1333    fn mul(self, scalar: f64) -> Self::Output {
1334        Normal3Vec(self.0.into_iter().map(|v| v * scalar as f32).collect())
1335    }
1336}
1337
1338// Point3Vec arithmetic operations
1339#[cfg(all(feature = "point3", feature = "vec_variants"))]
1340impl Add for Point3Vec {
1341    type Output = Point3Vec;
1342
1343    fn add(self, other: Point3Vec) -> Self::Output {
1344        Point3Vec(
1345            self.0
1346                .into_iter()
1347                .zip(other.0)
1348                .map(|(a, b)| a + b.coords)
1349                .collect(),
1350        )
1351    }
1352}
1353
1354#[cfg(all(feature = "point3", feature = "vec_variants"))]
1355impl Sub for Point3Vec {
1356    type Output = Point3Vec;
1357
1358    fn sub(self, other: Point3Vec) -> Self::Output {
1359        Point3Vec(
1360            self.0
1361                .into_iter()
1362                .zip(other.0)
1363                .map(|(a, b)| nalgebra::Point3::from(a.coords - b.coords))
1364                .collect(),
1365        )
1366    }
1367}
1368
1369#[cfg(all(feature = "point3", feature = "vec_variants"))]
1370impl Mul<f32> for Point3Vec {
1371    type Output = Point3Vec;
1372
1373    fn mul(self, scalar: f32) -> Self::Output {
1374        Point3Vec(
1375            self.0
1376                .into_iter()
1377                .map(|p| nalgebra::Point3::from(p.coords * scalar))
1378                .collect(),
1379        )
1380    }
1381}
1382
1383#[cfg(all(feature = "point3", feature = "vec_variants"))]
1384impl Mul<f64> for Point3Vec {
1385    type Output = Point3Vec;
1386
1387    fn mul(self, scalar: f64) -> Self::Output {
1388        Point3Vec(
1389            self.0
1390                .into_iter()
1391                .map(|p| nalgebra::Point3::from(p.coords * scalar as f32))
1392                .collect(),
1393        )
1394    }
1395}
1396
1397// Matrix4Vec arithmetic operations
1398#[cfg(all(feature = "matrix4", feature = "vec_variants"))]
1399impl Add for Matrix4Vec {
1400    type Output = Matrix4Vec;
1401
1402    fn add(self, other: Matrix4Vec) -> Self::Output {
1403        Matrix4Vec(
1404            self.0
1405                .into_iter()
1406                .zip(other.0)
1407                .map(|(a, b)| a + b)
1408                .collect(),
1409        )
1410    }
1411}
1412
1413#[cfg(all(feature = "matrix4", feature = "vec_variants"))]
1414impl Sub for Matrix4Vec {
1415    type Output = Matrix4Vec;
1416
1417    fn sub(self, other: Matrix4Vec) -> Self::Output {
1418        Matrix4Vec(
1419            self.0
1420                .into_iter()
1421                .zip(other.0)
1422                .map(|(a, b)| a - b)
1423                .collect(),
1424        )
1425    }
1426}
1427
1428#[cfg(all(feature = "matrix4", feature = "vec_variants"))]
1429impl Mul<f32> for Matrix4Vec {
1430    type Output = Matrix4Vec;
1431
1432    fn mul(self, scalar: f32) -> Self::Output {
1433        Matrix4Vec(self.0.into_iter().map(|v| v * scalar as f64).collect())
1434    }
1435}
1436
1437#[cfg(all(feature = "matrix4", feature = "vec_variants"))]
1438impl Mul<f64> for Matrix4Vec {
1439    type Output = Matrix4Vec;
1440
1441    fn mul(self, scalar: f64) -> Self::Output {
1442        Matrix4Vec(self.0.into_iter().map(|v| v * scalar).collect())
1443    }
1444}
1445
1446// Division implementations for f32
1447#[cfg(feature = "normal3")]
1448impl Div<f32> for Normal3 {
1449    type Output = Normal3;
1450
1451    fn div(self, scalar: f32) -> Normal3 {
1452        Normal3(self.0 / scalar)
1453    }
1454}
1455
1456#[cfg(feature = "point3")]
1457impl Div<f32> for Point3 {
1458    type Output = Point3;
1459
1460    fn div(self, scalar: f32) -> Point3 {
1461        Point3(self.0 / scalar)
1462    }
1463}
1464
1465#[cfg(feature = "matrix4")]
1466impl Div<f32> for Matrix4 {
1467    type Output = Matrix4;
1468
1469    fn div(self, scalar: f32) -> Matrix4 {
1470        Matrix4(self.0 / scalar as f64)
1471    }
1472}
1473
1474impl Div<f32> for Real {
1475    type Output = Real;
1476
1477    fn div(self, scalar: f32) -> Real {
1478        Real(self.0 / scalar as f64)
1479    }
1480}
1481
1482impl Div<f32> for Integer {
1483    type Output = Integer;
1484
1485    fn div(self, scalar: f32) -> Integer {
1486        Integer((self.0 as f64 / scalar as f64) as i64)
1487    }
1488}
1489
1490impl Div<f32> for Boolean {
1491    type Output = Boolean;
1492
1493    fn div(self, _scalar: f32) -> Boolean {
1494        self
1495    }
1496}
1497
1498impl Div<f32> for String {
1499    type Output = String;
1500
1501    fn div(self, _scalar: f32) -> String {
1502        self
1503    }
1504}
1505
1506impl Div<f32> for BooleanVec {
1507    type Output = BooleanVec;
1508
1509    fn div(self, _scalar: f32) -> BooleanVec {
1510        self
1511    }
1512}
1513
1514impl Div<f32> for StringVec {
1515    type Output = StringVec;
1516
1517    fn div(self, _scalar: f32) -> StringVec {
1518        self
1519    }
1520}
1521
1522impl Div<f32> for Color {
1523    type Output = Color;
1524
1525    fn div(self, scalar: f32) -> Color {
1526        Color([
1527            self.0[0] / scalar,
1528            self.0[1] / scalar,
1529            self.0[2] / scalar,
1530            self.0[3] / scalar,
1531        ])
1532    }
1533}
1534
1535#[cfg(feature = "vector2")]
1536impl Div<f32> for Vector2 {
1537    type Output = Vector2;
1538
1539    fn div(self, scalar: f32) -> Vector2 {
1540        Vector2(self.0 / scalar)
1541    }
1542}
1543
1544#[cfg(feature = "vector3")]
1545impl Div<f32> for Vector3 {
1546    type Output = Vector3;
1547
1548    fn div(self, scalar: f32) -> Vector3 {
1549        Vector3(self.0 / scalar)
1550    }
1551}
1552
1553#[cfg(feature = "matrix3")]
1554impl Div<f32> for Matrix3 {
1555    type Output = Matrix3;
1556
1557    fn div(self, scalar: f32) -> Matrix3 {
1558        Matrix3(self.0 / scalar)
1559    }
1560}
1561
1562#[cfg(feature = "vec_variants")]
1563impl Div<f32> for RealVec {
1564    type Output = RealVec;
1565
1566    fn div(self, scalar: f32) -> RealVec {
1567        RealVec(self.0.into_iter().map(|x| x / scalar as f64).collect())
1568    }
1569}
1570
1571#[cfg(feature = "vec_variants")]
1572impl Div<f32> for IntegerVec {
1573    type Output = IntegerVec;
1574
1575    fn div(self, scalar: f32) -> IntegerVec {
1576        IntegerVec(
1577            self.0
1578                .into_iter()
1579                .map(|x| (x as f64 / scalar as f64) as i64)
1580                .collect(),
1581        )
1582    }
1583}
1584
1585#[cfg(feature = "vec_variants")]
1586impl Div<f32> for ColorVec {
1587    type Output = ColorVec;
1588
1589    fn div(self, scalar: f32) -> ColorVec {
1590        ColorVec(
1591            self.0
1592                .into_iter()
1593                .map(|color| {
1594                    [
1595                        color[0] / scalar,
1596                        color[1] / scalar,
1597                        color[2] / scalar,
1598                        color[3] / scalar,
1599                    ]
1600                })
1601                .collect(),
1602        )
1603    }
1604}
1605
1606#[cfg(all(feature = "vector2", feature = "vec_variants"))]
1607impl Div<f32> for Vector2Vec {
1608    type Output = Vector2Vec;
1609
1610    fn div(self, scalar: f32) -> Vector2Vec {
1611        Vector2Vec(self.0.into_iter().map(|vec| vec / scalar).collect())
1612    }
1613}
1614
1615#[cfg(all(feature = "vector3", feature = "vec_variants"))]
1616impl Div<f32> for Vector3Vec {
1617    type Output = Vector3Vec;
1618
1619    fn div(self, scalar: f32) -> Vector3Vec {
1620        Vector3Vec(self.0.into_iter().map(|vec| vec / scalar).collect())
1621    }
1622}
1623
1624#[cfg(all(feature = "matrix3", feature = "vec_variants"))]
1625impl Div<f32> for Matrix3Vec {
1626    type Output = Matrix3Vec;
1627
1628    fn div(self, scalar: f32) -> Matrix3Vec {
1629        Matrix3Vec(self.0.into_iter().map(|mat| mat / scalar).collect())
1630    }
1631}
1632
1633#[cfg(all(feature = "normal3", feature = "vec_variants"))]
1634impl Div<f32> for Normal3Vec {
1635    type Output = Normal3Vec;
1636
1637    fn div(self, scalar: f32) -> Self::Output {
1638        Normal3Vec(self.0.into_iter().map(|v| v / scalar).collect())
1639    }
1640}
1641
1642#[cfg(all(feature = "point3", feature = "vec_variants"))]
1643impl Div<f32> for Point3Vec {
1644    type Output = Point3Vec;
1645
1646    fn div(self, scalar: f32) -> Self::Output {
1647        Point3Vec(self.0.into_iter().map(|v| v / scalar).collect())
1648    }
1649}
1650
1651#[cfg(all(feature = "matrix4", feature = "vec_variants"))]
1652impl Div<f32> for Matrix4Vec {
1653    type Output = Matrix4Vec;
1654
1655    fn div(self, scalar: f32) -> Self::Output {
1656        Matrix4Vec(self.0.into_iter().map(|v| v / scalar as f64).collect())
1657    }
1658}
1659
1660// Division implementations for f64
1661#[cfg(feature = "normal3")]
1662impl Div<f64> for Normal3 {
1663    type Output = Normal3;
1664
1665    fn div(self, scalar: f64) -> Normal3 {
1666        Normal3(self.0 / scalar as f32)
1667    }
1668}
1669
1670#[cfg(feature = "point3")]
1671impl Div<f64> for Point3 {
1672    type Output = Point3;
1673
1674    fn div(self, scalar: f64) -> Point3 {
1675        Point3(self.0 / scalar as f32)
1676    }
1677}
1678
1679#[cfg(feature = "matrix4")]
1680impl Div<f64> for Matrix4 {
1681    type Output = Matrix4;
1682
1683    fn div(self, scalar: f64) -> Matrix4 {
1684        Matrix4(self.0 / scalar)
1685    }
1686}
1687
1688impl Div<f64> for Real {
1689    type Output = Real;
1690
1691    fn div(self, scalar: f64) -> Real {
1692        Real(self.0 / scalar)
1693    }
1694}
1695
1696impl Div<f64> for Integer {
1697    type Output = Integer;
1698
1699    fn div(self, scalar: f64) -> Integer {
1700        Integer((self.0 as f64 / scalar) as i64)
1701    }
1702}
1703
1704impl Div<f64> for Boolean {
1705    type Output = Boolean;
1706
1707    fn div(self, _scalar: f64) -> Boolean {
1708        self
1709    }
1710}
1711
1712impl Div<f64> for String {
1713    type Output = String;
1714
1715    fn div(self, _scalar: f64) -> String {
1716        self
1717    }
1718}
1719
1720#[cfg(feature = "vec_variants")]
1721impl Div<f64> for BooleanVec {
1722    type Output = BooleanVec;
1723
1724    fn div(self, _scalar: f64) -> BooleanVec {
1725        self
1726    }
1727}
1728
1729#[cfg(feature = "vec_variants")]
1730impl Div<f64> for StringVec {
1731    type Output = StringVec;
1732
1733    fn div(self, _scalar: f64) -> StringVec {
1734        self
1735    }
1736}
1737
1738impl Div<f64> for Color {
1739    type Output = Color;
1740
1741    fn div(self, scalar: f64) -> Color {
1742        let scalar = scalar as f32;
1743        Color([
1744            self.0[0] / scalar,
1745            self.0[1] / scalar,
1746            self.0[2] / scalar,
1747            self.0[3] / scalar,
1748        ])
1749    }
1750}
1751
1752#[cfg(feature = "vector2")]
1753impl Div<f64> for Vector2 {
1754    type Output = Vector2;
1755
1756    fn div(self, scalar: f64) -> Vector2 {
1757        Vector2(self.0 / scalar as f32)
1758    }
1759}
1760
1761#[cfg(feature = "vector3")]
1762impl Div<f64> for Vector3 {
1763    type Output = Vector3;
1764
1765    fn div(self, scalar: f64) -> Vector3 {
1766        Vector3(self.0 / scalar as f32)
1767    }
1768}
1769
1770#[cfg(feature = "matrix3")]
1771impl Div<f64> for Matrix3 {
1772    type Output = Matrix3;
1773
1774    fn div(self, scalar: f64) -> Matrix3 {
1775        Matrix3(self.0 / scalar as f32)
1776    }
1777}
1778
1779#[cfg(feature = "vec_variants")]
1780impl Div<f64> for RealVec {
1781    type Output = RealVec;
1782
1783    fn div(self, scalar: f64) -> RealVec {
1784        RealVec(self.0.into_iter().map(|x| x / scalar).collect())
1785    }
1786}
1787
1788#[cfg(feature = "vec_variants")]
1789impl Div<f64> for IntegerVec {
1790    type Output = IntegerVec;
1791
1792    fn div(self, scalar: f64) -> IntegerVec {
1793        IntegerVec(
1794            self.0
1795                .into_iter()
1796                .map(|x| (x as f64 / scalar) as i64)
1797                .collect(),
1798        )
1799    }
1800}
1801
1802#[cfg(feature = "vec_variants")]
1803impl Div<f64> for ColorVec {
1804    type Output = ColorVec;
1805
1806    fn div(self, scalar: f64) -> ColorVec {
1807        let scalar = scalar as f32;
1808        ColorVec(
1809            self.0
1810                .into_iter()
1811                .map(|color| {
1812                    [
1813                        color[0] / scalar,
1814                        color[1] / scalar,
1815                        color[2] / scalar,
1816                        color[3] / scalar,
1817                    ]
1818                })
1819                .collect(),
1820        )
1821    }
1822}
1823
1824#[cfg(all(feature = "vector2", feature = "vec_variants"))]
1825impl Div<f64> for Vector2Vec {
1826    type Output = Vector2Vec;
1827
1828    fn div(self, scalar: f64) -> Vector2Vec {
1829        let scalar = scalar as f32;
1830        Vector2Vec(self.0.into_iter().map(|vec| vec / scalar).collect())
1831    }
1832}
1833
1834#[cfg(all(feature = "vector3", feature = "vec_variants"))]
1835impl Div<f64> for Vector3Vec {
1836    type Output = Vector3Vec;
1837
1838    fn div(self, scalar: f64) -> Vector3Vec {
1839        let scalar = scalar as f32;
1840        Vector3Vec(self.0.into_iter().map(|vec| vec / scalar).collect())
1841    }
1842}
1843
1844#[cfg(all(feature = "matrix3", feature = "vec_variants"))]
1845impl Div<f64> for Matrix3Vec {
1846    type Output = Matrix3Vec;
1847
1848    fn div(self, scalar: f64) -> Matrix3Vec {
1849        let scalar = scalar as f32;
1850        Matrix3Vec(self.0.into_iter().map(|mat| mat / scalar).collect())
1851    }
1852}
1853
1854#[cfg(all(feature = "normal3", feature = "vec_variants"))]
1855impl Div<f64> for Normal3Vec {
1856    type Output = Normal3Vec;
1857
1858    fn div(self, scalar: f64) -> Self::Output {
1859        Normal3Vec(self.0.into_iter().map(|v| v / scalar as f32).collect())
1860    }
1861}
1862
1863#[cfg(all(feature = "point3", feature = "vec_variants"))]
1864impl Div<f64> for Point3Vec {
1865    type Output = Point3Vec;
1866
1867    fn div(self, scalar: f64) -> Self::Output {
1868        Point3Vec(self.0.into_iter().map(|v| v / scalar as f32).collect())
1869    }
1870}
1871
1872#[cfg(all(feature = "matrix4", feature = "vec_variants"))]
1873impl Div<f64> for Matrix4Vec {
1874    type Output = Matrix4Vec;
1875
1876    fn div(self, scalar: f64) -> Self::Output {
1877        Matrix4Vec(self.0.into_iter().map(|v| v / scalar).collect())
1878    }
1879}
1880
1881// Hash implementations for floating point types
1882// Using bit representation for deterministic hashing
1883
1884impl Hash for Real {
1885    fn hash<H: Hasher>(&self, state: &mut H) {
1886        // Normalize -0.0 to 0.0 for consistent hashing
1887        // Check if the value is zero (either -0.0 or 0.0) and normalize to 0.0
1888        let normalized = if self.0 == 0.0 { 0.0_f64 } else { self.0 };
1889        normalized.to_bits().hash(state);
1890    }
1891}
1892
1893impl Hash for Color {
1894    fn hash<H: Hasher>(&self, state: &mut H) {
1895        for &component in &self.0 {
1896            // Normalize -0.0 to 0.0 for consistent hashing
1897            let normalized = if component == 0.0 { 0.0_f32 } else { component };
1898            normalized.to_bits().hash(state);
1899        }
1900    }
1901}
1902
1903#[cfg(feature = "vector2")]
1904impl Hash for Vector2 {
1905    fn hash<H: Hasher>(&self, state: &mut H) {
1906        // Normalize -0.0 to 0.0 for consistent hashing
1907        let x = if self.0.x == 0.0 { 0.0_f32 } else { self.0.x };
1908        let y = if self.0.y == 0.0 { 0.0_f32 } else { self.0.y };
1909        x.to_bits().hash(state);
1910        y.to_bits().hash(state);
1911    }
1912}
1913
1914#[cfg(feature = "vector3")]
1915impl Hash for Vector3 {
1916    fn hash<H: Hasher>(&self, state: &mut H) {
1917        // Normalize -0.0 to 0.0 for consistent hashing
1918        let x = if self.0.x == 0.0 { 0.0_f32 } else { self.0.x };
1919        let y = if self.0.y == 0.0 { 0.0_f32 } else { self.0.y };
1920        let z = if self.0.z == 0.0 { 0.0_f32 } else { self.0.z };
1921        x.to_bits().hash(state);
1922        y.to_bits().hash(state);
1923        z.to_bits().hash(state);
1924    }
1925}
1926
1927#[cfg(feature = "matrix3")]
1928impl Hash for Matrix3 {
1929    fn hash<H: Hasher>(&self, state: &mut H) {
1930        for &element in self.0.iter() {
1931            // Normalize -0.0 to 0.0 for consistent hashing
1932            let normalized = if element == 0.0 { 0.0_f32 } else { element };
1933            normalized.to_bits().hash(state);
1934        }
1935    }
1936}
1937
1938impl Hash for RealVec {
1939    fn hash<H: Hasher>(&self, state: &mut H) {
1940        self.0.len().hash(state);
1941        for &element in &self.0 {
1942            // Normalize -0.0 to 0.0 for consistent hashing
1943            let normalized = if element == 0.0 { 0.0_f64 } else { element };
1944            normalized.to_bits().hash(state);
1945        }
1946    }
1947}
1948
1949impl Hash for ColorVec {
1950    fn hash<H: Hasher>(&self, state: &mut H) {
1951        self.0.len().hash(state);
1952        for color in &self.0 {
1953            for &component in color {
1954                // Normalize -0.0 to 0.0 for consistent hashing
1955                let normalized = if component == 0.0 { 0.0_f32 } else { component };
1956                normalized.to_bits().hash(state);
1957            }
1958        }
1959    }
1960}
1961
1962#[cfg(all(feature = "vector2", feature = "vec_variants"))]
1963impl Hash for Vector2Vec {
1964    fn hash<H: Hasher>(&self, state: &mut H) {
1965        self.0.len().hash(state);
1966        for vector in &self.0 {
1967            // Normalize -0.0 to 0.0 for consistent hashing
1968            let x = if vector.x == 0.0 { 0.0_f32 } else { vector.x };
1969            let y = if vector.y == 0.0 { 0.0_f32 } else { vector.y };
1970            x.to_bits().hash(state);
1971            y.to_bits().hash(state);
1972        }
1973    }
1974}
1975
1976#[cfg(all(feature = "vector3", feature = "vec_variants"))]
1977impl Hash for Vector3Vec {
1978    fn hash<H: Hasher>(&self, state: &mut H) {
1979        self.0.len().hash(state);
1980        for vector in &self.0 {
1981            // Normalize -0.0 to 0.0 for consistent hashing
1982            let x = if vector.x == 0.0 { 0.0_f32 } else { vector.x };
1983            let y = if vector.y == 0.0 { 0.0_f32 } else { vector.y };
1984            let z = if vector.z == 0.0 { 0.0_f32 } else { vector.z };
1985            x.to_bits().hash(state);
1986            y.to_bits().hash(state);
1987            z.to_bits().hash(state);
1988        }
1989    }
1990}
1991
1992#[cfg(all(feature = "matrix3", feature = "vec_variants"))]
1993impl Hash for Matrix3Vec {
1994    fn hash<H: Hasher>(&self, state: &mut H) {
1995        self.0.len().hash(state);
1996        for matrix in &self.0 {
1997            for &element in matrix.iter() {
1998                // Normalize -0.0 to 0.0 for consistent hashing
1999                let normalized = if element == 0.0 { 0.0_f32 } else { element };
2000                normalized.to_bits().hash(state);
2001            }
2002        }
2003    }
2004}
2005
2006// Hash implementations for new types
2007#[cfg(feature = "normal3")]
2008impl Hash for Normal3 {
2009    fn hash<H: Hasher>(&self, state: &mut H) {
2010        // Normalize -0.0 to 0.0 for consistent hashing
2011        let x = if self.0.x == 0.0 { 0.0_f32 } else { self.0.x };
2012        let y = if self.0.y == 0.0 { 0.0_f32 } else { self.0.y };
2013        let z = if self.0.z == 0.0 { 0.0_f32 } else { self.0.z };
2014        x.to_bits().hash(state);
2015        y.to_bits().hash(state);
2016        z.to_bits().hash(state);
2017    }
2018}
2019
2020#[cfg(feature = "point3")]
2021impl Hash for Point3 {
2022    fn hash<H: Hasher>(&self, state: &mut H) {
2023        // Normalize -0.0 to 0.0 for consistent hashing
2024        let x = if self.0.x == 0.0 { 0.0_f32 } else { self.0.x };
2025        let y = if self.0.y == 0.0 { 0.0_f32 } else { self.0.y };
2026        let z = if self.0.z == 0.0 { 0.0_f32 } else { self.0.z };
2027        x.to_bits().hash(state);
2028        y.to_bits().hash(state);
2029        z.to_bits().hash(state);
2030    }
2031}
2032
2033#[cfg(feature = "matrix4")]
2034impl Hash for Matrix4 {
2035    fn hash<H: Hasher>(&self, state: &mut H) {
2036        for &element in self.0.iter() {
2037            // Normalize -0.0 to 0.0 for consistent hashing
2038            let normalized = if element == 0.0 { 0.0_f64 } else { element };
2039            normalized.to_bits().hash(state);
2040        }
2041    }
2042}
2043
2044#[cfg(all(feature = "normal3", feature = "vec_variants"))]
2045impl Hash for Normal3Vec {
2046    fn hash<H: Hasher>(&self, state: &mut H) {
2047        self.0.len().hash(state);
2048        for vector in &self.0 {
2049            // Normalize -0.0 to 0.0 for consistent hashing
2050            let x = if vector.x == 0.0 { 0.0_f32 } else { vector.x };
2051            let y = if vector.y == 0.0 { 0.0_f32 } else { vector.y };
2052            let z = if vector.z == 0.0 { 0.0_f32 } else { vector.z };
2053            x.to_bits().hash(state);
2054            y.to_bits().hash(state);
2055            z.to_bits().hash(state);
2056        }
2057    }
2058}
2059
2060#[cfg(all(feature = "point3", feature = "vec_variants"))]
2061impl Hash for Point3Vec {
2062    fn hash<H: Hasher>(&self, state: &mut H) {
2063        self.0.len().hash(state);
2064        for point in &self.0 {
2065            // Normalize -0.0 to 0.0 for consistent hashing
2066            let x = if point.x == 0.0 { 0.0_f32 } else { point.x };
2067            let y = if point.y == 0.0 { 0.0_f32 } else { point.y };
2068            let z = if point.z == 0.0 { 0.0_f32 } else { point.z };
2069            x.to_bits().hash(state);
2070            y.to_bits().hash(state);
2071            z.to_bits().hash(state);
2072        }
2073    }
2074}
2075
2076#[cfg(all(feature = "matrix4", feature = "vec_variants"))]
2077impl Hash for Matrix4Vec {
2078    fn hash<H: Hasher>(&self, state: &mut H) {
2079        self.0.len().hash(state);
2080        for matrix in &self.0 {
2081            for &element in matrix.iter() {
2082                // Normalize -0.0 to 0.0 for consistent hashing
2083                let normalized = if element == 0.0 { 0.0_f64 } else { element };
2084                normalized.to_bits().hash(state);
2085            }
2086        }
2087    }
2088}
2089
2090// Implement DataTypeOps for all types
2091impl_data_ops!(Integer, "integer", DataType::Integer);
2092impl_data_ops!(Real, "real", DataType::Real);
2093impl_data_ops!(Boolean, "boolean", DataType::Boolean);
2094impl_data_ops!(String, "string", DataType::String);
2095impl_data_ops!(Color, "color", DataType::Color);
2096#[cfg(feature = "vector2")]
2097impl_data_ops!(Vector2, "vec2", DataType::Vector2);
2098#[cfg(feature = "vector3")]
2099impl_data_ops!(Vector3, "vec3", DataType::Vector3);
2100#[cfg(feature = "matrix3")]
2101impl_data_ops!(Matrix3, "mat3", DataType::Matrix3);
2102
2103impl_data_ops!(IntegerVec, "integer_vec", DataType::IntegerVec);
2104impl_data_ops!(RealVec, "real_vec", DataType::RealVec);
2105impl_data_ops!(BooleanVec, "boolean_vec", DataType::BooleanVec);
2106impl_data_ops!(StringVec, "string_vec", DataType::StringVec);
2107impl_data_ops!(ColorVec, "color_vec", DataType::ColorVec);
2108
2109#[cfg(all(feature = "vector2", feature = "vec_variants"))]
2110impl_data_ops!(Vector2Vec, "vec2_vec", DataType::Vector2Vec);
2111#[cfg(all(feature = "vector3", feature = "vec_variants"))]
2112impl_data_ops!(Vector3Vec, "vec3_vec", DataType::Vector3Vec);
2113#[cfg(all(feature = "matrix3", feature = "vec_variants"))]
2114impl_data_ops!(Matrix3Vec, "mat3_vec", DataType::Matrix3Vec);
2115
2116// New data type implementations
2117#[cfg(feature = "normal3")]
2118impl_data_ops!(Normal3, "normal3", DataType::Normal3);
2119#[cfg(feature = "point3")]
2120impl_data_ops!(Point3, "point3", DataType::Point3);
2121#[cfg(feature = "matrix4")]
2122impl_data_ops!(Matrix4, "matrix4", DataType::Matrix4);
2123
2124#[cfg(all(feature = "normal3", feature = "vec_variants"))]
2125impl_data_ops!(Normal3Vec, "normal3_vec", DataType::Normal3Vec);
2126#[cfg(all(feature = "point3", feature = "vec_variants"))]
2127impl_data_ops!(Point3Vec, "point3_vec", DataType::Point3Vec);
2128#[cfg(all(feature = "matrix4", feature = "vec_variants"))]
2129impl_data_ops!(Matrix4Vec, "matrix4_vec", DataType::Matrix4Vec);
2130
2131// Macro to implement TryFrom<Value> and TryFrom<&Value> for data types using
2132// try_convert
2133macro_rules! impl_try_from_value {
2134    ($type:ty, $data_type:expr, $variant:ident) => {
2135        impl TryFrom<Value> for $type {
2136            type Error = anyhow::Error;
2137
2138            fn try_from(value: Value) -> Result<Self, Self::Error> {
2139                match value {
2140                    Value::Uniform(data) => {
2141                        let converted = data.try_convert($data_type)?;
2142                        match converted {
2143                            Data::$variant(v) => Ok(v),
2144                            _ => unreachable!(
2145                                "try_convert should return {} type",
2146                                stringify!($variant)
2147                            ),
2148                        }
2149                    }
2150                    Value::Animated(_) => Err(anyhow!(
2151                        "Cannot convert animated value to {}",
2152                        stringify!($type)
2153                    )),
2154                }
2155            }
2156        }
2157
2158        impl TryFrom<&Value> for $type {
2159            type Error = anyhow::Error;
2160
2161            fn try_from(value: &Value) -> Result<Self, Self::Error> {
2162                match value {
2163                    Value::Uniform(data) => {
2164                        let converted = data.try_convert($data_type)?;
2165                        match converted {
2166                            Data::$variant(v) => Ok(v),
2167                            _ => unreachable!(
2168                                "try_convert should return {} type",
2169                                stringify!($variant)
2170                            ),
2171                        }
2172                    }
2173                    Value::Animated(_) => Err(anyhow!(
2174                        "Cannot convert animated value to {}",
2175                        stringify!($type)
2176                    )),
2177                }
2178            }
2179        }
2180    };
2181}
2182
2183// Apply the macro to all data types
2184impl_try_from_value!(Boolean, DataType::Boolean, Boolean);
2185impl_try_from_value!(Integer, DataType::Integer, Integer);
2186impl_try_from_value!(Real, DataType::Real, Real);
2187impl_try_from_value!(String, DataType::String, String);
2188impl_try_from_value!(Color, DataType::Color, Color);
2189#[cfg(feature = "vector2")]
2190impl_try_from_value!(Vector2, DataType::Vector2, Vector2);
2191#[cfg(feature = "vector3")]
2192impl_try_from_value!(Vector3, DataType::Vector3, Vector3);
2193#[cfg(feature = "matrix3")]
2194impl_try_from_value!(Matrix3, DataType::Matrix3, Matrix3);
2195impl_try_from_value!(BooleanVec, DataType::BooleanVec, BooleanVec);
2196impl_try_from_value!(IntegerVec, DataType::IntegerVec, IntegerVec);
2197impl_try_from_value!(RealVec, DataType::RealVec, RealVec);
2198impl_try_from_value!(StringVec, DataType::StringVec, StringVec);
2199impl_try_from_value!(ColorVec, DataType::ColorVec, ColorVec);
2200#[cfg(all(feature = "vector2", feature = "vec_variants"))]
2201impl_try_from_value!(Vector2Vec, DataType::Vector2Vec, Vector2Vec);
2202#[cfg(all(feature = "vector3", feature = "vec_variants"))]
2203impl_try_from_value!(Vector3Vec, DataType::Vector3Vec, Vector3Vec);
2204#[cfg(all(feature = "matrix3", feature = "vec_variants"))]
2205impl_try_from_value!(Matrix3Vec, DataType::Matrix3Vec, Matrix3Vec);
2206
2207// New type TryFrom implementations
2208#[cfg(feature = "normal3")]
2209impl_try_from_value!(Normal3, DataType::Normal3, Normal3);
2210#[cfg(feature = "point3")]
2211impl_try_from_value!(Point3, DataType::Point3, Point3);
2212#[cfg(feature = "matrix4")]
2213impl_try_from_value!(Matrix4, DataType::Matrix4, Matrix4);
2214
2215#[cfg(all(feature = "normal3", feature = "vec_variants"))]
2216impl_try_from_value!(Normal3Vec, DataType::Normal3Vec, Normal3Vec);
2217#[cfg(all(feature = "point3", feature = "vec_variants"))]
2218impl_try_from_value!(Point3Vec, DataType::Point3Vec, Point3Vec);
2219#[cfg(all(feature = "matrix4", feature = "vec_variants"))]
2220impl_try_from_value!(Matrix4Vec, DataType::Matrix4Vec, Matrix4Vec);