From 1e33846f934be096a61e926ebb21d0e1bcb47c65 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sun, 20 Feb 2022 13:30:46 +0100 Subject: [PATCH] Make access to point coordinates more convenient --- src/math/point.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/math/point.rs b/src/math/point.rs index 0664479d7..f43620eb7 100644 --- a/src/math/point.rs +++ b/src/math/point.rs @@ -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 From<[Scalar; D]> for Point { fn from(array: [Scalar; D]) -> Self { Self {