package me.hammerle.supersnuvi.util;

import me.hammerle.supersnuvi.javafx.Image;
import me.hammerle.supersnuvi.javafx.ResourceImage;
import me.hammerle.supersnuvi.javafx.WritableImage;
import me.hammerle.supersnuvi.rendering.Game;

public class Utils 
{
    public static double round(double d)
    {
        return Math.round(d * 10000) / 10000d;
    }
    
    public static double interpolateY(double x1, double y1, double x2, double y2, double x3)
    {
        double k = (y2 - y1) / (x2 - x1);
        return k * x3 + y1 - k * x1;
    }
    
    public static double interpolateX(double x1, double y1, double x2, double y2, double y3)
    {
        double k = (x2 - x1) / (y2 - y1);
        return (y3 - y1) * k + x1;
    }
    
    public static Image getColoredImage(int r, int g, int b, int alpha, int width, int height)
    {       
        WritableImage image = new WritableImage(width, height);
        image.clear(r, g, b, alpha);
        return image;
    }
    
    public static Image getImage(String path)
    {
        ResourceImage image = new ResourceImage();
        image.load("resources/" + path + ".png");
        return image;
    }
    
    public static Image getTileImage(String path)
    {
        ResourceImage image = new ResourceImage();
        image.load("resources/" + path + ".png", Game.TILE_SIZE, Game.TILE_SIZE);
        return image;
    }
}
