mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-03 05:45:57 +00:00
Make access to vector coordinates more convenient
This commit is contained in:
parent
f1a82fcea1
commit
07993cb5c1
@ -1,6 +1,9 @@
|
|||||||
use std::ops;
|
use std::ops;
|
||||||
|
|
||||||
use super::Scalar;
|
use super::{
|
||||||
|
coordinates::{Uv, Xyz, T},
|
||||||
|
Scalar,
|
||||||
|
};
|
||||||
|
|
||||||
/// An n-dimensional vector
|
/// An n-dimensional vector
|
||||||
///
|
///
|
||||||
@ -106,6 +109,72 @@ impl Vector<3> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ops::Deref for Vector<1> {
|
||||||
|
type Target = T;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
let ptr = self.0.as_ptr() as *const Self::Target;
|
||||||
|
|
||||||
|
// This is sound. We've created this pointer from a valid instance, that
|
||||||
|
// has the same size and layout as the target.
|
||||||
|
unsafe { &*ptr }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ops::Deref for Vector<2> {
|
||||||
|
type Target = Uv;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
let ptr = self.0.as_ptr() as *const Self::Target;
|
||||||
|
|
||||||
|
// This is sound. We've created this pointer from a valid instance, that
|
||||||
|
// has the same size and layout as the target.
|
||||||
|
unsafe { &*ptr }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ops::Deref for Vector<3> {
|
||||||
|
type Target = Xyz;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
let ptr = self.0.as_ptr() as *const Self::Target;
|
||||||
|
|
||||||
|
// This is sound. We've created this pointer from a valid instance, that
|
||||||
|
// has the same size and layout as the target.
|
||||||
|
unsafe { &*ptr }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ops::DerefMut for Vector<1> {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
let ptr = self.0.as_mut_ptr() as *mut Self::Target;
|
||||||
|
|
||||||
|
// This is sound. We've created this pointer from a valid instance, that
|
||||||
|
// has the same size and layout as the target.
|
||||||
|
unsafe { &mut *ptr }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ops::DerefMut for Vector<2> {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
let ptr = self.0.as_mut_ptr() as *mut Self::Target;
|
||||||
|
|
||||||
|
// This is sound. We've created this pointer from a valid instance, that
|
||||||
|
// has the same size and layout as the target.
|
||||||
|
unsafe { &mut *ptr }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ops::DerefMut for Vector<3> {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
let ptr = self.0.as_mut_ptr() as *mut Self::Target;
|
||||||
|
|
||||||
|
// This is sound. We've created this pointer from a valid instance, that
|
||||||
|
// has the same size and layout as the target.
|
||||||
|
unsafe { &mut *ptr }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<const D: usize> From<[Scalar; D]> for Vector<D> {
|
impl<const D: usize> From<[Scalar; D]> for Vector<D> {
|
||||||
fn from(array: [Scalar; D]) -> Self {
|
fn from(array: [Scalar; D]) -> Self {
|
||||||
Self(array)
|
Self(array)
|
||||||
|
Loading…
Reference in New Issue
Block a user