Skip to content

Commit

Permalink
Integrate Long vectors with more other classes
Browse files Browse the repository at this point in the history
httpdigest committed Jul 27, 2023
1 parent de9186c commit 5799e75
Showing 3 changed files with 327 additions and 28 deletions.
79 changes: 79 additions & 0 deletions src/main/java/org/joml/Vector2L.java
Original file line number Diff line number Diff line change
@@ -126,6 +126,18 @@ public Vector2L(Vector2Lc v) {
y = v.y();
}

/**
* Create a new {@link Vector2L} and initialize its components to the one of
* the given vector.
*
* @param v
* the {@link Vector2ic} to copy the values from
*/
public Vector2L(Vector2ic v) {
x = v.x();
y = v.y();
}

/**
* Create a new {@link Vector2L} and initialize its components to the rounded value of
* the given vector.
@@ -289,6 +301,19 @@ public Vector2L set(Vector2Lc v) {
return this;
}

/**
* Set this vector to the values of v.
*
* @param v
* the vector to copy from
* @return this
*/
public Vector2L set(Vector2ic v) {
this.x = v.x();
this.y = v.y();
return this;
}

/**
* Set this vector to the values of v using {@link RoundingMode#TRUNCATE} rounding.
* <p>
@@ -537,6 +562,24 @@ public Vector2L sub(Vector2Lc v, Vector2L dest) {
return dest;
}

/**
* Subtract the supplied vector from this one and store the result in
* <code>this</code>.
*
* @param v
* the vector to subtract
* @return this
*/
public Vector2L sub(Vector2ic v) {
return sub(v, this);
}

public Vector2L sub(Vector2ic v, Vector2L dest) {
dest.x = x - v.x();
dest.y = y - v.y();
return dest;
}

/**
* Decrement the components of this vector by the given values.
*
@@ -677,6 +720,25 @@ public Vector2L add(Vector2Lc v, Vector2L dest) {
return dest;
}

/**
* Add <code>v</code> to this vector.
*
* @param v
* the vector to add
* @return this
*/
public Vector2L add(Vector2ic v) {
this.x = x + v.x();
this.y = y + v.y();
return this;
}

public Vector2L add(Vector2ic v, Vector2L dest) {
dest.x = x + v.x();
dest.y = y + v.y();
return dest;
}

/**
* Increment the components of this vector by the given values.
*
@@ -731,6 +793,23 @@ public Vector2L mul(Vector2Lc v, Vector2L dest) {
return dest;
}

/**
* Add the supplied vector by this one.
*
* @param v
* the vector to multiply
* @return this
*/
public Vector2L mul(Vector2ic v) {
return mul(v, this);
}

public Vector2L mul(Vector2ic v, Vector2L dest) {
dest.x = x * v.x();
dest.y = y * v.y();
return dest;
}

/**
* Multiply the components of this vector by the given values.
*
191 changes: 163 additions & 28 deletions src/main/java/org/joml/Vector4L.java
Original file line number Diff line number Diff line change
@@ -81,6 +81,35 @@ public Vector4L(Vector4Lc v) {
this.w = v.w();
}

/**
* Create a new {@link Vector4L} with the same values as <code>v</code>.
*
* @param v
* the {@link Vector4ic} to copy the values from
*/
public Vector4L(Vector4ic v) {
this.x = v.x();
this.y = v.y();
this.z = v.z();
this.w = v.w();
}

/**
* Create a new {@link Vector4L} with the first three components from the
* given <code>v</code> and the given <code>w</code>.
*
* @param v
* the {@link Vector3Lc}
* @param w
* the w component
*/
public Vector4L(Vector3Lc v, long w) {
this.x = v.x();
this.y = v.y();
this.z = v.z();
this.w = w;
}

/**
* Create a new {@link Vector4L} with the first three components from the
* given <code>v</code> and the given <code>w</code>.
@@ -97,6 +126,24 @@ public Vector4L(Vector3ic v, long w) {
this.w = w;
}

/**
* Create a new {@link Vector4L} with the first two components from the
* given <code>v</code> and the given <code>z</code>, and <code>w</code>.
*
* @param v
* the {@link Vector2ic}
* @param z
* the z component
* @param w
* the w component
*/
public Vector4L(Vector2Lc v, long z, long w) {
this.x = v.x();
this.y = v.y();
this.z = z;
this.w = w;
}

/**
* Create a new {@link Vector4L} with the first two components from the
* given <code>v</code> and the given <code>z</code>, and <code>w</code>.
@@ -353,6 +400,21 @@ public Vector4L set(Vector4Lc v) {
return this;
}

/**
* Set this vector to the values of the given <code>v</code>.
*
* @param v
* the vector whose values will be copied into this
* @return this
*/
public Vector4L set(Vector4ic v) {
this.x = v.x();
this.y = v.y();
this.z = v.z();
this.w = v.w();
return this;
}

