add into/from cgmath vec3

This commit is contained in:
Robin Appelman 2022-12-05 22:54:03 +01:00
commit 92a15fb4db
2 changed files with 29 additions and 7 deletions

View file

@ -6,16 +6,17 @@ exclude = ["data"]
[dependencies] [dependencies]
arrayvec = "0.7.2" arrayvec = "0.7.2"
thiserror = "1.0.30" thiserror = "1.0.37"
static_assertions = "1.1.0" static_assertions = "1.1.0"
bitflags = "1.0.4" bitflags = "1.3.2"
itertools = "0.10.3" itertools = "0.10.5"
tracing = "0.1.29" tracing = "0.1.37"
bytemuck = { version = "1.8.0", features = ["derive"] } bytemuck = { version = "1.12.3", features = ["derive"] }
cgmath = "0.18.0"
[dev-dependencies] [dev-dependencies]
three-d = "0.10.2" three-d = "0.10.2"
miette = { version = "4.2.1", features = ["fancy"] } miette = { version = "4.7.1", features = ["fancy"] }
criterion = "0.3" criterion = "0.3"
iai = "0.1" iai = "0.1"
@ -25,4 +26,4 @@ harness = false
[[bench]] [[bench]]
name = "iai" name = "iai"
harness = false harness = false

View file

@ -4,6 +4,7 @@ use bytemuck::{Pod, Zeroable};
use std::fmt; use std::fmt;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
use std::ops::Add; use std::ops::Add;
use cgmath::Vector3;
#[derive(Debug, Clone, Copy, Zeroable, Pod)] #[derive(Debug, Clone, Copy, Zeroable, Pod)]
#[repr(C)] #[repr(C)]
@ -13,6 +14,26 @@ pub struct Vector {
pub z: f32, pub z: f32,
} }
impl From<Vector> for Vector3<f32> {
fn from(v: Vector) -> Self {
Self {
x: v.x,
y: v.y,
z: v.z,
}
}
}
impl From<Vector3<f32>> for Vector {
fn from(v: Vector3<f32>) -> Self {
Self {
x: v.x,
y: v.y,
z: v.z,
}
}
}
impl Vector { impl Vector {
pub fn iter(&self) -> impl Iterator<Item = f32> { pub fn iter(&self) -> impl Iterator<Item = f32> {
[self.x, self.y, self.z].into_iter() [self.x, self.y, self.z].into_iter()