diff --git a/documentation/modifiers.md b/documentation/modifiers.md index 9224707b..184c27d2 100644 --- a/documentation/modifiers.md +++ b/documentation/modifiers.md @@ -99,6 +99,7 @@ desired effects. * **PushPullModifier:** Pushes or pulls vertices towards or away from a specified center point. * **RandomHolesModifier:** * **RemoveDoubleVerticesModifier:** Removes duplicate vertices from the mesh. +* **RippleModifier:** Applies a ripple effect based on sinusoidal wave functions. * **RotateXModifier:** Rotates the mesh around the X-axis. * **RotateYModifier:** Rotates the mesh around the Y-axis. * **RotateZModifier:** Rotates the mesh around the Z-axis. @@ -109,6 +110,7 @@ desired effects. * **SpherifyModifier:** Spherifies the mesh. * **TranslateModifier:** Translates the mesh. * **UpdateFaceNormalsModifier** Updates the face normals of the mesh. +* **WaveModifier:** Applies a wave-like deformation, simulating the appearance of sinusoidal wave. * **WireframeModifier:** Converts the mesh to a wireframe representation. ## Subdivision Modifiers diff --git a/src/main/java/math/Color.java b/src/main/java/math/Color.java index 49109681..c6b0ffab 100644 --- a/src/main/java/math/Color.java +++ b/src/main/java/math/Color.java @@ -325,10 +325,10 @@ public Color subtractLocal(float r, float g, float b, float a) { * @return this */ public Color divideLocal(float a) { - r /= a; - g /= a; - b /= a; - a /= a; + this.r /= a; + this.g /= a; + this.b /= a; + this.a /= a; return this; } diff --git a/src/main/java/math/GeometryUtil.java b/src/main/java/math/GeometryUtil.java index ee604c5d..cdc656f6 100644 --- a/src/main/java/math/GeometryUtil.java +++ b/src/main/java/math/GeometryUtil.java @@ -129,7 +129,7 @@ public static double angleBetweenVectors(Vector3f v1, Vector3f v2) { * values between 0 and 1 will return points in between. * @return The point along the line segment. */ - public Vector2f getDistributionPoint(Vector2f start, Vector2f end, + public static Vector2f getDistributionPoint(Vector2f start, Vector2f end, float lambda) { float scalar = 1f / (1f + lambda); return start.add(end.mult(lambda)).mult(scalar); diff --git a/src/main/java/math/Mathf.java b/src/main/java/math/Mathf.java index f70fb4c9..6f815973 100644 --- a/src/main/java/math/Mathf.java +++ b/src/main/java/math/Mathf.java @@ -10,948 +10,969 @@ */ public class Mathf { - /** - * A random number generator used to generate random values. - */ - private static Random random = new Random(); - - /** - * A float representation of the golden ratio, approximately 1.618. - */ - public static final float GOLDEN_RATIO = (1 + sqrt(5)) / 2.0f; - - /** - * A float representation of the reciprocal of the golden ratio, , which is - * exactly 1 less than the golden ratio itself; approximately 0.618. - */ - public static final float GOLDEN_RATIO_RECIPROCAL = 2 / (1 + sqrt(5)); - - /** - * Euler's number, the base of the natural logarithm, approximately 2.718. - */ - public static final float E = (float) Math.E; - - /** - * A representation of negative infinity. - */ - public static final float NEGATIVE_INFINITY = Float.NEGATIVE_INFINITY; - - /** - * A representation of positive infinity. - */ - public static final float POSITIVE_INFINITY = Float.POSITIVE_INFINITY; - - /** - * The smallest positive nonzero value representable as a float. - */ - public static final float MIN_VALUE = Float.MIN_VALUE; - - /** - * The largest finite value representable as a float. - */ - public static final float MAX_VALUE = Float.MAX_VALUE; - - /** - * A small value used for floating-point comparisons, approximately - * 2.22E-16. - */ - public static final double DBL_EPSILON = 2.220446049250313E-16d; - - /** - * A small value used for floating-point comparisons, approximately 1.19E-7. - */ - public static final float FLT_EPSILON = 1.1920928955078125E-7f; - - /** - * A small tolerance value for comparing floating-point numbers. - */ - public static final float ZERO_TOLERANCE = 0.0001f; - - /** - * A float representation of one-third, approximately 0.33333334. - */ - public static final float ONE_THIRD = 1f / 3f; - - /** - * The value of Pi, approximately 3.14159. - */ - public static final float PI = (float) Math.PI; - - /** - * Twice the value of Pi, approximately 6.283185. - */ - public static final float TWO_PI = 2.0f * PI; - - /** - * Half the value of Pi, approximately 1.570796. - */ - public static final float HALF_PI = 0.5f * PI; - - /** - * A quarter of the value of Pi, approximately 0.785398. - */ - public static final float QUARTER_PI = 0.25f * PI; - - /** - * The reciprocal of Pi, approximately 0.3183099. - */ - public static final float INV_PI = 1.0f / PI; - - /** - * The reciprocal of two times Pi, approximately 0.1591549. - */ - public static final float INV_TWO_PI = 1.0f / TWO_PI; - - /** - * A factor to convert degrees to radians, approximately 0.0174533. - */ - public static final float DEG_TO_RAD = PI / 180.0f; - - /** - * A factor to convert radians to degrees, approximately 57.29578. - */ - public static final float RAD_TO_DEG = 180.0f / PI; - - /** - * The Tribonacci constant, often denoted as t, is the real root of the - * cubic equation x³ - x² - x - 1 = 0. It is approximately equal to - * 1.83928675521416. - */ - public static final float TRIBONACCI_CONSTANT = 1.83928675521416f; - - /** - * Converts a 2D index (row, column) into a 1D index for a matrix or array. - * - *