/**
* Set this vector to the values of v using {@link RoundingMode#TRUNCATE} rounding.
* <p>
@@ -716,6 +778,31 @@ public Vector4Lc getToAddress(long address) {
public Vector4L sub(Vector4Lc v) {
return sub(v, this);
}
public Vector4L sub(Vector4Lc v, Vector4L dest) {
dest.x = this.x - v.x();
dest.y = this.y - v.y();
dest.z = this.z - v.z();
dest.w = this.w - v.w();
return dest;
}

/**
* Subtract the supplied vector from this one.
*
* @param v
* the vector to subtract
* @return this
*/
public Vector4L sub(Vector4ic v) {
return sub(v, this);
}
public Vector4L sub(Vector4ic v, Vector4L dest) {
dest.x = this.x - v.x();
dest.y = this.y - v.y();
dest.z = this.z - v.z();
dest.w = this.w - v.w();
return dest;
}

/**
* Subtract <code>(x, y, z, w)</code> from this.
@@ -733,15 +820,6 @@ public Vector4L sub(Vector4Lc v) {
public Vector4L sub(long x, long y, long z, long w) {
return sub(x, y, z, w, this);
}

public Vector4L sub(Vector4Lc v, Vector4L dest) {
dest.x = this.x - v.x();
dest.y = this.y - v.y();
dest.z = this.z - v.z();
dest.w = this.w - v.w();
return dest;
}

public Vector4L sub(long x, long y, long z, long w, Vector4L dest) {
dest.x = this.x - x;
dest.y = this.y - y;
@@ -760,7 +838,6 @@ public Vector4L sub(long x, long y, long z, long w, Vector4L dest) {
public Vector4L add(Vector4Lc v) {
return add(v, this);
}

public Vector4L add(Vector4Lc v, Vector4L dest) {
dest.x = this.x + v.x();
dest.y = this.y + v.y();
@@ -769,6 +846,24 @@ public Vector4L add(Vector4Lc v, Vector4L dest) {
return dest;
}

/**
* Add the supplied vector to this one.
*
* @param v
* the vector to add
* @return this
*/
public Vector4L add(Vector4ic v) {
return add(v, this);
}
public Vector4L add(Vector4ic v, Vector4L dest) {
dest.x = this.x + v.x();
dest.y = this.y + v.y();
dest.z = this.z + v.z();
dest.w = this.w + v.w();
return dest;
}

/**
* Increment the components of this vector by the given values.
*
@@ -785,7 +880,6 @@ public Vector4L add(Vector4Lc v, Vector4L dest) {
public Vector4L add(long x, long y, long z, long w) {
return add(x, y, z, w, this);
}

public Vector4L add(long x, long y, long z, long w, Vector4L dest) {
dest.x = this.x + x;
dest.y = this.y + y;
@@ -795,7 +889,7 @@ public Vector4L add(long x, long y, long z, long w, Vector4L dest) {
}

/**
* Multiply this Vector4L component-wise by another Vector4L.
* Multiply this Vector4L component-wise by another vector.
*
* @param v
* the other vector
@@ -804,7 +898,6 @@ public Vector4L add(long x, long y, long z, long w, Vector4L dest) {
public Vector4L mul(Vector4Lc v) {
return mul(v, this);
}

public Vector4L mul(Vector4Lc v, Vector4L dest) {
dest.x = x * v.x();
dest.y = y * v.y();
@@ -814,7 +907,25 @@ public Vector4L mul(Vector4Lc v, Vector4L dest) {
}

/**
* Divide this Vector4L component-wise by another Vector4L.
* Multiply this Vector4L component-wise by another vector.
*
* @param v
* the other vector
* @return this
*/
public Vector4L mul(Vector4ic v) {
return mul(v, this);
}
public Vector4L mul(Vector4ic v, Vector4L dest) {
dest.x = x * v.x();
dest.y = y * v.y();
dest.z = z * v.z();
dest.w = w * v.w();
return dest;
}

/**
* Divide this Vector4L component-wise by another vector.
*
* @param v
* the vector to divide by
@@ -823,7 +934,6 @@ public Vector4L mul(Vector4Lc v, Vector4L dest) {
public Vector4L div(Vector4Lc v) {
return div(v, this);
}

public Vector4L div(Vector4Lc v, Vector4L dest) {
dest.x = x / v.x();
dest.y = y / v.y();
@@ -832,6 +942,24 @@ public Vector4L div(Vector4Lc v, Vector4L dest) {
return dest;
}

/**
* Divide this Vector4L component-wise by another vector.
*
* @param v
* the vector to divide by
* @return this
*/
public Vector4L div(Vector4ic v) {
return div(v, this);
}
public Vector4L div(Vector4ic v, Vector4L dest) {
dest.x = x / v.x();
dest.y = y / v.y();
dest.z = z / v.z();
dest.w = w / v.w();
return dest;
}

