Skip to content

Commit

Permalink
Add Vector2d(Vector3) constructors and Vector2d.set(Vector3) setters (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
httpdigest committed Jun 30, 2023
1 parent d462744 commit 7dc7156
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/main/java/org/joml/Vector2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,42 @@ public Vector2d(Vector2ic v) {
y = v.y();
}

/**
* Create a new {@link Vector2d} and initialize its components using the <code>x</code> and <code>y</code>
* components of the provided vector.
*
* @param v
* the {@link Vector3dc} to copy the <code>x</code> and <code>y</code> components from
*/
public Vector2d(Vector3dc v) {
x = v.x();
y = v.y();
}

/**
* Create a new {@link Vector2d} and initialize its components using the <code>x</code> and <code>y</code>
* components of the provided vector.
*
* @param v
* the {@link Vector3fc} to copy the <code>x</code> and <code>y</code> components from
*/
public Vector2d(Vector3fc v) {
x = v.x();
y = v.y();
}

/**
* Create a new {@link Vector2d} and initialize its components using the <code>x</code> and <code>y</code>
* components of the provided vector.
*
* @param v
* the {@link Vector3ic} to copy the <code>x</code> and <code>y</code> components from
*/
public Vector2d(Vector3ic v) {
x = v.x();
y = v.y();
}

/**
* Create a new {@link Vector2d} and initialize its two components from the first
* two elements of the given array.
Expand Down Expand Up @@ -284,6 +320,45 @@ public Vector2d set(Vector2ic v) {
return this;
}

/**
* Set this {@link Vector2d} to the <code>(x, y)</code> components of <code>v</code>.
*
* @param v
* the vector to copy from
* @return this
*/
public Vector2d set(Vector3dc v) {
this.x = v.x();
this.y = v.y();
return this;
}

/**
* Set this {@link Vector2d} to the <code>(x, y)</code> components of <code>v</code>.
*
* @param v
* the vector to copy from
* @return this
*/
public Vector2d set(Vector3fc v) {
this.x = v.x();
this.y = v.y();
return this;
}

/**
* Set this {@link Vector2i} to the <code>(x, y)</code> components of <code>v</code>.
*
* @param v
* the vector to copy from
* @return this
*/
public Vector2d set(Vector3ic v) {
this.x = v.x();
this.y = v.y();
return this;
}

/**
* Set the two components of this vector to the first two elements of the given array.
*
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/org/joml/Vector2f.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,45 @@ public Vector2f(Vector2ic v) {
y = v.y();
}

/**
* Create a new {@link Vector2f} and initialize its components using the <code>x</code> and <code>y</code>
* components of the provided vector.
*
* @param v
* the {@link Vector3fc} to copy the <code>x</code> and <code>y</code> components from
*/
public Vector2f(Vector3fc v) {
x = v.x();
y = v.y();
}

/**
* Create a new {@link Vector2f} and initialize its components using the <code>x</code> and <code>y</code>
* components of the provided vector.
* <p>
* Note that due to the given vector <code>v</code> storing the components in double-precision,
* there is the possibility to lose precision.
*
* @param v
* the {@link Vector3dc} to copy the <code>x</code> and <code>y</code> components from
*/
public Vector2f(Vector3dc v) {
x = (float) v.x();
y = (float) v.y();
}

/**
* Create a new {@link Vector2f} and initialize its components using the <code>x</code> and <code>y</code>
* components of the provided vector.
*
* @param v
* the {@link Vector3ic} to copy the <code>x</code> and <code>y</code> components from
*/
public Vector2f(Vector3ic v) {
x = v.x();
y = v.y();
}

/**
* Create a new {@link Vector2f} and initialize its two components from the first
* two elements of the given array.
Expand Down Expand Up @@ -291,6 +330,48 @@ public Vector2f set(Vector2dc v) {
return this;
}

/**
* Set this {@link Vector2f} to the <code>(x, y)</code> components of <code>v</code>.
* <p>
* Note that due to the given vector <code>v</code> storing the components in double-precision,
* there is the possibility to lose precision.
*
* @param v
* the vector to copy from
* @return this
*/
public Vector2f set(Vector3dc v) {
this.x = (float) v.x();
this.y = (float) v.y();
return this;
}

/**
* Set this {@link Vector2f} to the <code>(x, y)</code> components of <code>v</code>.
*
* @param v
* the vector to copy from
* @return this
*/
public Vector2f set(Vector3fc v) {
this.x = v.x();
this.y = v.y();
return this;
}

/**
* Set this {@link Vector2f} to the <code>(x, y)</code> components of <code>v</code>.
*
* @param v
* the vector to copy from
* @return this
*/
public Vector2f set(Vector3ic v) {
this.x = v.x();
this.y = v.y();
return this;
}

/**
* Set the two components of this vector to the first two elements of the given array.
*
Expand Down

0 comments on commit 7dc7156

Please sign in to comment.