diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java
index 51109d08b..7e68362eb 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Cartesian2D.java
@@ -36,7 +36,7 @@ import org.apache.commons.math4.util.MathUtils;
*
Instances of this class are guaranteed to be immutable.
* @since 4.0
*/
-public class Cartesian2D implements Point, Vector {
+public class Cartesian2D extends Vector2D implements Point {
/** Origin (coordinates: 0, 0). */
public static final Cartesian2D ZERO = new Cartesian2D(0, 0);
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java
new file mode 100644
index 000000000..4a2a398ef
--- /dev/null
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2D.java
@@ -0,0 +1,38 @@
+/*
+ * 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.twod;
+
+import org.apache.commons.math4.geometry.Vector;
+
+/** This class represents a 2D vector.
+ * @since 3.0
+ */
+public abstract class Vector2D implements Vector {
+
+ /** Get the abscissa of the vector.
+ * @return abscissa of the vector
+ * @see #Vector2D(double, double)
+ */
+ public abstract double getX();
+
+ /** Get the ordinate of the vector.
+ * @return ordinate of the vector
+ * @see #Vector2D(double, double)
+ */
+ public abstract double getY();
+
+}
diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java
index 936450a43..cb765968d 100644
--- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java
+++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormat.java
@@ -108,26 +108,26 @@ public class Vector2DFormat extends VectorFormat {
@Override
public StringBuffer format(final Vector vector, final StringBuffer toAppendTo,
final FieldPosition pos) {
- final Cartesian2D p2 = (Cartesian2D) vector;
+ final Vector2D p2 = (Vector2D) vector;
return format(toAppendTo, pos, p2.getX(), p2.getY());
}
/** {@inheritDoc} */
@Override
- public Cartesian2D parse(final String source) throws MathParseException {
+ public Vector2D parse(final String source) throws MathParseException {
ParsePosition parsePosition = new ParsePosition(0);
- Cartesian2D result = parse(source, parsePosition);
+ Vector2D result = parse(source, parsePosition);
if (parsePosition.getIndex() == 0) {
throw new MathParseException(source,
parsePosition.getErrorIndex(),
- Cartesian2D.class);
+ Vector2D.class);
}
return result;
}
/** {@inheritDoc} */
@Override
- public Cartesian2D parse(final String source, final ParsePosition pos) {
+ public Vector2D parse(final String source, final ParsePosition pos) {
final double[] coordinates = parseCoordinates(2, source, pos);
if (coordinates == null) {
return null;
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormatAbstractTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormatAbstractTest.java
index 11f518af2..93d34212b 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormatAbstractTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/Vector2DFormatAbstractTest.java
@@ -157,8 +157,8 @@ public abstract class Vector2DFormatAbstractTest {
@Test
public void testParseSimpleNoDecimals() throws MathParseException {
String source = "{1; 1}";
- Cartesian2D expected = new Cartesian2D(1, 1);
- Cartesian2D actual = vector2DFormat.parse(source);
+ Vector2D expected = new Cartesian2D(1, 1);
+ Vector2D actual = vector2DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -181,8 +181,8 @@ public abstract class Vector2DFormatAbstractTest {
"{1" + getDecimalCharacter() +
"23; 1" + getDecimalCharacter() +
"43}";
- Cartesian2D expected = new Cartesian2D(1.23, 1.43);
- Cartesian2D actual = vector2DFormat.parse(source);
+ Vector2D expected = new Cartesian2D(1.23, 1.43);
+ Vector2D actual = vector2DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -192,8 +192,8 @@ public abstract class Vector2DFormatAbstractTest {
"{1" + getDecimalCharacter() +
"2323; 1" + getDecimalCharacter() +
"4343}";
- Cartesian2D expected = new Cartesian2D(1.2323, 1.4343);
- Cartesian2D actual = vector2DFormat.parse(source);
+ Vector2D expected = new Cartesian2D(1.2323, 1.4343);
+ Vector2D actual = vector2DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -203,8 +203,8 @@ public abstract class Vector2DFormatAbstractTest {
"{-1" + getDecimalCharacter() +
"2323; 1" + getDecimalCharacter() +
"4343}";
- Cartesian2D expected = new Cartesian2D(-1.2323, 1.4343);
- Cartesian2D actual = vector2DFormat.parse(source);
+ Vector2D expected = new Cartesian2D(-1.2323, 1.4343);
+ Vector2D actual = vector2DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -214,8 +214,8 @@ public abstract class Vector2DFormatAbstractTest {
"{1" + getDecimalCharacter() +
"2323; -1" + getDecimalCharacter() +
"4343}";
- Cartesian2D expected = new Cartesian2D(1.2323, -1.4343);
- Cartesian2D actual = vector2DFormat.parse(source);
+ Vector2D expected = new Cartesian2D(1.2323, -1.4343);
+ Vector2D actual = vector2DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -225,8 +225,8 @@ public abstract class Vector2DFormatAbstractTest {
"{1" + getDecimalCharacter() +
"2323; 1" + getDecimalCharacter() +
"4343}";
- Cartesian2D expected = new Cartesian2D(1.2323, 1.4343);
- Cartesian2D actual = vector2DFormat.parse(source);
+ Vector2D expected = new Cartesian2D(1.2323, 1.4343);
+ Vector2D actual = vector2DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -236,8 +236,8 @@ public abstract class Vector2DFormatAbstractTest {
"{-1" + getDecimalCharacter() +
"2323; -1" + getDecimalCharacter() +
"4343}";
- Cartesian2D expected = new Cartesian2D(-1.2323, -1.4343);
- Cartesian2D actual = vector2DFormat.parse(source);
+ Vector2D expected = new Cartesian2D(-1.2323, -1.4343);
+ Vector2D actual = vector2DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -247,8 +247,8 @@ public abstract class Vector2DFormatAbstractTest {
"{0" + getDecimalCharacter() +
"0; -1" + getDecimalCharacter() +
"4343}";
- Cartesian2D expected = new Cartesian2D(0.0, -1.4343);
- Cartesian2D actual = vector2DFormat.parse(source);
+ Vector2D expected = new Cartesian2D(0.0, -1.4343);
+ Vector2D actual = vector2DFormat.parse(source);
Assert.assertEquals(expected, actual);
}
@@ -258,29 +258,29 @@ public abstract class Vector2DFormatAbstractTest {
"[1" + getDecimalCharacter() +
"2323 : 1" + getDecimalCharacter() +
"4343]";
- Cartesian2D expected = new Cartesian2D(1.2323, 1.4343);
- Cartesian2D actual = vector2DFormatSquare.parse(source);
+ Vector2D expected = new Cartesian2D(1.2323, 1.4343);
+ Vector2D actual = vector2DFormatSquare.parse(source);
Assert.assertEquals(expected, actual);
}
@Test
public void testParseNan() throws MathParseException {
String source = "{(NaN); (NaN)}";
- Cartesian2D actual = vector2DFormat.parse(source);
+ Vector2D actual = vector2DFormat.parse(source);
Assert.assertEquals(Cartesian2D.NaN, actual);
}
@Test
public void testParsePositiveInfinity() throws MathParseException {
String source = "{(Infinity); (Infinity)}";
- Cartesian2D actual = vector2DFormat.parse(source);
+ Vector2D actual = vector2DFormat.parse(source);
Assert.assertEquals(Cartesian2D.POSITIVE_INFINITY, actual);
}
@Test
public void testParseNegativeInfinity() throws MathParseException {
String source = "{(-Infinity); (-Infinity)}";
- Cartesian2D actual = vector2DFormat.parse(source);
+ Vector2D actual = vector2DFormat.parse(source);
Assert.assertEquals(Cartesian2D.NEGATIVE_INFINITY, actual);
}