From 8530671a49d9df0a5a4a6494ff0a6cf0c787150d Mon Sep 17 00:00:00 2001 From: notevil Date: Thu, 23 Apr 2026 05:26:34 +0200 Subject: [PATCH] Audit-6 : strip dead math utilities (-300 LOC) Confirmed-dead method cleanup in rig/math/ following AUDIT_2026-04-22 essentiality cross-check. All removals verified via grep across src/ showing zero live callers. - MathUtils.java (-242 LOC) : bezierCurve (both overloads), rotWrap, lerpDegree, greatest/least (all 6 numeric overloads), translateStack, rotateStack, scaleStack (+ their OPEN_MATRIX_BUFFER field), lerpMojangVector, setQuaternion, mulQuaternion, getLeastAngleVector (idx variant kept, used by ClothSimulator), packColor, unpackColor, normalIntValue, wrapClamp, worldToScreenCoord. Unused imports (Vector4i, Vector4f, Axis, Camera, Vec2) stripped. - OpenMatrix4f.java (-56 LOC net) : 3-arg add, mulAsOrigin, createScale, ofScale. mulAsOriginInverse (task-KEEP) inlined to no longer depend on mulAsOrigin. - Vec3f.java (-2 LOC net) : toMojangVector, fromMojangVector. ValueModifier.java NOT deleted despite task instruction : grep found live references in rig/anim/property/AnimationProperty.java (4 AttackPhaseProperty constants + import). Task explicitly says "STOP and report" in this case. The 4 constants have no downstream readers and could be purged in a follow-up, but that is outside this task's scope. 20/20 rig tests GREEN (--rerun-tasks verified), ./gradlew compileJava GREEN after each file group. --- .../com/tiedup/remake/rig/math/MathUtils.java | 242 ------------------ .../tiedup/remake/rig/math/OpenMatrix4f.java | 64 +---- .../com/tiedup/remake/rig/math/Vec3f.java | 10 +- 3 files changed, 8 insertions(+), 308 deletions(-) diff --git a/src/main/java/com/tiedup/remake/rig/math/MathUtils.java b/src/main/java/com/tiedup/remake/rig/math/MathUtils.java index 347402e..e63cde0 100644 --- a/src/main/java/com/tiedup/remake/rig/math/MathUtils.java +++ b/src/main/java/com/tiedup/remake/rig/math/MathUtils.java @@ -19,19 +19,14 @@ import org.joml.Matrix3f; import org.joml.Matrix4f; import org.joml.Quaternionf; import org.joml.Vector3f; -import org.joml.Vector4f; -import org.joml.Vector4i; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Axis; -import net.minecraft.client.Camera; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.phys.HitResult; -import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; public class MathUtils { @@ -52,30 +47,6 @@ public class MathUtils { return modelMatrix; } - /** - * Blender 2.79 bezier curve - * @param t: 0 ~ 1 - * @retur - */ - public static double bezierCurve(double t) { - double p1 = 0.0D; - double p2 = 0.0D; - double p3 = 1.0D; - double p4 = 1.0D; - double v1, v2, v3, v4; - - v1 = p1; - v2 = 3.0D * (p2 - p1); - v3 = 3.0D * (p1 - 2.0D * p2 + p3); - v4 = p4 - p1 + 3.0D * (p2 - p3); - - return v1 + t * v2 + t * t * v3 + t * t * t * v4; - } - - public static float bezierCurve(float t) { - return (float)bezierCurve((double)t); - } - public static int getSign(double value) { return value > 0.0D ? 1 : -1; } @@ -128,16 +99,6 @@ public class MathUtils { return f1; } - public static float rotWrap(double d) { - while (d >= 180.0) { - d -= 360.0; - } - while (d < -180.0) { - d += 360.0; - } - return (float)d; - } - public static float wrapRadian(float pValue) { float maxRot = (float)Math.PI * 2.0F; float f = pValue % maxRot; @@ -153,21 +114,6 @@ public class MathUtils { return f; } - public static float lerpDegree(float from, float to, float progression) { - from = Mth.wrapDegrees(from); - to = Mth.wrapDegrees(to); - - if (Math.abs(from - to) > 180.0F) { - if (to < 0.0F) { - from -= 360.0F; - } else if (to > 0.0F) { - from += 360.0F; - } - } - - return Mth.lerp(progression, from, to); - } - public static float findNearestRotation(float src, float rotation) { float diff = Math.abs(src - rotation); float idealRotation = rotation; @@ -213,98 +159,6 @@ public class MathUtils { return getNearestVector(from, vectors.toArray(new Vec3[0])); } - public static int greatest(int... iList) { - int max = Integer.MIN_VALUE; - - for (int i : iList) { - if (max < i) { - max = i; - } - } - - return max; - } - - public static int least(int... iList) { - int min = Integer.MAX_VALUE; - - for (int i : iList) { - if (min > i) { - min = i; - } - } - - return min; - } - - public static float greatest(float... fList) { - float max = -1000000.0F; - - for (float f : fList) { - if (max < f) { - max = f; - } - } - - return max; - } - - public static float least(float... fList) { - float min = 1000000.0F; - - for (float f : fList) { - if (min > f) { - min = f; - } - } - - return min; - } - - public static double greatest(double... dList) { - double max = -1000000.0D; - - for (double d : dList) { - if (max < d) { - max = d; - } - } - - return max; - } - - public static double least(double... dList) { - double min = 1000000.0D; - - for (double d : dList) { - if (min > d) { - min = d; - } - } - - return min; - } - - @Deprecated(forRemoval = true, since = "1.21.1") - public static void translateStack(PoseStack poseStack, OpenMatrix4f mat) { - poseStack.translate(mat.m30, mat.m31, mat.m32); - } - - private static final OpenMatrix4f OPEN_MATRIX_BUFFER = new OpenMatrix4f(); - - @Deprecated(forRemoval = true, since = "1.21.1") - public static void rotateStack(PoseStack poseStack, OpenMatrix4f mat) { - OpenMatrix4f.transpose(mat, OPEN_MATRIX_BUFFER); - poseStack.mulPose(getQuaternionFromMatrix(OPEN_MATRIX_BUFFER)); - } - - @Deprecated(forRemoval = true, since = "1.21.1") - public static void scaleStack(PoseStack poseStack, OpenMatrix4f mat) { - OpenMatrix4f.transpose(mat, OPEN_MATRIX_BUFFER); - Vector3f vector = getScaleVectorFromMatrix(OPEN_MATRIX_BUFFER); - poseStack.scale(vector.x(), vector.y(), vector.z()); - } - private static final Matrix4f MATRIX4F = new Matrix4f(); private static final Matrix3f MATRIX3F = new Matrix3f(); @@ -372,13 +226,6 @@ public class MathUtils { return new Vec3(start.x + (end.x - start.x) * delta, start.y + (end.y - start.y) * delta, start.z + (end.z - start.z) * delta); } - public static Vector3f lerpMojangVector(Vector3f start, Vector3f end, float delta) { - float x = start.x() + (end.x() - start.x()) * delta; - float y = start.y() + (end.y() - start.y()) * delta; - float z = start.z() + (end.z() - start.z()) * delta; - return new Vector3f(x, y, z); - } - public static Vec3 projectVector(Vec3 from, Vec3 to) { double dot = to.dot(from); double normalScale = 1.0D / ((to.x * to.x) + (to.y * to.y) + (to.z * to.z)); @@ -401,33 +248,6 @@ public class MathUtils { return dest; } - public static void setQuaternion(Quaternionf quat, float x, float y, float z, float w) { - quat.set(x, y, z, w); - } - - public static Quaternionf mulQuaternion(Quaternionf left, Quaternionf right, Quaternionf dest) { - if (dest == null) { - dest = new Quaternionf(0.0F, 0.0F, 0.0F, 1.0F); - } - - float f = left.x(); - float f1 = left.y(); - float f2 = left.z(); - float f3 = left.w(); - float f4 = right.x(); - float f5 = right.y(); - float f6 = right.z(); - float f7 = right.w(); - float i = f3 * f4 + f * f7 + f1 * f6 - f2 * f5; - float j = f3 * f5 - f * f6 + f1 * f7 + f2 * f4; - float k = f3 * f6 + f * f5 - f1 * f4 + f2 * f7; - float r = f3 * f7 - f * f4 - f1 * f5 - f2 * f6; - - dest.set(i, j, k, r); - - return dest; - } - public static Quaternionf lerpQuaternion(Quaternionf from, Quaternionf to, float delta) { return lerpQuaternion(from, to, delta, null); } @@ -514,10 +334,6 @@ public class MathUtils { return leastVectorIdx; } - public static Vec3f getLeastAngleVector(Vec3f src, Vec3f... candidates) { - return candidates[getLeastAngleVectorIdx(src, candidates)]; - } - public static boolean canBeSeen(Entity target, Entity watcher, double maxDistance) { if (target.level() != watcher.level()) { return false; @@ -537,63 +353,5 @@ public class MathUtils { vec1.distanceToSqr(vec4) < sqr && level.clip(new ClipContext(vec1, vec4, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, watcher)).getType() == HitResult.Type.MISS; } - public static int packColor(int r, int g, int b, int a) { - int ir = r << 16; - int ig = g << 8; - int ib = b; - int ia = a << 24; - - return ir | ig | ib | ia; - } - - public static void unpackColor(int packedColor, Vector4i result) { - int b = (packedColor & 0x000000FF); - int g = (packedColor & 0x0000FF00) >>> 8; - int r = (packedColor & 0x00FF0000) >>> 16; - int a = (packedColor & 0xFF000000) >>> 24; - - result.x = r; - result.y = g; - result.z = b; - result.w = a; - } - - public static byte normalIntValue(float pNum) { - return (byte)((int)(Mth.clamp(pNum, -1.0F, 1.0F) * 127.0F) & 255); - } - - /** - * Wrap a value within bounds - */ - public static int wrapClamp(int value, int min, int max) { - int stride = max - min + 1; - while (value < min) value += stride; - while (value > max) value -= stride; - return value; - } - - /** - * Transform the world coordinate system to -1~1 screen coord system - * @param projection current projection matrix - * @param modelView current model-view matrix - * @param position a source vector to transform - */ - public static Vec2 worldToScreenCoord(Matrix4f projectionMatrix, Camera camera, Vec3 position) { - Vector4f relativeCamera = new Vector4f((float)camera.getPosition().x() - (float)position.x(), (float)camera.getPosition().y() - (float)position.y(), (float)camera.getPosition().z() - (float)position.z(), 1.0F); - relativeCamera.rotate(Axis.YP.rotationDegrees(camera.getYRot() + 180.0F)); - relativeCamera.rotate(Axis.XP.rotationDegrees(camera.getXRot())); - relativeCamera.mul(projectionMatrix); - - float depth = relativeCamera.w; - relativeCamera.mul(1.0F / relativeCamera.w()); - - if (depth < 0.0F) { - relativeCamera.x = -relativeCamera.x; - relativeCamera.y = -relativeCamera.y; - } - - return new Vec2(relativeCamera.x(), relativeCamera.y()); - } - private MathUtils() {} } diff --git a/src/main/java/com/tiedup/remake/rig/math/OpenMatrix4f.java b/src/main/java/com/tiedup/remake/rig/math/OpenMatrix4f.java index 4775fc0..c5e42c1 100644 --- a/src/main/java/com/tiedup/remake/rig/math/OpenMatrix4f.java +++ b/src/main/java/com/tiedup/remake/rig/math/OpenMatrix4f.java @@ -256,33 +256,6 @@ public class OpenMatrix4f { return new OpenMatrix4f(this, true); } - public static OpenMatrix4f add(OpenMatrix4f left, OpenMatrix4f right, @Nullable OpenMatrix4f dest) { - if (dest == null) { - dest = new OpenMatrix4f(); - } else if (dest.immutable) { - throw new UnsupportedOperationException("Can't modify immutable matrix"); - } - - dest.m00 = left.m00 + right.m00; - dest.m01 = left.m01 + right.m01; - dest.m02 = left.m02 + right.m02; - dest.m03 = left.m03 + right.m03; - dest.m10 = left.m10 + right.m10; - dest.m11 = left.m11 + right.m11; - dest.m12 = left.m12 + right.m12; - dest.m13 = left.m13 + right.m13; - dest.m20 = left.m20 + right.m20; - dest.m21 = left.m21 + right.m21; - dest.m22 = left.m22 + right.m22; - dest.m23 = left.m23 + right.m23; - dest.m30 = left.m30 + right.m30; - dest.m31 = left.m31 + right.m31; - dest.m32 = left.m32 + right.m32; - dest.m33 = left.m33 + right.m33; - - return dest; - } - public OpenMatrix4f mulFront(OpenMatrix4f mulTransform) { return OpenMatrix4f.mul(mulTransform, this, this); } @@ -345,23 +318,19 @@ public class OpenMatrix4f { return result; } - public static OpenMatrix4f mulAsOrigin(OpenMatrix4f left, OpenMatrix4f right, OpenMatrix4f dest) { - float x = right.m30; - float y = right.m31; - float z = right.m32; - - OpenMatrix4f result = mul(left, right, dest); + public static OpenMatrix4f mulAsOriginInverse(OpenMatrix4f left, OpenMatrix4f right, OpenMatrix4f dest) { + float x = left.m30; + float y = left.m31; + float z = left.m32; + + OpenMatrix4f result = mul(right, left, dest); result.m30 = x; result.m31 = y; result.m32 = z; - + return result; } - public static OpenMatrix4f mulAsOriginInverse(OpenMatrix4f left, OpenMatrix4f right, OpenMatrix4f dest) { - return mulAsOrigin(right, left, dest); - } - public static Vec4f transform(OpenMatrix4f matrix, Vec4f src, @Nullable Vec4f dest) { if (dest == null) { dest = new Vec4f(); @@ -572,25 +541,6 @@ public class OpenMatrix4f { return dest; } - public static OpenMatrix4f createScale(float x, float y, float z) { - return ofScale(x, y, z, null); - } - - public static OpenMatrix4f ofScale(float x, float y, float z, OpenMatrix4f dest) { - if (dest == null) { - dest = new OpenMatrix4f(); - } else if (dest.immutable) { - throw new UnsupportedOperationException("Can't modify immutable matrix"); - } - - dest.setIdentity(); - dest.m00 = x; - dest.m11 = y; - dest.m22 = z; - - return dest; - } - public OpenMatrix4f rotateDeg(float angle, Vec3f axis) { return rotate((float)Math.toRadians(angle), axis); } diff --git a/src/main/java/com/tiedup/remake/rig/math/Vec3f.java b/src/main/java/com/tiedup/remake/rig/math/Vec3f.java index fea6005..a97bf74 100644 --- a/src/main/java/com/tiedup/remake/rig/math/Vec3f.java +++ b/src/main/java/com/tiedup/remake/rig/math/Vec3f.java @@ -447,18 +447,10 @@ public class Vec3f extends Vec2f { return index; } - public Vector3f toMojangVector() { - return new Vector3f(this.x, this.y, this.z); - } - public Vec3 toDoubleVector() { return new Vec3(this.x, this.y, this.z); } - - public static Vec3f fromMojangVector(Vector3f vec3) { - return new Vec3f(vec3.x(), vec3.y(), vec3.z()); - } - + public static Vec3f fromDoubleVector(Vec3 vec3) { return new Vec3f((float)vec3.x(), (float)vec3.y(), (float)vec3.z()); }