Make access to point coordinates more convenient

This commit is contained in:
Hanno Braun 2022-02-20 13:30:46 +01:00
parent fee466e3e5
commit 1e33846f93

View File

@ -1,6 +1,9 @@
use std::ops;
use super::{Scalar, Vector};
use super::{
coordinates::{Uv, Xyz, T},
Scalar, Vector,
};
/// An n-dimensional point
///
@ -91,6 +94,48 @@ impl Point<3> {
}
}
impl ops::Deref for Point<1> {
type Target = T;
fn deref(&self) -> &Self::Target {
self.coords.deref()
}
}
impl ops::Deref for Point<2> {
type Target = Uv;
fn deref(&self) -> &Self::Target {
self.coords.deref()
}
}
impl ops::Deref for Point<3> {
type Target = Xyz;
fn deref(&self) -> &Self::Target {
self.coords.deref()
}
}
impl ops::DerefMut for Point<1> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.coords.deref_mut()
}
}
impl ops::DerefMut for Point<2> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.coords.deref_mut()
}
}
impl ops::DerefMut for Point<3> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.coords.deref_mut()
}
}
impl<const D: usize> From<[Scalar; D]> for Point<D> {
fn from(array: [Scalar; D]) -> Self {
Self {