Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ABF749322 for ; Thu, 10 Nov 2011 21:04:20 +0000 (UTC) Received: (qmail 77704 invoked by uid 500); 10 Nov 2011 21:04:20 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 77655 invoked by uid 500); 10 Nov 2011 21:04:20 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 77648 invoked by uid 99); 10 Nov 2011 21:04:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Nov 2011 21:04:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Nov 2011 21:04:17 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BEEEB2388993 for ; Thu, 10 Nov 2011 21:03:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1200546 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/geometry/euclidean/threed/ main/java/org/apache/commons/math/geometry/euclidean/twod/ site/xdoc/ test/java/org/apache/commons/math/geometry/euclidean/threed/ Date: Thu, 10 Nov 2011 21:03:55 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111110210355.BEEEB2388993@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: luc Date: Thu Nov 10 21:03:55 2011 New Revision: 1200546 URL: http://svn.apache.org/viewvc?rev=1200546&view=rev Log: Added array constructor and getter for Vector2D and Vector3D. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Vector3D.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Vector2D.java commons/proper/math/trunk/src/site/xdoc/changes.xml commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/Vector3DTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Vector3D.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Vector3D.java?rev=1200546&r1=1200545&r2=1200546&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Vector3D.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Vector3D.java Thu Nov 10 21:03:55 2011 @@ -20,6 +20,7 @@ package org.apache.commons.math.geometry import java.io.Serializable; import java.text.NumberFormat; +import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.MathArithmeticException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.geometry.Vector; @@ -98,6 +99,21 @@ public class Vector3D implements Seriali } /** Simple constructor. + * Build a vector from its coordinates + * @param v coordinates array + * @exception DimensionMismatchException if array does not have 3 elements + * @see #toArray() + */ + public Vector3D(double[] v) throws DimensionMismatchException { + if (v.length != 3) { + throw new DimensionMismatchException(v.length, 3); + } + this.x = v[0]; + this.y = v[1]; + this.z = v[2]; + } + + /** Simple constructor. * Build a vector from its azimuthal coordinates * @param alpha azimuth (α) around Z * (0 is +X, π/2 is +Y, π is -X and 3π/2 is -Y) @@ -198,6 +214,14 @@ public class Vector3D implements Seriali return z; } + /** Get the vector coordinates as a dimension 3 array. + * @return vector coordinates + * @see #Vector3D(double[]) + */ + public double[] toArray() { + return new double[] { x, y, z }; + } + /** {@inheritDoc} */ public Space getSpace() { return Euclidean3D.getInstance(); Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Vector2D.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Vector2D.java?rev=1200546&r1=1200545&r2=1200546&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Vector2D.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/twod/Vector2D.java Thu Nov 10 21:03:55 2011 @@ -18,6 +18,7 @@ package org.apache.commons.math.geometry import java.text.NumberFormat; +import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.MathArithmeticException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.geometry.Space; @@ -69,6 +70,20 @@ public class Vector2D implements Vector< this.y = y; } + /** Simple constructor. + * Build a vector from its coordinates + * @param v coordinates array + * @exception DimensionMismatchException if array does not have 2 elements + * @see #toArray() + */ + public Vector2D(double[] v) throws DimensionMismatchException { + if (v.length != 2) { + throw new DimensionMismatchException(v.length, 2); + } + this.x = v[0]; + this.y = v[1]; + } + /** Multiplicative constructor * Build a vector from another one and a scale factor. * The vector built will be a * u @@ -143,6 +158,14 @@ public class Vector2D implements Vector< return y; } + /** Get the vector coordinates as a dimension 2 array. + * @return vector coordinates + * @see #Vector2D(double[]) + */ + public double[] toArray() { + return new double[] { x, y }; + } + /** {@inheritDoc} */ public Space getSpace() { return Euclidean2D.getInstance(); Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1200546&r1=1200545&r2=1200546&view=diff ============================================================================== --- commons/proper/math/trunk/src/site/xdoc/changes.xml (original) +++ commons/proper/math/trunk/src/site/xdoc/changes.xml Thu Nov 10 21:03:55 2011 @@ -53,6 +53,9 @@ The type attribute can be add,u --> + Added array constructor and getter for Vector2D and Vector3D. + + Added applyTo and applyInverseTo methods in the Rotation class that handle directly arrays instead of Vector3D instances. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/Vector3DTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/Vector3DTest.java?rev=1200546&r1=1200545&r2=1200546&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/Vector3DTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/Vector3DTest.java Thu Nov 10 21:03:55 2011 @@ -17,6 +17,7 @@ package org.apache.commons.math.geometry.euclidean.threed; +import org.apache.commons.math.exception.DimensionMismatchException; import org.apache.commons.math.exception.MathArithmeticException; import org.apache.commons.math.random.Well1024a; import org.apache.commons.math.util.FastMath; @@ -41,6 +42,13 @@ public class Vector3DTest { 5, Vector3D.MINUS_J, -3, Vector3D.MINUS_K), 2, 0, 3); + checkVector(new Vector3D(new double[] { 2, 5, -3 }), + 2, 5, -3); + } + + @Test(expected=DimensionMismatchException.class) + public void testWrongDimension() { + new Vector3D(new double[] { 2, 5 }); } @Test @@ -49,6 +57,10 @@ public class Vector3DTest { Assert.assertTrue(FastMath.abs(v.getX() - 1) < 1.0e-12); Assert.assertTrue(FastMath.abs(v.getY() - 2) < 1.0e-12); Assert.assertTrue(FastMath.abs(v.getZ() - 3) < 1.0e-12); + double[] coordinates = v.toArray(); + Assert.assertTrue(FastMath.abs(coordinates[0] - 1) < 1.0e-12); + Assert.assertTrue(FastMath.abs(coordinates[1] - 2) < 1.0e-12); + Assert.assertTrue(FastMath.abs(coordinates[2] - 3) < 1.0e-12); } @Test