Skip to content

Commit 2c05c10

Browse files
authored
Add more simple math methods to Vector classes (#1744)
I've added these convenience multiplication and division methods that were missing from the Vector3f class, and did my best to also follow the same javadoc formatting. Let me know if this looks alright and then I will do the same for Vector2f and Vector4f. Should I make the changes to Vector2f and Vector4f in this PR or should I make a new PR for each?
1 parent 78bfa81 commit 2c05c10

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

jme3-core/src/main/java/com/jme3/math/Vector3f.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,20 @@ public Vector3f mult(Vector3f vec) {
569569
}
570570
return mult(vec, null);
571571
}
572-
572+
573+
/**
574+
* Multiplies component-wise by the specified components and returns the
575+
* product as a new instance. The current instance is unaffected.
576+
*
577+
* @param x the scale factor for the X component
578+
* @param y the scale factor for the Y component
579+
* @param z the scale factor for the Z component
580+
* @return a new Vector3f
581+
*/
582+
public Vector3f mult(float x, float y, float z) {
583+
return new Vector3f(this.x * x, this.y * y, this.z * z);
584+
}
585+
573586
/**
574587
* Multiplies component-wise with the specified vector and returns the
575588
* product in a 3rd vector. If the argument is null, null is returned.
@@ -617,6 +630,22 @@ public Vector3f divideLocal(float scalar) {
617630
z *= scalar;
618631
return this;
619632
}
633+
634+
/**
635+
* Divides component-wise by the specified components returns the (modified)
636+
* current instance.
637+
*
638+
* @param x the divisor for the X component
639+
* @param y the divisor for the Y component
640+
* @param z the divisor for the Z component
641+
* @return the (modified) current instance (for chaining)
642+
*/
643+
public Vector3f divideLocal(float x, float y, float z) {
644+
this.x /= x;
645+
this.y /= y;
646+
this.z /= z;
647+
return this;
648+
}
620649

621650
/**
622651
* Divides component-wise by the argument and returns the quotient as a new
@@ -629,6 +658,19 @@ public Vector3f divide(Vector3f divisor) {
629658
return new Vector3f(x / divisor.x, y / divisor.y, z / divisor.z);
630659
}
631660

661+
/**
662+
* Divides component-wise by the specified components and returns the quotient
663+
* as a new instance. The current instance is unaffected.
664+
*
665+
* @param x the divisor for the X component
666+
* @param y the divisor for the Y component
667+
* @param z the divisor for the Z component
668+
* @return a new Vector3f
669+
*/
670+
public Vector3f divide(float x, float y, float z) {
671+
return new Vector3f(this.x / x, this.y / y, this.z / z);
672+
}
673+
632674
/**
633675
* Divides component-wise by the argument and returns the (modified) current
634676
* instance.

0 commit comments

Comments
 (0)