|
- use mint::Point2;
-
- pub struct IsometricVector2(Point2<f32>);
-
- impl IsometricVector2 {
- pub fn x(&self) -> f32 {
- self.0.x
- }
-
- pub fn y(&self) -> f32 {
- self.0.y
- }
- }
-
- impl From<Point2<f32>> for IsometricVector2 {
- fn from(cart: Point2<f32>) -> IsometricVector2 {
- let x = cart.x - cart.y;
- let y = (cart.x + cart.y) / 2.0;
- IsometricVector2(Point2 { x, y })
- }
- }
-
- impl Into<Point2<f32>> for IsometricVector2 {
- fn into(self) -> Point2<f32> {
- let x = (2.0 * self.y() + self.x()) / 2.0;
- let y = (2.0 * self.y() - self.x()) / 2.0;
- Point2 { x, y }
- }
- }
-
- impl<T> From<(T, T)> for IsometricVector2
- where
- T: std::convert::Into<f32>,
- {
- fn from(tuple: (T, T)) -> IsometricVector2 {
- IsometricVector2(Point2 {
- x: tuple.0.into(),
- y: tuple.1.into(),
- })
- }
- }
|