From 8b5052865c2800f13055b03714676dd5eb8e1651 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Thu, 21 Dec 2023 16:34:38 +0100 Subject: [PATCH] Remove barely used utility classes --- .../glpreview/buffered/BufferedGLPanel.java | 3 +- .../Heightmap3DGLPreviewBufferedGL.java | 16 +++++-- src/main/java/net/worldsynth/util/Arrays.java | 48 ------------------- .../util/math/MathHelperScalar.java | 22 --------- 4 files changed, 13 insertions(+), 76 deletions(-) delete mode 100644 src/main/java/net/worldsynth/util/Arrays.java delete mode 100644 src/main/java/net/worldsynth/util/math/MathHelperScalar.java diff --git a/src/main/java/net/worldsynth/glpreview/buffered/BufferedGLPanel.java b/src/main/java/net/worldsynth/glpreview/buffered/BufferedGLPanel.java index f781f42..ec620fc 100644 --- a/src/main/java/net/worldsynth/glpreview/buffered/BufferedGLPanel.java +++ b/src/main/java/net/worldsynth/glpreview/buffered/BufferedGLPanel.java @@ -16,7 +16,6 @@ import net.worldsynth.glpreview.Commons; import net.worldsynth.glpreview.buffered.Shader.ShaderType; import net.worldsynth.glpreview.model.AbstractModel; -import net.worldsynth.util.math.MathHelperScalar; import javax.swing.SwingUtilities; import java.awt.event.MouseEvent; @@ -279,7 +278,7 @@ public void mouseDragged(MouseEvent e) { display(); } else if(SwingUtilities.isMiddleMouseButton(e)) { yLookatHeight += (y - lastMouseY) * -zoom * 0.2f; - yLookatHeight = MathHelperScalar.clamp(yLookatHeight, minYLookatHeight, maxYLookatHeight); + yLookatHeight = Math.min(Math.max(yLookatHeight, minYLookatHeight), maxYLookatHeight); display(); } else if(SwingUtilities.isRightMouseButton(e)) { float lightDist = 5000; diff --git a/src/main/java/net/worldsynth/glpreview/heightmap/Heightmap3DGLPreviewBufferedGL.java b/src/main/java/net/worldsynth/glpreview/heightmap/Heightmap3DGLPreviewBufferedGL.java index c848801..0a84d2b 100644 --- a/src/main/java/net/worldsynth/glpreview/heightmap/Heightmap3DGLPreviewBufferedGL.java +++ b/src/main/java/net/worldsynth/glpreview/heightmap/Heightmap3DGLPreviewBufferedGL.java @@ -9,8 +9,6 @@ import com.jogamp.opengl.GLCapabilities; import com.jogamp.opengl.GLProfile; import net.worldsynth.glpreview.buffered.BufferedGLPanel; -import net.worldsynth.util.Arrays; -import net.worldsynth.util.math.MathHelperScalar; public class Heightmap3DGLPreviewBufferedGL extends BufferedGLPanel { @@ -49,7 +47,17 @@ public void setHeightmap(float[][] heightmap, double size, float normalizedHeigh } public void setHeightmap(double[][] heightmap, double size, float normalizedHeight) { - setHeightmap(Arrays.cast2f(heightmap), size, normalizedHeight); + setHeightmap(cast2f(heightmap), size, normalizedHeight); + } + + private float[][] cast2f(double[][] array2d) { + float[][] array2f = new float[array2d.length][array2d[0].length]; + for(int i = 0, width = array2d.length; i < width; i++) { + for(int j = 0, length = array2d[0].length; j < length; j++) { + array2f[i][j] = (float) array2d[i][j]; + } + } + return array2f; } public void setColorscale(float[][] colorscale) { @@ -71,7 +79,7 @@ private float[][][] colormapFromHeightmap(float[][] heightmap, float normalizedH } private float[] heightToColor(float height, float normalizedHeight) { - height = MathHelperScalar.clamp(height, 0.0f, normalizedHeight) / normalizedHeight; + height = Math.min(Math.max(height, 0.0f), normalizedHeight) / normalizedHeight; float[] lowRange = colorscale[0]; float[] highRange = colorscale[1]; diff --git a/src/main/java/net/worldsynth/util/Arrays.java b/src/main/java/net/worldsynth/util/Arrays.java deleted file mode 100644 index d0f9fc3..0000000 --- a/src/main/java/net/worldsynth/util/Arrays.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -package net.worldsynth.util; - -public class Arrays { - - public static float[][] fill(float[][] array2d, float d) { - for(int i = 0, width = array2d.length; i < width; i++) { - for(int j = 0, length = array2d[0].length; j < length; j++) { - array2d[i][j] = d; - } - } - return array2d; - } - - public static double[][] fill(double[][] array2d, double d) { - for(int i = 0, width = array2d.length; i < width; i++) { - for(int j = 0, length = array2d[0].length; j < length; j++) { - array2d[i][j] = d; - } - } - return array2d; - } - - public static double[][] cast2d(float[][] array2f) { - double[][] array2d = new double[array2f.length][array2f[0].length]; - for(int i = 0, width = array2f.length; i < width; i++) { - for(int j = 0, length = array2f[0].length; j < length; j++) { - array2d[i][j] = array2f[i][j]; - } - } - return array2d; - } - - public static float[][] cast2f(double[][] array2d) { - float[][] array2f = new float[array2d.length][array2d[0].length]; - for(int i = 0, width = array2d.length; i < width; i++) { - for(int j = 0, length = array2d[0].length; j < length; j++) { - array2f[i][j] = (float) array2d[i][j]; - } - } - return array2f; - } -} diff --git a/src/main/java/net/worldsynth/util/math/MathHelperScalar.java b/src/main/java/net/worldsynth/util/math/MathHelperScalar.java deleted file mode 100644 index ce63b50..0000000 --- a/src/main/java/net/worldsynth/util/math/MathHelperScalar.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -package net.worldsynth.util.math; - -public class MathHelperScalar { - - public static double clamp(double a, double min, double max) { - return Math.min(Math.max(a, min), max); - } - - public static float clamp(float a, float min, float max) { - return Math.min(Math.max(a, min), max); - } - - public static boolean isPositivePowerOfTwo(int number) { - return number > 0 && ((number & (number - 1)) == 0); - } -}