Compare commits
4 Commits
strafe-sta
...
ga-euclide
| Author | SHA1 | Date | |
|---|---|---|---|
|
6f99aa5385
|
|||
|
bad895ef54
|
|||
|
41a02e7b3c
|
|||
|
4637891a21
|
46
lib/common/src/euclidean_point.rs
Normal file
46
lib/common/src/euclidean_point.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
/// 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
|
||||
|
||||
// This can be used for both Position and Time
|
||||
pub struct Absolute<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 Absolute<P>{
|
||||
type Output=Absolute<P::Output>;
|
||||
fn add(self,rhs:P)->Self::Output{
|
||||
Absolute(self.0+rhs)
|
||||
}
|
||||
}
|
||||
impl<P:Sub> Sub<P> for Absolute<P>{
|
||||
type Output=Absolute<P::Output>;
|
||||
fn sub(self,rhs:P)->Self::Output{
|
||||
Absolute(self.0-rhs)
|
||||
}
|
||||
}
|
||||
impl<P:AddAssign> AddAssign<P> for Absolute<P>{
|
||||
fn add_assign(&mut self,rhs:P){
|
||||
self.0+=rhs;
|
||||
}
|
||||
}
|
||||
impl<P:SubAssign> SubAssign<P> for Absolute<P>{
|
||||
fn sub_assign(&mut self,rhs:P){
|
||||
self.0-=rhs;
|
||||
}
|
||||
}
|
||||
|
||||
// Extract ideal point from euclidean point
|
||||
impl<P:Sub> Sub for Absolute<P>{
|
||||
type Output=P::Output;
|
||||
fn sub(self,rhs:Absolute<P>)->Self::Output{
|
||||
self.0-rhs.0
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user