| 1 |
use alga::general::{ |
| 2 |
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, |
| 3 |
AbstractSemigroup, Id, Identity, Multiplicative, RealField, TwoSidedInverse, |
| 4 |
}; |
| 5 |
use alga::linear::{ |
| 6 |
AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation, |
| 7 |
ProjectiveTransformation, Rotation, Similarity, Transformation, |
| 8 |
}; |
| 9 |
|
| 10 |
use crate::base::Vector2; |
| 11 |
use crate::geometry::{Point2, UnitComplex}; |
| 12 |
|
| 13 |
/* |
| 14 |
* |
| 15 |
* Implementations for UnitComplex. |
| 16 |
* |
| 17 |
*/ |
| 18 |
impl<T: RealField + simba::scalar::RealField> Identity<Multiplicative> for UnitComplex<T> { |
| 19 |
#[inline] |
| 20 |
fn identity() -> Self { |
| 21 |
Self::identity() |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
impl<T: RealField + simba::scalar::RealField> AbstractMagma<Multiplicative> for UnitComplex<T> { |
| 26 |
#[inline] |
| 27 |
fn operate(&self, rhs: &Self) -> Self { |
| 28 |
self * rhs |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
impl<T: RealField + simba::scalar::RealField> TwoSidedInverse<Multiplicative> for UnitComplex<T> { |
| 33 |
#[inline] |
| 34 |
fn two_sided_inverse(&self) -> Self { |
| 35 |
self.inverse() |
| 36 |
} |
| 37 |
|
| 38 |
#[inline] |
| 39 |
fn two_sided_inverse_mut(&mut self) { |
| 40 |
self.inverse_mut() |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
macro_rules! impl_structures( |
| 45 |
($($marker: ident<$operator: ident>),* $(,)*) => {$( |
| 46 |
impl<T: RealField + simba::scalar::RealField> $marker<$operator> for UnitComplex<T> { |
| 47 |
} |
| 48 |
)*} |
| 49 |
); |
| 50 |
|
| 51 |
impl_structures!( |
| 52 |
AbstractSemigroup<Multiplicative>, |
| 53 |
AbstractQuasigroup<Multiplicative>, |
| 54 |
AbstractMonoid<Multiplicative>, |
| 55 |
AbstractLoop<Multiplicative>, |
| 56 |
AbstractGroup<Multiplicative> |
| 57 |
); |
| 58 |
|
| 59 |
impl<T: RealField + simba::scalar::RealField> Transformation<Point2<T>> for UnitComplex<T> { |
| 60 |
#[inline] |
| 61 |
fn transform_point(&self, pt: &Point2<T>) -> Point2<T> { |
| 62 |
self.transform_point(pt) |
| 63 |
} |
| 64 |
|
| 65 |
#[inline] |
| 66 |
fn transform_vector(&self, v: &Vector2<T>) -> Vector2<T> { |
| 67 |
self.transform_vector(v) |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
impl<T: RealField + simba::scalar::RealField> ProjectiveTransformation<Point2<T>> |
| 72 |
for UnitComplex<T> |
| 73 |
{ |
| 74 |
#[inline] |
| 75 |
fn inverse_transform_point(&self, pt: &Point2<T>) -> Point2<T> { |
| 76 |
self.inverse_transform_point(pt) |
| 77 |
} |
| 78 |
|
| 79 |
#[inline] |
| 80 |
fn inverse_transform_vector(&self, v: &Vector2<T>) -> Vector2<T> { |
| 81 |
self.inverse_transform_vector(v) |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
impl<T: RealField + simba::scalar::RealField> AffineTransformation<Point2<T>> for UnitComplex<T> { |
| 86 |
type Rotation = Self; |
| 87 |
type NonUniformScaling = Id; |
| 88 |
type Translation = Id; |
| 89 |
|
| 90 |
#[inline] |
| 91 |
fn decompose(&self) -> (Id, Self, Id, Self) { |
| 92 |
(Id::new(), *self, Id::new(), Self::identity()) |
| 93 |
} |
| 94 |
|
| 95 |
#[inline] |
| 96 |
fn append_translation(&self, _: &Self::Translation) -> Self { |
| 97 |
*self |
| 98 |
} |
| 99 |
|
| 100 |
#[inline] |
| 101 |
fn prepend_translation(&self, _: &Self::Translation) -> Self { |
| 102 |
*self |
| 103 |
} |
| 104 |
|
| 105 |
#[inline] |
| 106 |
fn append_rotation(&self, r: &Self::Rotation) -> Self { |
| 107 |
r * self |
| 108 |
} |
| 109 |
|
| 110 |
#[inline] |
| 111 |
fn prepend_rotation(&self, r: &Self::Rotation) -> Self { |
| 112 |
self * r |
| 113 |
} |
| 114 |
|
| 115 |
#[inline] |
| 116 |
fn append_scaling(&self, _: &Self::NonUniformScaling) -> Self { |
| 117 |
*self |
| 118 |
} |
| 119 |
|
| 120 |
#[inline] |
| 121 |
fn prepend_scaling(&self, _: &Self::NonUniformScaling) -> Self { |
| 122 |
*self |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
impl<T: RealField + simba::scalar::RealField> Similarity<Point2<T>> for UnitComplex<T> { |
| 127 |
type Scaling = Id; |
| 128 |
|
| 129 |
#[inline] |
| 130 |
fn translation(&self) -> Id { |
| 131 |
Id::new() |
| 132 |
} |
| 133 |
|
| 134 |
#[inline] |
| 135 |
fn rotation(&self) -> Self { |
| 136 |
*self |
| 137 |
} |
| 138 |
|
| 139 |
#[inline] |
| 140 |
fn scaling(&self) -> Id { |
| 141 |
Id::new() |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
macro_rules! marker_impl( |
| 146 |
($($Trait: ident),*) => {$( |
| 147 |
impl<T: RealField + simba::scalar::RealField> $Trait<Point2<T>> for UnitComplex<T> |
| 148 |
{ } |
| 149 |
)*} |
| 150 |
); |
| 151 |
|
| 152 |
marker_impl!(Isometry, DirectIsometry, OrthogonalTransformation); |
| 153 |
|
| 154 |
impl<T: RealField + simba::scalar::RealField> Rotation<Point2<T>> for UnitComplex<T> { |
| 155 |
#[inline] |
| 156 |
fn powf(&self, n: T) -> Option<Self> { |
| 157 |
Some(self.powf(n)) |
| 158 |
} |
| 159 |
|
| 160 |
#[inline] |
| 161 |
fn rotation_between(a: &Vector2<T>, b: &Vector2<T>) -> Option<Self> { |
| 162 |
Some(Self::rotation_between(a, b)) |
| 163 |
} |
| 164 |
|
| 165 |
#[inline] |
| 166 |
fn scaled_rotation_between(a: &Vector2<T>, b: &Vector2<T>, s: T) -> Option<Self> { |
| 167 |
Some(Self::scaled_rotation_between(a, b, s)) |
| 168 |
} |
| 169 |
} |