Compare commits

...

2 Commits

Author SHA1 Message Date
41a02e7b3c notes 2025-11-27 15:07:24 -08:00
4637891a21 euclidean point 2025-11-27 15:06:18 -08:00
2 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
/// Euclidean point.
/// Newtype of ideal point.
/// Euclidean points can be offset by ideal points to create a new euclidean point.
/// Two euclidean points cannot be added together.
/// Subtracting two euclidean points gives an ideal point.
// TODO: Affine*Point translates but Affine*Vector does not translate
pub struct Point<P>(P);
use core::ops::Add;
use core::ops::Sub;
use core::ops::AddAssign;
use core::ops::SubAssign;
// Offset euclidean point by ideal point
impl<P:Add> Add<P> for Point<P>{
type Output=Point<P::Output>;
fn add(self,rhs:P)->Self::Output{
Point(self.0+rhs)
}
}
impl<P:Sub> Sub<P> for Point<P>{
type Output=Point<P::Output>;
fn sub(self,rhs:P)->Self::Output{
Point(self.0-rhs)
}
}
impl<P:AddAssign> AddAssign<P> for Point<P>{
fn add_assign(&mut self,rhs:P){
self.0+=rhs;
}
}
impl<P:SubAssign> SubAssign<P> for Point<P>{
fn sub_assign(&mut self,rhs:P){
self.0-=rhs;
}
}
// Extract ideal point from euclidean point
impl<P:Sub> Sub for Point<P>{
type Output=P::Output;
fn sub(self,rhs:Point<P>)->Self::Output{
self.0-rhs.0
}
}

View File

@@ -5,6 +5,7 @@ pub mod run;
pub mod aabb;
pub mod model;
pub mod mouse;
pub mod euclidean_point;
pub mod timer;
pub mod integer;
pub mod physics;