12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package me.hammerle.supersnuvi.util;
- import me.hammerle.supersnuvi.tiles.Tile;
- public class Utils
- {
- public static float round(float d)
- {
- return Math.round(d * 10000) / 10000f;
- }
-
- public static float interpolate(float from, float to, float factor)
- {
- return from + (to - from) * factor;
- }
-
- public static float interpolateY(float x1, float y1, float x2, float y2, float x3)
- {
- float k = (y2 - y1) / (x2 - x1);
- return k * x3 + y1 - k * x1;
- }
-
- public static float interpolateX(float x1, float y1, float x2, float y2, float y3)
- {
- float k = (x2 - x1) / (y2 - y1);
- return (y3 - y1) * k + x1;
- }
-
- public static int toBlock(float c)
- {
- return (int) (c / Tile.SIZE);
- }
- public static float toCoord(int b)
- {
- return b * Tile.SIZE;
- }
-
- public static float getSquaredDistance(float x1, float y1, float x2, float y2)
- {
- return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
- }
- }
|