rust impl
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 line
880 B

  1. use mint::Point2;
  2. pub struct IsometricVector2(Point2<f32>);
  3. impl IsometricVector2 {
  4. pub fn x(&self) -> f32 {
  5. self.0.x
  6. }
  7. pub fn y(&self) -> f32 {
  8. self.0.y
  9. }
  10. }
  11. impl From<Point2<f32>> for IsometricVector2 {
  12. fn from(cart: Point2<f32>) -> IsometricVector2 {
  13. let x = cart.x - cart.y;
  14. let y = (cart.x + cart.y) / 2.0;
  15. IsometricVector2(Point2 { x, y })
  16. }
  17. }
  18. impl Into<Point2<f32>> for IsometricVector2 {
  19. fn into(self) -> Point2<f32> {
  20. let x = (2.0 * self.y() + self.x()) / 2.0;
  21. let y = (2.0 * self.y() - self.x()) / 2.0;
  22. Point2 { x, y }
  23. }
  24. }
  25. impl<T> From<(T, T)> for IsometricVector2
  26. where
  27. T: std::convert::Into<f32>,
  28. {
  29. fn from(tuple: (T, T)) -> IsometricVector2 {
  30. IsometricVector2(Point2 {
  31. x: tuple.0.into(),
  32. y: tuple.1.into(),
  33. })
  34. }
  35. }