/**
* Multiply all components of this vector by the given scalar
* value.
@@ -843,7 +971,6 @@ public Vector4L div(Vector4Lc v, Vector4L dest) {
public Vector4L mul(long scalar) {
return mul(scalar, this);
}

public Vector4L mul(long scalar, Vector4L dest) {
dest.x = x * scalar;
dest.y = y * scalar;
@@ -862,7 +989,6 @@ public Vector4L mul(long scalar, Vector4L dest) {
public Vector4L div(float scalar) {
return div(scalar, this);
}

public Vector4L div(float scalar, Vector4L dest) {
float invscalar = 1.0f / scalar;
dest.x = (int) (x * invscalar);
@@ -882,7 +1008,6 @@ public Vector4L div(float scalar, Vector4L dest) {
public Vector4L div(long scalar) {
return div(scalar, this);
}

public Vector4L div(long scalar, Vector4L dest) {
dest.x = x / scalar;
dest.y = y / scalar;
@@ -892,7 +1017,7 @@ public Vector4L div(long scalar, Vector4L dest) {
}

public long lengthSquared() {
return (long) x * x + (long) y * y + (long) z * z + (long) w * w;
return x * x + y * y + z * z + w * w;
}

/**
@@ -906,11 +1031,11 @@ public long lengthSquared() {
* @return the length squared of the given vector
*/
public static long lengthSquared(long x, long y, long z, long w) {
return (long) x * x + (long) y * y + (long) z * z + (long) w * w;
return x * x + y * y + z * z + w * w;
}

public double length() {
return Math.sqrt((long) x * x + (long) y * y + (long) z * z + (long) w * w);
return Math.sqrt(x * x + y * y + z * z + w * w);
}

/**
@@ -924,12 +1049,15 @@ public double length() {
* @return the length squared of the given vector
*/
public static double length(long x, long y, long z, long w) {
return Math.sqrt((long) x * x + (long) y * y + (long) z * z + (long) w * w);
return Math.sqrt(x * x + y * y + z * z + w * w);
}

public double distance(Vector4Lc v) {
return distance(v.x(), v.y(), v.z(), v.w());
}
public double distance(Vector4ic v) {
return distance(v.x(), v.y(), v.z(), v.w());
}

