Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a convenient method to clamp the vector's components. #7369

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
12 changes: 12 additions & 0 deletions gdx/src/com/badlogic/gdx/math/Vector3.java
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,18 @@ public boolean epsilonEquals (float x, float y, float z) {
return epsilonEquals(x, y, z, MathUtils.FLOAT_ROUNDING_ERROR);
}

/** Clamps the vector's X, Y and Z with the given boundaries.
*
* @param min The minimum value to clamp the vector's components
* @param max The maximum value to clamp the vector's components
* @return this vector for chaining */
public Vector3 clampComponents (float min, float max) {
x = MathUtils.clamp(x, min, max);
y = MathUtils.clamp(y, min, max);
z = MathUtils.clamp(z, min, max);
return this;
}

@Override
public Vector3 setZero () {
this.x = 0;
Expand Down