Skip to content

Commit

Permalink
Add Vector3.xy(Vector2) swizzle (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
httpdigest committed Jun 30, 2023
1 parent 6b65259 commit d475251
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/Vector3d.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,33 @@ public double x() {
return this.x;
}

/**
* Copy the <code>(x, y)</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 Vector2f xy(Vector2f dest) {
return dest.set(x, y);
}

/**
* Copy the <code>(x, y)</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 Vector2d xy(Vector2d dest) {
return dest.set(x, y);
}

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

/**
* Copy the <code>(x, y)</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 Vector2f xy(Vector2f dest) {
return dest.set(x, y);
}

/**
* Copy the <code>(x, y)</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 Vector2d xy(Vector2d dest) {
return dest.set(x, y);
}

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

/**
* Copy the <code>(x, y)</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 Vector2f xy(Vector2f dest) {
return dest.set(x, y);
}

/**
* Copy the <code>(x, y)</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 Vector2d xy(Vector2d dest) {
return dest.set(x, y);
}

/**
* Copy the <code>(x, y)</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 Vector2i xy(Vector2i dest) {
return dest.set(x, y);
}

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

0 comments on commit d475251

Please sign in to comment.