From 78869fc84f49df129e1aefca2321944e1f04b3b0 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 22 Mar 2022 12:26:30 +0900 Subject: [PATCH] just some silly math functions --- src/com/jme3/math/FastMath.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/com/jme3/math/FastMath.java b/src/com/jme3/math/FastMath.java index f06424615..54168198f 100644 --- a/src/com/jme3/math/FastMath.java +++ b/src/com/jme3/math/FastMath.java @@ -895,4 +895,30 @@ final public class FastMath { for (int i = 1; i < f.length; i++) max = (f[i] > max) ? f[i] : max; return max; } + + public static int getGCD(int a, int b) { + while (a != b) { + if (a > b) a = a-b; + else b = b-a; + } + return a; + } + + public static long getGCD(long a, long b) { + while (a != b) { + if (a > b) a = a-b; + else b = b-a; + } + return a; + } + + public static int[] getRatioOf(int a, int b) { + int factor = getGCD(a, b); + return new int[]{a / factor, b / factor}; + } + + public static long[] getRatioOf(long a, long b) { + long factor = getGCD(a, b); + return new long[]{a / factor, b / factor}; + } }