public double distance(long x, long y, long z, long w) {
long dx = this.x - x;
@@ -942,6 +1070,9 @@ public double distance(long x, long y, long z, long w) {
public long gridDistance(Vector4Lc v) {
return Math.abs(v.x() - x()) + Math.abs(v.y() - y()) + Math.abs(v.z() - z()) + Math.abs(v.w() - w());
}
public long gridDistance(Vector4ic v) {
return Math.abs(v.x() - x()) + Math.abs(v.y() - y()) + Math.abs(v.z() - z()) + Math.abs(v.w() - w());
}

public long gridDistance(long x, long y, long z, long w) {
return Math.abs(x - x()) + Math.abs(y - y()) + Math.abs(z - z()) + Math.abs(w - w());
@@ -950,13 +1081,16 @@ public long gridDistance(long x, long y, long z, long w) {
public long distanceSquared(Vector4Lc v) {
return distanceSquared(v.x(), v.y(), v.z(), v.w());
}
public long distanceSquared(Vector4ic v) {
return distanceSquared(v.x(), v.y(), v.z(), v.w());
}

public long distanceSquared(long x, long y, long z, long w) {
long dx = this.x - x;
long dy = this.y - y;
long dz = this.z - z;
long dw = this.w - w;
return (long) dx * dx + (long) dy * dy + (long) dz * dz + (long) dw * dw;
return dx * dx + dy * dy + dz * dz + dw * dw;
}

/**
@@ -985,7 +1119,7 @@ public static double distance(long x1, long y1, long z1, long w1, long x2, long
long dy = y1 - y2;
long dz = z1 - z2;
long dw = w1 - w2;
return Math.sqrt((long) dx * dx + (long) dy * dy + (long) dz * dz + (long) dw * dw);
return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
}

/**
@@ -1014,11 +1148,14 @@ public static long distanceSquared(long x1, long y1, long z1, long w1, long x2,
long dy = y1 - y2;
long dz = z1 - z2;
long dw = w1 - w2;
return (long) dx * dx + (long) dy * dy + (long) dz * dz + (long) dw * dw;
return dx * dx + dy * dy + dz * dz + dw * dw;
}

public long dot(Vector4Lc v) {
return (long) x * v.x() + (long) y * v.y() + (long) z * v.z() + (long) w * v.w();
return x * v.x() + y * v.y() + z * v.z() + w * v.w();
}
public long dot(Vector4ic v) {
return x * v.x() + y * v.y() + z * v.z() + w * v.w();
}

/**
@@ -1097,7 +1234,6 @@ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundExcept
public Vector4L min(Vector4Lc v) {
return min(v, this);
}

public Vector4L min(Vector4Lc v, Vector4L dest) {
dest.x = x < v.x() ? x : v.x();
dest.y = y < v.y() ? y : v.y();
@@ -1116,7 +1252,6 @@ public Vector4L min(Vector4Lc v, Vector4L dest) {
public Vector4L max(Vector4Lc v) {
return max(v, this);
}

public Vector4L max(Vector4Lc v, Vector4L dest) {
dest.x = x > v.x() ? x : v.x();
dest.y = y > v.y() ? y : v.y();
85 changes: 85 additions & 0 deletions src/main/java/org/joml/Vector4Lc.java
Original file line number Diff line number Diff line change
@@ -148,6 +148,18 @@ public interface Vector4Lc {
*/
Vector4L sub(Vector4Lc v, Vector4L dest);

/**
* Subtract the supplied vector from this one and store the result in
* <code>dest</code>.
*
* @param v
* the vector to subtract from <code>this</code>
* @param dest
* will hold the result
* @return dest
*/
Vector4L sub(Vector4ic v, Vector4L dest);

/**
* Subtract <code>(x, y, z, w)</code> from this and store the result in
* <code>dest</code>.
@@ -178,6 +190,18 @@ public interface Vector4Lc {
*/
Vector4L add(Vector4Lc v, Vector4L dest);

/**
* Add the supplied vector to this one and store the result in
* <code>dest</code>.
*
* @param v
* the vector to add
* @param dest
* will hold the result
* @return dest
*/
Vector4L add(Vector4ic v, Vector4L dest);

/**
* Increment the components of this vector by the given values and store the
* result in <code>dest</code>.
@@ -208,6 +232,18 @@ public interface Vector4Lc {
*/
Vector4L mul(Vector4Lc v, Vector4L dest);

/**
* Multiply this Vector4L component-wise by another Vector4ic and store the
* result in <code>dest</code>.
*
* @param v
* the other vector
* @param dest
* will hold the result
* @return dest
*/
Vector4L mul(Vector4ic v, Vector4L dest);

/**
* Divide this Vector4L component-wise by another Vector4Lc and store the
* result in <code>dest</code>.
@@ -220,6 +256,18 @@ public interface Vector4Lc {
*/
Vector4L div(Vector4Lc v, Vector4L dest);

/**
* Divide this Vector4L component-wise by another Vector4ic and store the
* result in <code>dest</code>.
*
* @param v
* the vector to divide by
* @param dest
* will hold the result
* @return dest
*/
Vector4L div(Vector4ic v, Vector4L dest);

/**
* Multiply all components of this vector by the given scalar
* value and store the result in <code>dest</code>.
@@ -279,6 +327,15 @@ public interface Vector4Lc {
*/
double distance(Vector4Lc v);

/**
* Return the distance between this Vector and <code>v</code>.
*
* @param v
* the other vector
* @return the distance
*/
double distance(Vector4ic v);

/**
* Return the distance between <code>this</code> vector and <code>(x, y, z, w)</code>.
*
@@ -304,6 +361,16 @@ public interface Vector4Lc {
*/
long gridDistance(Vector4Lc v);

/**
* Return the grid distance in between (aka 1-Norm, Minkowski or Manhattan distance)
* <code>(x, y)</code>.
*
* @param v
* the other vector
* @return the grid distance
*/
long gridDistance(Vector4ic v);

/**
* Return the grid distance in between (aka 1-Norm, Minkowski or Manhattan distance)
* <code>(x, y)</code>.
@@ -329,6 +396,15 @@ public interface Vector4Lc {
*/
long distanceSquared(Vector4Lc v);

/**
* Return the square of the distance between this vector and <code>v</code>.
*
* @param v
* the other vector
* @return the squared of the distance
*/
long distanceSquared(Vector4ic v);

/**
* Return the square of the distance between <code>this</code> vector and
* <code>(x, y, z, w)</code>.
@@ -354,6 +430,15 @@ public interface Vector4Lc {
*/
long dot(Vector4Lc v);

/**
* Compute the dot product (inner product) of this vector and <code>v</code>.
*
* @param v
* the other vector
* @return the dot product
*/
long dot(Vector4ic v);

/**
* Negate this vector and store the result in <code>dest</code>.
*

0 comments on commit 5799e75

Please sign in to comment.