Utils.java 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package me.hammerle.supersnuvi.util;
  2. import me.hammerle.supersnuvi.tiles.Tile;
  3. public class Utils
  4. {
  5. public static float round(float d)
  6. {
  7. return Math.round(d * 10000) / 10000f;
  8. }
  9. public static float interpolate(float from, float to, float factor)
  10. {
  11. return from + (to - from) * factor;
  12. }
  13. public static float interpolateY(float x1, float y1, float x2, float y2, float x3)
  14. {
  15. float k = (y2 - y1) / (x2 - x1);
  16. return k * x3 + y1 - k * x1;
  17. }
  18. public static float interpolateX(float x1, float y1, float x2, float y2, float y3)
  19. {
  20. float k = (x2 - x1) / (y2 - y1);
  21. return (y3 - y1) * k + x1;
  22. }
  23. public static int toBlock(float c)
  24. {
  25. return (int) (c / Tile.SIZE);
  26. }
  27. public static float toCoord(int b)
  28. {
  29. return b * Tile.SIZE;
  30. }
  31. public static float getSquaredDistance(float x1, float y1, float x2, float y2)
  32. {
  33. return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
  34. }
  35. }