Skip to content

Commit

Permalink
Add Vector4.xyz(Vector3) swizzle
Browse files Browse the repository at this point in the history
  • Loading branch information
httpdigest committed Jun 30, 2023
1 parent d475251 commit bbc988e
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/java/org/joml/Vector4d.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,33 @@ public double x() {
return this.x;
}

/**
* Copy the <code>(x, y, z)</code> components of <code>this</code> into the supplied <code>dest</code> vector
* and return it.
* <p>
* Note that due to the given vector <code>dest</code> storing the components in float-precision,
* there is the possibility to lose precision.
*
* @param dest
* will hold the result
* @return dest
*/
public Vector3f xyz(Vector3f dest) {
return dest.set(x, y, z);
}

/**
* Copy the <code>(x, y, z)</code> components of <code>this</code> into the supplied <code>dest</code> vector
* and return it.
*
* @param dest
* will hold the result
* @return dest
*/
public Vector3d xyz(Vector3d dest) {
return dest.set(x, y, z);
}

public double y() {
return this.y;
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/joml/Vector4f.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,30 @@ public float x() {
return this.x;
}

/**
* Copy the <code>(x, y, z)</code> components of <code>this</code> into the supplied <code>dest</code> vector
* and return it.
*
* @param dest
* will hold the result
* @return dest
*/
public Vector3f xyz(Vector3f dest) {
return dest.set(x, y, z);
}

/**
* Copy the <code>(x, y, z)</code> components of <code>this</code> into the supplied <code>dest</code> vector
* and return it.
*
* @param dest
* will hold the result
* @return dest
*/
public Vector3d xyz(Vector3d dest) {
return dest.set(x, y, z);
}

public float y() {
return this.y;
}
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/org/joml/Vector4i.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,42 @@ public int x() {
return this.x;
}

/**
* Copy the <code>(x, y, z)</code> components of <code>this</code> into the supplied <code>dest</code> vector
* and return it.
*
* @param dest
* will hold the result
* @return dest
*/
public Vector3f xyz(Vector3f dest) {
return dest.set(x, y, z);
}

/**
* Copy the <code>(x, y, z)</code> components of <code>this</code> into the supplied <code>dest</code> vector
* and return it.
*
* @param dest
* will hold the result
* @return dest
*/
public Vector3d xyz(Vector3d dest) {
return dest.set(x, y, z);
}

/**
* Copy the <code>(x, y, z)</code> components of <code>this</code> into the supplied <code>dest</code> vector
* and return it.
*
* @param dest
* will hold the result
* @return dest
*/
public Vector3i xyz(Vector3i dest) {
return dest.set(x, y, z);
}

public int y() {
return this.y;
}
Expand Down

0 comments on commit bbc988e

Please sign in to comment.