You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2017/05/06 15:04:31 UTC
[18/19] [math] MATH-1284: Restore Vector3D class as an abstract
implementation of Vector and now Cartesian3D extends Vector3D.
Restore the public interface of Vector3DFormat to act on Vector3D.
MATH-1284: Restore Vector3D class as an abstract implementation of Vector<Euclidean3D> and now Cartesian3D extends Vector3D.
Restore the public interface of Vector3DFormat to act on Vector3D.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/05edf063
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/05edf063
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/05edf063
Branch: refs/heads/feature-MATH-1284
Commit: 05edf06360cc8a1a61fbd1ce5f9abf5d83f9d3f9
Parents: 09c55eb
Author: Ray DeCampo <ra...@decampo.org>
Authored: Sat May 6 10:59:17 2017 -0400
Committer: Ray DeCampo <ra...@decampo.org>
Committed: Sat May 6 10:59:17 2017 -0400
----------------------------------------------------------------------
.../geometry/euclidean/threed/Cartesian3D.java | 2 +-
.../geometry/euclidean/threed/Vector3D.java | 46 ++++++++++++++++++++
.../euclidean/threed/Vector3DFormat.java | 20 ++++-----
.../threed/Vector3DFormatAbstractTest.java | 42 +++++++++---------
4 files changed, 78 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/05edf063/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java
index 5dc04c5..3880edf 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Cartesian3D.java
@@ -39,7 +39,7 @@ import org.apache.commons.math4.util.MathUtils;
* <p>Instance of this class are guaranteed to be immutable.</p>
* @since 4.0
*/
-public class Cartesian3D implements Serializable, Point<Euclidean3D>, Vector<Euclidean3D> {
+public class Cartesian3D extends Vector3D implements Serializable, Point<Euclidean3D> {
/** Null vector (coordinates: 0, 0, 0). */
public static final Cartesian3D ZERO = new Cartesian3D(0, 0, 0);
http://git-wip-us.apache.org/repos/asf/commons-math/blob/05edf063/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java
new file mode 100644
index 0000000..23d644a
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3D.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math4.geometry.euclidean.threed;
+
+import org.apache.commons.math4.geometry.Vector;
+
+/**
+ * This class implements vectors in a three-dimensional space.
+ * @since 1.2
+ */
+public abstract class Vector3D implements Vector<Euclidean3D> {
+
+ /** Get the abscissa of the vector.
+ * @return abscissa of the vector
+ * @see #Cartesian3D(double, double, double)
+ */
+ public abstract double getX();
+
+ /** Get the ordinate of the vector.
+ * @return ordinate of the vector
+ * @see #Cartesian3D(double, double, double)
+ */
+ public abstract double getY();
+
+ /** Get the height of the vector.
+ * @return height of the vector
+ * @see #Cartesian3D(double, double, double)
+ */
+ public abstract double getZ();
+
+}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/05edf063/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java
index dc2c0f9..1991c53 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormat.java
@@ -104,7 +104,7 @@ public class Vector3DFormat extends VectorFormat<Euclidean3D> {
}
/**
- * Formats a {@link Cartesian3D} object to produce a string.
+ * Formats a {@link Vector3D} object to produce a string.
* @param vector the object to format.
* @param toAppendTo where the text is to be appended
* @param pos On input: an alignment field, if desired. On output: the
@@ -114,37 +114,37 @@ public class Vector3DFormat extends VectorFormat<Euclidean3D> {
@Override
public StringBuffer format(final Vector<Euclidean3D> vector, final StringBuffer toAppendTo,
final FieldPosition pos) {
- final Cartesian3D v3 = (Cartesian3D) vector;
+ final Vector3D v3 = (Vector3D) vector;
return format(toAppendTo, pos, v3.getX(), v3.getY(), v3.getZ());
}
/**
- * Parses a string to produce a {@link Cartesian3D} object.
+ * Parses a string to produce a {@link Vector3D} object.
* @param source the string to parse
- * @return the parsed {@link Cartesian3D} object.
+ * @return the parsed {@link Vector3D} object.
* @throws MathParseException if the beginning of the specified string
* cannot be parsed.
*/
@Override
- public Cartesian3D parse(final String source) throws MathParseException {
+ public Vector3D parse(final String source) throws MathParseException {
ParsePosition parsePosition = new ParsePosition(0);
- Cartesian3D result = parse(source, parsePosition);
+ Vector3D result = parse(source, parsePosition);
if (parsePosition.getIndex() == 0) {
throw new MathParseException(source,
parsePosition.getErrorIndex(),
- Cartesian3D.class);
+ Vector3D.class);
}
return result;
}
/**
- * Parses a string to produce a {@link Cartesian3D} object.
+ * Parses a string to produce a {@link Vector3D} object.
* @param source the string to parse
* @param pos input/ouput parsing parameter.
- * @return the parsed {@link Cartesian3D} object.
+ * @return the parsed {@link Vector3D} object.
*/
@Override
- public Cartesian3D parse(final String source, final ParsePosition pos) {
+ public Vector3D parse(final String source, final ParsePosition pos) {
final double[] coordinates = parseCoordinates(3, source, pos);
if (coordinates == null) {
return null;
http://git-wip-us.apache.org/repos/asf/commons-math/blob/05edf063/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormatAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormatAbstractTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormatAbstractTest.java
index 9092797..5d03373 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormatAbstractTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DFormatAbstractTest.java
@@ -163,8 +163,8 @@ public abstract class Vector3DFormatAbstractTest {
@Test
public void testParseSimpleNoDecimals() throws MathParseException {
String source = "{1; 1; 1}";
- Cartesian3D expected = new Cartesian3D(1, 1, 1);
- Cartesian3D actual = vector3DFormat.parse(source);
+ Vector3D expected = new Cartesian3D(1, 1, 1);
+ Vector3D actual = vector3DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -188,8 +188,8 @@ public abstract class Vector3DFormatAbstractTest {
"23; 1" + getDecimalCharacter() +
"43; 1" + getDecimalCharacter() +
"63}";
- Cartesian3D expected = new Cartesian3D(1.23, 1.43, 1.63);
- Cartesian3D actual = vector3DFormat.parse(source);
+ Vector3D expected = new Cartesian3D(1.23, 1.43, 1.63);
+ Vector3D actual = vector3DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -200,8 +200,8 @@ public abstract class Vector3DFormatAbstractTest {
"2323; 1" + getDecimalCharacter() +
"4343; 1" + getDecimalCharacter() +
"6333}";
- Cartesian3D expected = new Cartesian3D(1.2323, 1.4343, 1.6333);
- Cartesian3D actual = vector3DFormat.parse(source);
+ Vector3D expected = new Cartesian3D(1.2323, 1.4343, 1.6333);
+ Vector3D actual = vector3DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -212,8 +212,8 @@ public abstract class Vector3DFormatAbstractTest {
"2323; 1" + getDecimalCharacter() +
"4343; 1" + getDecimalCharacter() +
"6333}";
- Cartesian3D expected = new Cartesian3D(-1.2323, 1.4343, 1.6333);
- Cartesian3D actual = vector3DFormat.parse(source);
+ Vector3D expected = new Cartesian3D(-1.2323, 1.4343, 1.6333);
+ Vector3D actual = vector3DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -224,8 +224,8 @@ public abstract class Vector3DFormatAbstractTest {
"2323; -1" + getDecimalCharacter() +
"4343; 1" + getDecimalCharacter() +
"6333}";
- Cartesian3D expected = new Cartesian3D(1.2323, -1.4343, 1.6333);
- Cartesian3D actual = vector3DFormat.parse(source);
+ Vector3D expected = new Cartesian3D(1.2323, -1.4343, 1.6333);
+ Vector3D actual = vector3DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -236,8 +236,8 @@ public abstract class Vector3DFormatAbstractTest {
"2323; 1" + getDecimalCharacter() +
"4343; -1" + getDecimalCharacter() +
"6333}";
- Cartesian3D expected = new Cartesian3D(1.2323, 1.4343, -1.6333);
- Cartesian3D actual = vector3DFormat.parse(source);
+ Vector3D expected = new Cartesian3D(1.2323, 1.4343, -1.6333);
+ Vector3D actual = vector3DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -248,8 +248,8 @@ public abstract class Vector3DFormatAbstractTest {
"2323; -1" + getDecimalCharacter() +
"4343; -1" + getDecimalCharacter() +
"6333}";
- Cartesian3D expected = new Cartesian3D(-1.2323, -1.4343, -1.6333);
- Cartesian3D actual = vector3DFormat.parse(source);
+ Vector3D expected = new Cartesian3D(-1.2323, -1.4343, -1.6333);
+ Vector3D actual = vector3DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -260,8 +260,8 @@ public abstract class Vector3DFormatAbstractTest {
"0; -1" + getDecimalCharacter() +
"4343; 1" + getDecimalCharacter() +
"6333}";
- Cartesian3D expected = new Cartesian3D(0.0, -1.4343, 1.6333);
- Cartesian3D actual = vector3DFormat.parse(source);
+ Vector3D expected = new Cartesian3D(0.0, -1.4343, 1.6333);
+ Vector3D actual = vector3DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -272,29 +272,29 @@ public abstract class Vector3DFormatAbstractTest {
"2323 : 1" + getDecimalCharacter() +
"4343 : 1" + getDecimalCharacter() +
"6333]";
- Cartesian3D expected = new Cartesian3D(1.2323, 1.4343, 1.6333);
- Cartesian3D actual = vector3DFormatSquare.parse(source);
+ Vector3D expected = new Cartesian3D(1.2323, 1.4343, 1.6333);
+ Vector3D actual = vector3DFormatSquare.parse(source);
Assert.assertEquals(expected, actual);
}
@Test
public void testParseNan() throws MathParseException {
String source = "{(NaN); (NaN); (NaN)}";
- Cartesian3D actual = vector3DFormat.parse(source);
+ Vector3D actual = vector3DFormat.parse(source);
Assert.assertEquals(Cartesian3D.NaN, actual);
}
@Test
public void testParsePositiveInfinity() throws MathParseException {
String source = "{(Infinity); (Infinity); (Infinity)}";
- Cartesian3D actual = vector3DFormat.parse(source);
+ Vector3D actual = vector3DFormat.parse(source);
Assert.assertEquals(Cartesian3D.POSITIVE_INFINITY, actual);
}
@Test
public void testParseNegativeInfinity() throws MathParseException {
String source = "{(-Infinity); (-Infinity); (-Infinity)}";
- Cartesian3D actual = vector3DFormat.parse(source);
+ Vector3D actual = vector3DFormat.parse(source);
Assert.assertEquals(Cartesian3D.NEGATIVE_INFINITY, actual);
}