Explorar o código

Add simple math methods to Vector2f (#1756)

Ryan McDonough %!s(int64=3) %!d(string=hai) anos
pai
achega
0768b851cf
Modificáronse 1 ficheiros con 54 adicións e 2 borrados
  1. 54 2
      jme3-core/src/main/java/com/jme3/math/Vector2f.java

+ 54 - 2
jme3-core/src/main/java/com/jme3/math/Vector2f.java

@@ -402,7 +402,33 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
         product.y = y * scalar;
         return product;
     }
-
+    
+    /**
+     * Multiplies component-wise by the specified components and returns the 
+     * product as a new instance. The current instance is unaffected.
+     *
+     * @param x the scale factor for the X component
+     * @param y the scale factor for the Y component
+     * @return a new Vector2f
+     */
+    public Vector2f mult(float x, float y) {
+        return new Vector2f(this.x * x, this.y * y);
+    }
+    
+    /**
+     * Multiplies component-wise by the specified components and returns the 
+     * (modified) current instance.
+     *
+     * @param x the scale factor for the X component
+     * @param y the scale factor for the Y component
+     * @return the (modified) current instance (for chaining)
+     */
+    public Vector2f multLocal(float x, float y) {
+        this.x *= x;
+        this.y *= y;
+        return this;
+    }
+    
     /**
      * Divides by the scalar argument and returns the quotient as a new
      * instance. The current instance is unaffected.
@@ -426,7 +452,33 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
         y /= scalar;
         return this;
     }
-
+    
+    /**
+     * Divides component-wise by the specified components and returns the quotient
+     * as a new instance. The current instance is unaffected.
+     *
+     * @param x the divisor for the X component
+     * @param y the divisor for the Y component
+     * @return a new Vector2f
+     */
+    public Vector2f divide(float x, float y) {
+        return new Vector2f(this.x / x, this.y / y);
+    }
+ 
+    /**
+     * Divides component-wise by the specified components returns the (modified) 
+     * current instance.
+     *
+     * @param x the divisor for the X component
+     * @param y the divisor for the Y component
+     * @return the (modified) current instance (for chaining)
+     */
+    public Vector2f divideLocal(float x, float y) {
+        this.x /= x;
+        this.y /= y;
+        return this;
+    }
+        
     /**
      * Returns the negative of the vector. The current instance is unaffected.
      *