From 7f5355a3ea4c4492e27e8f2a0f00289983f5be61 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Fri, 15 Feb 2008 10:24:50 +0000 Subject: [PATCH] improved consistency between Vector3D and RealMatrix API (multiply -> scalarMultiply) improved javadoc git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@627998 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/math/geometry/Vector3D.java | 13 +++++++------ .../apache/commons/math/geometry/RotationTest.java | 2 +- .../apache/commons/math/geometry/Vector3DTest.java | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/java/org/apache/commons/math/geometry/Vector3D.java b/src/java/org/apache/commons/math/geometry/Vector3D.java index d00bba0a0..8616bc11d 100644 --- a/src/java/org/apache/commons/math/geometry/Vector3D.java +++ b/src/java/org/apache/commons/math/geometry/Vector3D.java @@ -232,16 +232,16 @@ public class Vector3D return new Vector3D(x - factor * v.x, y - factor * v.y, z - factor * v.z); } - /** Normalize the instance. + /** Get a normalized vector aligned with the instance. * @return a new normalized vector - * @exception ArithmeticException if the norm is null + * @exception ArithmeticException if the norm is zero */ public Vector3D normalize() { double s = getNorm(); if (s == 0) { - throw new ArithmeticException("null norm"); + throw new ArithmeticException("cannot normalize a zero norm vector"); } - return multiply(1 / s); + return scalarMultiply(1 / s); } /** Get a vector orthogonal to the instance. @@ -323,7 +323,7 @@ public class Vector3D * @param a scalar * @return a new vector */ - public Vector3D multiply(double a) { + public Vector3D scalarMultiply(double a) { return new Vector3D(a * x, a * y, a * z); } @@ -357,6 +357,7 @@ public class Vector3D private final double z; /** Serializable version identifier */ - private static final long serialVersionUID = 7318440192750283659L; + private static final long serialVersionUID = -5721105387745193385L; + } diff --git a/src/test/org/apache/commons/math/geometry/RotationTest.java b/src/test/org/apache/commons/math/geometry/RotationTest.java index 9b53fda7a..3f6c11cd5 100644 --- a/src/test/org/apache/commons/math/geometry/RotationTest.java +++ b/src/test/org/apache/commons/math/geometry/RotationTest.java @@ -98,7 +98,7 @@ public class RotationTest Vector3D u = new Vector3D(3, 2, 1); Vector3D v = new Vector3D(-4, 2, 2); Rotation r = new Rotation(u, v); - checkVector(r.applyTo(u.multiply(v.getNorm())), v.multiply(u.getNorm())); + checkVector(r.applyTo(u.scalarMultiply(v.getNorm())), v.scalarMultiply(u.getNorm())); checkAngle(new Rotation(u, u.negate()).getAngle(), Math.PI); diff --git a/src/test/org/apache/commons/math/geometry/Vector3DTest.java b/src/test/org/apache/commons/math/geometry/Vector3DTest.java index 5c4bdfd01..8d4430daf 100644 --- a/src/test/org/apache/commons/math/geometry/Vector3DTest.java +++ b/src/test/org/apache/commons/math/geometry/Vector3DTest.java @@ -84,10 +84,10 @@ public class Vector3DTest public void testScalarProduct() { Vector3D v = new Vector3D(1, 2, 3); - v = v.multiply(3); + v = v.scalarMultiply(3); checkVector(v, 3, 6, 9); - checkVector(v.multiply(0.5), 1.5, 3, 4.5); + checkVector(v.scalarMultiply(0.5), 1.5, 3, 4.5); } @@ -125,7 +125,7 @@ public class Vector3DTest Vector3D k = v1.normalize(); Vector3D i = k.orthogonal(); - Vector3D v2 = k.multiply(Math.cos(1.2)).add(i.multiply(Math.sin(1.2))); + Vector3D v2 = k.scalarMultiply(Math.cos(1.2)).add(i.scalarMultiply(Math.sin(1.2))); assertTrue(Math.abs(Vector3D.angle(v1, v2) - 1.2) < 1.0e-12);