All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pepsoft.worldpainter.util.MathUtils Maven / Gradle / Ivy

There is a newer version: 2.23.2
Show newest version
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.pepsoft.worldpainter.util;

import static org.pepsoft.worldpainter.Constants.*;

/**
 *
 * @author pepijn
 */
public final class MathUtils {
    private MathUtils() {
        // Prevent instantiation
    }
    
    public static float getSmallestDistanceFromOrigin(int x, int y) {
        return Math.min(
            Math.min(org.pepsoft.util.MathUtils.getDistance(x * TILE_SIZE + 0.5f, y * TILE_SIZE + 0.5f),
                org.pepsoft.util.MathUtils.getDistance(x * TILE_SIZE + TILE_SIZE - 0.5f, y * TILE_SIZE + 0.5f)),
            Math.min(org.pepsoft.util.MathUtils.getDistance(x * TILE_SIZE + 0.5f, y * TILE_SIZE + TILE_SIZE - 0.5f),
                org.pepsoft.util.MathUtils.getDistance(x * TILE_SIZE + TILE_SIZE - 0.5f, y * TILE_SIZE + TILE_SIZE - 0.5f)));
    }

    public static float getLargestDistanceFromOrigin(int x, int y) {
        return Math.max(
            Math.max(org.pepsoft.util.MathUtils.getDistance(x * TILE_SIZE, y * TILE_SIZE),
                org.pepsoft.util.MathUtils.getDistance(x * TILE_SIZE + TILE_SIZE - 1, y * TILE_SIZE)),
            Math.max(org.pepsoft.util.MathUtils.getDistance(x * TILE_SIZE, y * TILE_SIZE + TILE_SIZE - 1),
                org.pepsoft.util.MathUtils.getDistance(x * TILE_SIZE + TILE_SIZE - 1, y * TILE_SIZE + TILE_SIZE - 1)));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy