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

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