From cb8b89a636080b64a18fdbba676f1f4611ff8723 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 24 Apr 2022 08:03:38 +0200 Subject: [PATCH] [DEV] add avg in vector 3f --- src/org/atriasoft/etk/math/Vector3f.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/org/atriasoft/etk/math/Vector3f.java b/src/org/atriasoft/etk/math/Vector3f.java index f0ec0bb..9630977 100644 --- a/src/org/atriasoft/etk/math/Vector3f.java +++ b/src/org/atriasoft/etk/math/Vector3f.java @@ -178,7 +178,7 @@ public record Vector3f( @CheckReturnValue public Vector3f divide(final float val) { if (val != 0.0f) { - float tmp = 1.0f / val; + final float tmp = 1.0f / val; return new Vector3f(this.x * tmp, this.y * tmp, this.z * tmp); } throw new IllegalArgumentException("divice by 0 (vector3f)"); @@ -316,7 +316,7 @@ public record Vector3f( * @return the new reflect vector */ @CheckReturnValue - public Vector3f reflect(Vector3f normal) { + public Vector3f reflect(final Vector3f normal) { return this.less(normal.multiply(this.dot(normal) * 2.0f)); } @@ -539,6 +539,11 @@ public record Vector3f( return new Vector3f(Math.min(obj1.x, obj2.x), Math.min(obj1.y, obj2.y), Math.min(obj1.z, obj2.z)); } + @CheckReturnValue + public static Vector3f avg(final Vector3f min, final Vector3f obj2, final Vector3f max) { + return new Vector3f(FMath.avg(min.x, obj2.x, max.x), FMath.avg(min.y, obj2.y, max.y), FMath.avg(min.z, obj2.z, max.z)); + } + /** * Set each element to the min of the current values and the values of * another Vector3f @@ -603,9 +608,9 @@ public record Vector3f( @CheckReturnValue public static Vector3f valueOf(final String valuesX, final String valuesY, final String valuesZ) { - float val1 = Float.valueOf(valuesX); - float val2 = Float.valueOf(valuesY); - float val3 = Float.valueOf(valuesZ); + final float val1 = Float.valueOf(valuesX); + final float val2 = Float.valueOf(valuesY); + final float val3 = Float.valueOf(valuesZ); return new Vector3f(val1, val2, val3); }