- * This method is useful when working with matrices or arrays that are - * stored in a 1D array. It calculates the 1D index corresponding to the - * specified row and column in a matrix with the given number of columns. - * - * @param rowIndex The zero-based index of the row. - * @param colIndex The zero-based index of the column. - * @param numberOfColumns The total number of columns in the matrix. - * @return The 1D index corresponding to the given row and column. - * - * @throws IllegalArgumentException if `rowIndex` or `colIndex` is negative, - * or if `numberOfColumns` is less than or - * equal to zero. - */ - public static int toOneDimensionalIndex(int rowIndex, int colIndex, - int numberOfColumns) { - if (rowIndex < 0 || colIndex < 0) - throw new IllegalArgumentException(); - - if (numberOfColumns <= 0) - throw new IllegalArgumentException(); - - return rowIndex * numberOfColumns + colIndex; - } - - /** - * Returns the smaller of two int values. That is, the result is the - * argument closer to {@link Integer#MIN_VALUE}. If the arguments have the - * same value, the result is that same value. - * - * @param a The first integer. - * @param b The second integer. - * @return The smaller of `a` and `b`. - */ - public static int min(int a, int b) { - return Math.min(a, b); - } - - /** - * Returns the larger of two int values. That is, the result is the argument - * closer to {@link Integer#MAX_VALUE}. If the arguments have the same - * value, the result is that same value. - * - * @param a The first integer. - * @param b The second integer. - * @return The larger of `a` and `b`. - */ - public static int max(int a, int b) { - return Math.max(a, b); - } - - /** - * Returns the minimum value in the given array. - * - * @param values The array of integers. - * @return The minimum value in the array, or 0 if the array is empty. - */ - public static int min(int[] values) { - if (values.length == 0) - return 0; - - int min = values[0]; - for (int i = 1; i < values.length; i++) - min = Math.min(min, values[i]); - return min; - } - - /** - * Returns the maximum value in the given array. - * - * @param values The array of integers. - * @return The maximum value in the array, or 0 if the array is empty. - */ - public static int max(int[] values) { - if (values.length == 0) - return 0; - - int max = values[0]; - for (int i = 1; i < values.length; i++) - max = Math.max(max, values[i]); - return max; - } - - /** - * Returns the larger of the two given float values. - * - * @param a The first float value. - * @param b The second float value. - * @return The larger of `a` and `b`. - */ - public static float max(float a, float b) { - return Math.max(a, b); - } - - /** - * Returns the smaller of the two given float values. - * - * @param a The first float value. - * @param b The second float value. - * @return The smaller of `a` and `b`. - */ - public static float min(float a, float b) { - return Math.min(a, b); - } - - /** - * Returns the maximum float value in the given array. - * - * @param values The array of float values. - * @return The maximum value in the array, or {@link Float#NaN} if the array - * is empty. - */ - public static float max(float... values) { - if (values.length == 0) - return Float.NaN; - - float max = values[0]; - for (int i = 1; i < values.length; i++) - max = Math.max(max, values[i]); - return max; - } - - /** - * Returns the minimum float value in the given array. - * - * @param values The array of float values. - * @return The minimum value in the array, or {@link Float#NaN} if the array - * is empty. - */ - public static float min(float... values) { - if (values.length == 0) - return Float.NaN; - - float min = values[0]; - for (int i = 1; i < values.length; i++) - min = Math.min(min, values[i]); - return min; - } - - /** - * Rounds a float value to the nearest integer, rounding ties towards - * positive infinity. - * - * @param a The float value to be rounded. - * @return The rounded integer value. - */ - public static int roundToInt(float a) { - return Math.round(a); - } - - /** - * Rounds a float value to the nearest integer. - * - *

- * This method rounds the given float value to the nearest integer. If the - * fractional part is 0.5 or greater, the value is rounded up. Otherwise, it - * is rounded down. - * - * @param a The float value to be rounded. - * @return The rounded float value. - */ - public static float round(float a) { - return Math.round(a); - } - - /** - * Clamps a value between a minimum and maximum value. - * - * @param a The value to clamp. - * @param min The minimum value. - * @param max The maximum value- - * @return The clamped value. - */ - public static float clamp(float a, float min, float max) { - return Math.max(min, Math.min(max, a)); - } - - /** - * Clamps a between min and max and returns the clamped value. - * - * @param a The value to clamp - * @param min The minimum for a. - * @param max The maximum for a. - * @return The clamped value. - */ - public static int clampInt(int a, int min, int max) { - a = a < min ? min : (a > max ? max : a); - return a; - } - - /** - * Clamps the given float value to be between 0 and 1. This method is - * equivalent to {@link #saturate(float)}. - * - * @param a The value to clamp. - * @return A clamped value between 0 and 1- - * @see #saturate(float) - */ - public static float clamp01(float a) { - return clamp(a, 0f, 1f); - } - - /** - * Converts an angle measured in degrees to an approximately equivalent - * angle measured in radians. The conversion from degrees to radians is - * generally inexact; users should not expect cos(toRadians(90.0)) to - * exactly equal 0.0. - * - * @param angdeg The angle, in degrees. - * @return The angle in radians. - */ - public static float toRadians(float angdeg) { - return (float) Math.toRadians((double) angdeg); - } - - /** - * Converts an angle measured in radians to an approximately equivalent - * angle measured in degrees. The conversion from radians to degreees is - * generally inexact; users should not expect cos(toRadians(90.0)) to - * exactlyequal 0.0. - * - * @param angrad The angle, in radians. - * @return The angle in degrees. - */ - public static float toDegrees(float angrad) { - return (float) Math.toDegrees((double) angrad); - } - - /** - * Returns a hash code for a float value; compatible with Float.hashCode(). - * - * @param value The value to hash. - * @return A hash code value for a float value. - */ - public static int hashCode(float value) { - return Float.hashCode(value); - } - - /** - * Returns the absolute value of a. - * - * @param a The argument whose absolute value is to be determined. - * @return The absolute value of the argument. - */ - public static float abs(float a) { - return Math.abs(a); - } - - /** - * Returns the trigonometric tangent of an angle. Special cases: - *