Compare commits
2 Commits
md-generic
...
ga-euclide
| Author | SHA1 | Date | |
|---|---|---|---|
|
41a02e7b3c
|
|||
|
4637891a21
|
45
lib/common/src/euclidean_point.rs
Normal file
45
lib/common/src/euclidean_point.rs
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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