From 577ffa85f1fd0b33045ffb08f639dc4fb048aa95 Mon Sep 17 00:00:00 2001 From: httpdigest Date: Mon, 27 Jan 2020 20:13:54 +0100 Subject: [PATCH] Add Vector3i.div() and Vector4i.div(float)/(int, Vector4i) overloads --- src/org/joml/Vector3i.java | 44 +++++++++++++++++++++++++++++++++++++ src/org/joml/Vector3ic.java | 24 ++++++++++++++++++++ src/org/joml/Vector4i.java | 39 ++++++++++++++++++++++++-------- src/org/joml/Vector4ic.java | 12 ++++++++++ 4 files changed, 110 insertions(+), 9 deletions(-) diff --git a/src/org/joml/Vector3i.java b/src/org/joml/Vector3i.java index 9e9d83ccc..8f4860a3a 100644 --- a/src/org/joml/Vector3i.java +++ b/src/org/joml/Vector3i.java @@ -794,6 +794,50 @@ public Vector3i mul(int x, int y, int z, Vector3i dest) { return dest; } + /** + * Divide all components of this {@link Vector3i} by the given scalar value. + * + * @param scalar + * the scalar to divide by + * @return a vector holding the result + */ + public Vector3i div(float scalar) { + float invscalar = 1.0f / scalar; + this.x = (int) (x * invscalar); + this.y = (int) (y * invscalar); + this.z = (int) (z * invscalar); + return this; + } + + public Vector3i div(float scalar, Vector3i dest) { + float invscalar = 1.0f / scalar; + dest.x = (int) (x * invscalar); + dest.y = (int) (y * invscalar); + dest.z = (int) (z * invscalar); + return dest; + } + + /** + * Divide all components of this {@link Vector3i} by the given scalar value. + * + * @param scalar + * the scalar to divide by + * @return a vector holding the result + */ + public Vector3i div(int scalar) { + this.x = x / scalar; + this.y = y / scalar; + this.z = z / scalar; + return this; + } + + public Vector3i div(int scalar, Vector3i dest) { + dest.x = x / scalar; + dest.y = y / scalar; + dest.z = z / scalar; + return dest; + } + /* (non-Javadoc) * @see org.joml.Vector3ic#lengthSquared() */ diff --git a/src/org/joml/Vector3ic.java b/src/org/joml/Vector3ic.java index 96d105c86..33f2d45d2 100644 --- a/src/org/joml/Vector3ic.java +++ b/src/org/joml/Vector3ic.java @@ -226,6 +226,30 @@ public interface Vector3ic { */ Vector3i mul(int x, int y, int z, Vector3i dest); + /** + * Divide all components of this {@link Vector3i} by the given scalar value + * and store the result in dest. + * + * @param scalar + * the scalar to divide by + * @param dest + * will hold the result + * @return dest + */ + Vector3i div(float scalar, Vector3i dest); + + /** + * Divide all components of this {@link Vector3i} by the given scalar value + * and store the result in dest. + * + * @param scalar + * the scalar to divide by + * @param dest + * will hold the result + * @return dest + */ + Vector3i div(int scalar, Vector3i dest); + /** * Return the length squared of this vector. * diff --git a/src/org/joml/Vector4i.java b/src/org/joml/Vector4i.java index b70e17a1c..c4f2d2bd4 100644 --- a/src/org/joml/Vector4i.java +++ b/src/org/joml/Vector4i.java @@ -903,23 +903,21 @@ public Vector4i mul(int scalar, Vector4i dest) { } /** - * Divide all components of this {@link Vector4i} by the given scalar value. + * Divide all components of this {@link Vector3i} by the given scalar value. * * @param scalar * the scalar to divide by * @return a vector holding the result */ - public Vector4i div(int scalar) { - this.x = x / scalar; - this.y = y / scalar; - this.z = z / scalar; - this.w = w / scalar; + public Vector4i div(float scalar) { + float invscalar = 1.0f / scalar; + this.x = (int) (x * invscalar); + this.y = (int) (y * invscalar); + this.z = (int) (z * invscalar); + this.w = (int) (w * invscalar); return this; } - /* (non-Javadoc) - * @see org.joml.Vector4ic#div(float, org.joml.Vector4i) - */ public Vector4i div(float scalar, Vector4i dest) { float invscalar = 1.0f / scalar; dest.x = (int) (x * invscalar); @@ -929,6 +927,29 @@ public Vector4i div(float scalar, Vector4i dest) { return dest; } + /** + * Divide all components of this {@link Vector4i} by the given scalar value. + * + * @param scalar + * the scalar to divide by + * @return a vector holding the result + */ + public Vector4i div(int scalar) { + this.x = x / scalar; + this.y = y / scalar; + this.z = z / scalar; + this.w = w / scalar; + return this; + } + + public Vector4i div(int scalar, Vector4i dest) { + dest.x = x / scalar; + dest.y = y / scalar; + dest.z = z / scalar; + dest.w = w / scalar; + return dest; + } + /* (non-Javadoc) * @see org.joml.Vector4ic#lengthSquared() */ diff --git a/src/org/joml/Vector4ic.java b/src/org/joml/Vector4ic.java index c3dba62d0..9ac5310c5 100644 --- a/src/org/joml/Vector4ic.java +++ b/src/org/joml/Vector4ic.java @@ -244,6 +244,18 @@ public interface Vector4ic { */ Vector4i div(float scalar, Vector4i dest); + /** + * Divide all components of this {@link Vector4i} by the given scalar value + * and store the result in dest. + * + * @param scalar + * the scalar to divide by + * @param dest + * will hold the result + * @return dest + */ + Vector4i div(int scalar, Vector4i dest); + /** * Return the length squared of this vector. *