Changed Vector.mult to Vector.scale and clarified the javadocs.
As Tim points out, vector multiplication implies dot or cross products. These methods are scaling, not multiplying. Cross product coming in a future commit.
This commit is contained in:
@@ -34,7 +34,7 @@ public abstract class AbstractVector implements IVector
|
|||||||
|
|
||||||
@Override // from interface IVector
|
@Override // from interface IVector
|
||||||
public Vector normalize (Vector result) {
|
public Vector normalize (Vector result) {
|
||||||
return mult(1f / length(), result);
|
return scale(1f / length(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IVector
|
@Override // from interface IVector
|
||||||
@@ -71,22 +71,22 @@ public abstract class AbstractVector implements IVector
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IVector
|
@Override // from interface IVector
|
||||||
public Vector mult (double v) {
|
public Vector scale (double v) {
|
||||||
return mult(v, new Vector());
|
return scale(v, new Vector());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IVector
|
@Override // from interface IVector
|
||||||
public Vector mult (double v, Vector result) {
|
public Vector scale (double v, Vector result) {
|
||||||
return result.set(x()*v, y()*v);
|
return result.set(x()*v, y()*v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IVector
|
@Override // from interface IVector
|
||||||
public Vector mult (IVector other) {
|
public Vector scale (IVector other) {
|
||||||
return mult(other, new Vector());
|
return scale(other, new Vector());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IVector
|
@Override // from interface IVector
|
||||||
public Vector mult (IVector other, Vector result) {
|
public Vector scale (IVector other, Vector result) {
|
||||||
return result.set(x()*other.x(), y()*other.y());
|
return result.set(x()*other.x(), y()*other.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,21 +52,24 @@ public interface IVector
|
|||||||
/** Returns the squared distance from this vector to the specified other. */
|
/** Returns the squared distance from this vector to the specified other. */
|
||||||
double distanceSq (IVector other);
|
double distanceSq (IVector other);
|
||||||
|
|
||||||
/** Multiplies this vector by a scalar.
|
/** Scales this vector uniformly by the specified magnitude.
|
||||||
* @return a new vector containing the result. */
|
* @return a new vector containing the result. */
|
||||||
Vector mult (double v);
|
Vector scale (double v);
|
||||||
|
|
||||||
/** Multiplies this vector by a scalar and places the result in the supplied object.
|
/** Scales this vector uniformly by the specified magnitude, and places the result in the
|
||||||
|
* supplied object.
|
||||||
* @return a reference to the result, for chaining. */
|
* @return a reference to the result, for chaining. */
|
||||||
Vector mult (double v, Vector result);
|
Vector scale (double v, Vector result);
|
||||||
|
|
||||||
/** Multiplies this vector by another.
|
/** Scales this vector's x and y components independently by the x and y components of the
|
||||||
|
* supplied vector.
|
||||||
* @return a new vector containing the result. */
|
* @return a new vector containing the result. */
|
||||||
Vector mult (IVector other);
|
Vector scale (IVector other);
|
||||||
|
|
||||||
/** Multiplies this vector by another, storing the result in the object provided.
|
/** Scales this vector's x and y components independently by the x and y components of the
|
||||||
|
* supplied vector, and stores the result in the object provided.
|
||||||
* @return a reference to the result vector, for chaining. */
|
* @return a reference to the result vector, for chaining. */
|
||||||
Vector mult (IVector other, Vector result);
|
Vector scale (IVector other, Vector result);
|
||||||
|
|
||||||
/** Adds a vector to this one.
|
/** Adds a vector to this one.
|
||||||
* @return a new vector containing the result. */
|
* @return a new vector containing the result. */
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ public class NonUniformTransform extends AbstractTransform
|
|||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform invert () {
|
public Transform invert () {
|
||||||
Vector iscale = new Vector(1f / scaleX, 1f / scaleY);
|
Vector iscale = new Vector(1f / scaleX, 1f / scaleY);
|
||||||
Vector t = new Vector(tx, ty).negateLocal().rotateLocal(-rotation).multLocal(iscale);
|
Vector t = new Vector(tx, ty).negateLocal().rotateLocal(-rotation).scaleLocal(iscale);
|
||||||
return new NonUniformTransform(iscale.x, iscale.y, -rotation, t.x, t.y);
|
return new NonUniformTransform(iscale.x, iscale.y, -rotation, t.x, t.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public class UniformTransform extends AbstractTransform
|
|||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform invert () {
|
public Transform invert () {
|
||||||
double nscale = 1f / scale, nrotation = -rotation;
|
double nscale = 1f / scale, nrotation = -rotation;
|
||||||
Vector t = translation().negateLocal().rotateLocal(nrotation).multLocal(nscale);
|
Vector t = translation().negateLocal().rotateLocal(nrotation).scaleLocal(nscale);
|
||||||
return new UniformTransform(nscale, nrotation, t.x, t.y);
|
return new UniformTransform(nscale, nrotation, t.x, t.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,16 +41,17 @@ public class Vector extends AbstractVector
|
|||||||
return normalize(this);
|
return normalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Multiplies this vector in-place by a scalar.
|
/** Scales this vector in place, uniformly by the specified magnitude.
|
||||||
* @return a reference to this vector, for chaining. */
|
* @return a reference to this vector, for chaining. */
|
||||||
public Vector multLocal (double v) {
|
public Vector scaleLocal (double v) {
|
||||||
return mult(v, this);
|
return scale(v, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Multiplies this vector in-place by another.
|
/** Scales this vector's x and y components, in place, independently by the x and y components
|
||||||
|
* of the supplied vector.
|
||||||
* @return a reference to this vector, for chaining. */
|
* @return a reference to this vector, for chaining. */
|
||||||
public Vector multLocal (IVector other) {
|
public Vector scaleLocal (IVector other) {
|
||||||
return mult(other, this);
|
return scale(other, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds a vector in-place to this one.
|
/** Adds a vector in-place to this one.
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public abstract class AbstractVector implements IVector
|
|||||||
|
|
||||||
@Override // from interface IVector
|
@Override // from interface IVector
|
||||||
public Vector normalize (Vector result) {
|
public Vector normalize (Vector result) {
|
||||||
return mult(1f / length(), result);
|
return scale(1f / length(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IVector
|
@Override // from interface IVector
|
||||||
@@ -71,22 +71,22 @@ public abstract class AbstractVector implements IVector
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IVector
|
@Override // from interface IVector
|
||||||
public Vector mult (float v) {
|
public Vector scale (float v) {
|
||||||
return mult(v, new Vector());
|
return scale(v, new Vector());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IVector
|
@Override // from interface IVector
|
||||||
public Vector mult (float v, Vector result) {
|
public Vector scale (float v, Vector result) {
|
||||||
return result.set(x()*v, y()*v);
|
return result.set(x()*v, y()*v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IVector
|
@Override // from interface IVector
|
||||||
public Vector mult (IVector other) {
|
public Vector scale (IVector other) {
|
||||||
return mult(other, new Vector());
|
return scale(other, new Vector());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // from interface IVector
|
@Override // from interface IVector
|
||||||
public Vector mult (IVector other, Vector result) {
|
public Vector scale (IVector other, Vector result) {
|
||||||
return result.set(x()*other.x(), y()*other.y());
|
return result.set(x()*other.x(), y()*other.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,21 +52,24 @@ public interface IVector
|
|||||||
/** Returns the squared distance from this vector to the specified other. */
|
/** Returns the squared distance from this vector to the specified other. */
|
||||||
float distanceSq (IVector other);
|
float distanceSq (IVector other);
|
||||||
|
|
||||||
/** Multiplies this vector by a scalar.
|
/** Scales this vector uniformly by the specified magnitude.
|
||||||
* @return a new vector containing the result. */
|
* @return a new vector containing the result. */
|
||||||
Vector mult (float v);
|
Vector scale (float v);
|
||||||
|
|
||||||
/** Multiplies this vector by a scalar and places the result in the supplied object.
|
/** Scales this vector uniformly by the specified magnitude, and places the result in the
|
||||||
|
* supplied object.
|
||||||
* @return a reference to the result, for chaining. */
|
* @return a reference to the result, for chaining. */
|
||||||
Vector mult (float v, Vector result);
|
Vector scale (float v, Vector result);
|
||||||
|
|
||||||
/** Multiplies this vector by another.
|
/** Scales this vector's x and y components independently by the x and y components of the
|
||||||
|
* supplied vector.
|
||||||
* @return a new vector containing the result. */
|
* @return a new vector containing the result. */
|
||||||
Vector mult (IVector other);
|
Vector scale (IVector other);
|
||||||
|
|
||||||
/** Multiplies this vector by another, storing the result in the object provided.
|
/** Scales this vector's x and y components independently by the x and y components of the
|
||||||
|
* supplied vector, and stores the result in the object provided.
|
||||||
* @return a reference to the result vector, for chaining. */
|
* @return a reference to the result vector, for chaining. */
|
||||||
Vector mult (IVector other, Vector result);
|
Vector scale (IVector other, Vector result);
|
||||||
|
|
||||||
/** Adds a vector to this one.
|
/** Adds a vector to this one.
|
||||||
* @return a new vector containing the result. */
|
* @return a new vector containing the result. */
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ public class NonUniformTransform extends AbstractTransform
|
|||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform invert () {
|
public Transform invert () {
|
||||||
Vector iscale = new Vector(1f / scaleX, 1f / scaleY);
|
Vector iscale = new Vector(1f / scaleX, 1f / scaleY);
|
||||||
Vector t = new Vector(tx, ty).negateLocal().rotateLocal(-rotation).multLocal(iscale);
|
Vector t = new Vector(tx, ty).negateLocal().rotateLocal(-rotation).scaleLocal(iscale);
|
||||||
return new NonUniformTransform(iscale.x, iscale.y, -rotation, t.x, t.y);
|
return new NonUniformTransform(iscale.x, iscale.y, -rotation, t.x, t.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public class UniformTransform extends AbstractTransform
|
|||||||
@Override // from Transform
|
@Override // from Transform
|
||||||
public Transform invert () {
|
public Transform invert () {
|
||||||
float nscale = 1f / scale, nrotation = -rotation;
|
float nscale = 1f / scale, nrotation = -rotation;
|
||||||
Vector t = translation().negateLocal().rotateLocal(nrotation).multLocal(nscale);
|
Vector t = translation().negateLocal().rotateLocal(nrotation).scaleLocal(nscale);
|
||||||
return new UniformTransform(nscale, nrotation, t.x, t.y);
|
return new UniformTransform(nscale, nrotation, t.x, t.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,16 +41,17 @@ public class Vector extends AbstractVector
|
|||||||
return normalize(this);
|
return normalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Multiplies this vector in-place by a scalar.
|
/** Scales this vector in place, uniformly by the specified magnitude.
|
||||||
* @return a reference to this vector, for chaining. */
|
* @return a reference to this vector, for chaining. */
|
||||||
public Vector multLocal (float v) {
|
public Vector scaleLocal (float v) {
|
||||||
return mult(v, this);
|
return scale(v, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Multiplies this vector in-place by another.
|
/** Scales this vector's x and y components, in place, independently by the x and y components
|
||||||
|
* of the supplied vector.
|
||||||
* @return a reference to this vector, for chaining. */
|
* @return a reference to this vector, for chaining. */
|
||||||
public Vector multLocal (IVector other) {
|
public Vector scaleLocal (IVector other) {
|
||||||
return mult(other, this);
|
return scale(other, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds a vector in-place to this one.
|
/** Adds a vector in-place to this one.
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ public class TransformTest
|
|||||||
test(tpre, point, expect);
|
test(tpre, point, expect);
|
||||||
}
|
}
|
||||||
for (Vector vector : VECTORS) {
|
for (Vector vector : VECTORS) {
|
||||||
Vector expect = vector.mult(scale);
|
Vector expect = vector.scale(scale);
|
||||||
test(t, vector, expect);
|
test(t, vector, expect);
|
||||||
test(tpost, vector, expect);
|
test(tpost, vector, expect);
|
||||||
test(tpre, vector, expect);
|
test(tpre, vector, expect);
|
||||||
@@ -177,7 +177,7 @@ public class TransformTest
|
|||||||
test(tpre, point, expect);
|
test(tpre, point, expect);
|
||||||
}
|
}
|
||||||
for (Vector vector : VECTORS) {
|
for (Vector vector : VECTORS) {
|
||||||
Vector expect = vector.mult(scale);
|
Vector expect = vector.scale(scale);
|
||||||
test(t, vector, expect);
|
test(t, vector, expect);
|
||||||
test(tpost, vector, expect);
|
test(tpost, vector, expect);
|
||||||
test(tpre, vector, expect);
|
test(tpre, vector, expect);
|
||||||
@@ -207,7 +207,7 @@ public class TransformTest
|
|||||||
test(tpre, point, expect);
|
test(tpre, point, expect);
|
||||||
}
|
}
|
||||||
for (Vector vector : VECTORS) {
|
for (Vector vector : VECTORS) {
|
||||||
Vector expect = vector.rotate(angle).multLocal(scale);
|
Vector expect = vector.rotate(angle).scaleLocal(scale);
|
||||||
test(t, vector, expect);
|
test(t, vector, expect);
|
||||||
test(tpost, vector, expect);
|
test(tpost, vector, expect);
|
||||||
test(tpre, vector, expect);
|
test(tpre, vector, expect);
|
||||||
@@ -236,7 +236,7 @@ public class TransformTest
|
|||||||
test(tpre, point, expect);
|
test(tpre, point, expect);
|
||||||
}
|
}
|
||||||
for (Vector vector : VECTORS) {
|
for (Vector vector : VECTORS) {
|
||||||
Vector expect = vector.mult(scale).rotateLocal(angle);
|
Vector expect = vector.scale(scale).rotateLocal(angle);
|
||||||
test(tpost, vector, expect);
|
test(tpost, vector, expect);
|
||||||
test(tpre, vector, expect);
|
test(tpre, vector, expect);
|
||||||
}
|
}
|
||||||
@@ -255,7 +255,7 @@ public class TransformTest
|
|||||||
test(t, point, expect);
|
test(t, point, expect);
|
||||||
}
|
}
|
||||||
for (Vector vector : VECTORS) {
|
for (Vector vector : VECTORS) {
|
||||||
Vector expect = vector.mult(scale).rotateLocal(angle);
|
Vector expect = vector.scale(scale).rotateLocal(angle);
|
||||||
test(t, vector, expect);
|
test(t, vector, expect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,7 +286,7 @@ public class TransformTest
|
|||||||
test(tpre, point, expect);
|
test(tpre, point, expect);
|
||||||
}
|
}
|
||||||
for (Vector vector : VECTORS) {
|
for (Vector vector : VECTORS) {
|
||||||
Vector expect = vector.mult(scale).rotateLocal(angle);
|
Vector expect = vector.scale(scale).rotateLocal(angle);
|
||||||
test(tpost, vector, expect);
|
test(tpost, vector, expect);
|
||||||
test(tpre, vector, expect);
|
test(tpre, vector, expect);
|
||||||
}
|
}
|
||||||
@@ -307,7 +307,7 @@ public class TransformTest
|
|||||||
test(t, point, expect);
|
test(t, point, expect);
|
||||||
}
|
}
|
||||||
for (Vector vector : VECTORS) {
|
for (Vector vector : VECTORS) {
|
||||||
Vector expect = vector.mult(scale).rotateLocal(angle);
|
Vector expect = vector.scale(scale).rotateLocal(angle);
|
||||||
test(t, vector, expect);
|
test(t, vector, expect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user