This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit a44ea1a5f8337b1666782af3480444ca77755432 Author: jsorel <[email protected]> AuthorDate: Fri Nov 27 10:16:40 2026 +0100 refactor(Math): create vectors with Vector.of --- .../main/org/apache/sis/geometries/Geometries.java | 16 +++--- .../main/org/apache/sis/geometries/OBBox.java | 9 ++-- .../internal/shared/CurveLinearizer.java | 3 +- .../sis/geometries/internal/shared/DefaultArc.java | 3 +- .../apache/sis/geometries/mesh/MeshPrimitive.java | 8 +-- .../sis/geometries/mesh/MeshPrimitiveIndexes.java | 11 ++-- .../main/org/apache/sis/maths/Affine1D.java | 2 +- .../main/org/apache/sis/maths/Affine2D.java | 2 +- .../main/org/apache/sis/maths/Affine3D.java | 2 +- .../main/org/apache/sis/maths/Affine4D.java | 2 +- .../main/org/apache/sis/maths/Matrices.java | 6 +-- .../main/org/apache/sis/maths/Matrix2D.java | 2 +- .../main/org/apache/sis/maths/Matrix3D.java | 10 ++-- .../main/org/apache/sis/maths/Matrix4D.java | 4 +- .../main/org/apache/sis/maths/Quaternion.java | 8 +-- .../main/org/apache/sis/maths/Similarity3D.java | 4 +- .../main/org/apache/sis/maths/Vector.java | 4 +- .../main/org/apache/sis/maths/Vector3D.java | 6 +-- .../main/org/apache/sis/scene/physics/Motion.java | 9 ++-- .../sis/geometries/adapter/ShapeConverterTest.java | 36 ++++++------- .../internal/shared/ArraySequenceTest.java | 43 ++++++++-------- .../sis/geometries/mesh/PrimitiveVisitorTest.java | 12 ++--- .../geometries/operation/SutherlandHogmanTest.java | 9 ++-- .../geometries/spherical/GreatCircleArcTest.java | 11 ++-- .../spherical/SphericalConvexPolygonTest.java | 29 ++++++----- .../geometries/spherical/SphericalPolygonTest.java | 8 +-- .../spherical/SphericalTriangleTest.java | 21 ++++---- .../org/apache/sis/maths/AbstractVectorTest.java | 2 +- .../apache/sis/maths/ArrayConcatenatedTest.java | 60 +++++++++++----------- .../test/org/apache/sis/maths/QuaternionTest.java | 8 +-- .../test/org/apache/sis/maths/Vector3DTest.java | 12 ++--- .../test/org/apache/sis/maths/VectorXbTest.java | 8 +-- .../test/org/apache/sis/maths/VectorXdTest.java | 8 +-- .../test/org/apache/sis/maths/VectorXfTest.java | 8 +-- .../test/org/apache/sis/maths/VectorXiTest.java | 8 +-- .../test/org/apache/sis/maths/VectorXlTest.java | 8 +-- .../test/org/apache/sis/maths/VectorXsTest.java | 8 +-- .../test/org/apache/sis/maths/VectorXubTest.java | 8 +-- .../test/org/apache/sis/maths/VectorXuiTest.java | 8 +-- .../test/org/apache/sis/maths/VectorXusTest.java | 8 +-- .../test/org/apache/sis/maths/VectorsTest.java | 38 +++++++------- .../org/apache/sis/scene/SceneUtilitiesTest.java | 18 +++---- 42 files changed, 216 insertions(+), 274 deletions(-) diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/Geometries.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/Geometries.java index 176da49173..f276c9d24f 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/Geometries.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/Geometries.java @@ -305,14 +305,14 @@ public final class Geometries { double maxy = upper.get(1); double maxz = upper.get(2); - final Vector3D.Double lll = new Vector3D.Double(minx, miny, minz); - final Vector3D.Double ull = new Vector3D.Double(maxx, miny, minz); - final Vector3D.Double uul = new Vector3D.Double(maxx, maxy, minz); - final Vector3D.Double lul = new Vector3D.Double(minx, maxy, minz); - final Vector3D.Double ulu = new Vector3D.Double(maxx, miny, maxz); - final Vector3D.Double llu = new Vector3D.Double(minx, miny, maxz); - final Vector3D.Double uuu = new Vector3D.Double(maxx, maxy, maxz); - final Vector3D.Double luu = new Vector3D.Double(minx, maxy, maxz); + final Vector3D.Double lll = Vector.of(minx, miny, minz); + final Vector3D.Double ull = Vector.of(maxx, miny, minz); + final Vector3D.Double uul = Vector.of(maxx, maxy, minz); + final Vector3D.Double lul = Vector.of(minx, maxy, minz); + final Vector3D.Double ulu = Vector.of(maxx, miny, maxz); + final Vector3D.Double llu = Vector.of(minx, miny, maxz); + final Vector3D.Double uuu = Vector.of(maxx, maxy, maxz); + final Vector3D.Double luu = Vector.of(minx, maxy, maxz); final Array positions = NDArrays.of(system, new double[24*3]); //back diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/OBBox.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/OBBox.java index 384775e226..c624be4128 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/OBBox.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/OBBox.java @@ -24,7 +24,6 @@ import org.apache.sis.geometries.internal.shared.SinglePositionDataPoints; import org.apache.sis.maths.DataType; import org.apache.sis.maths.NDRange; import org.apache.sis.maths.Vector; -import org.apache.sis.maths.Vector3D; import org.apache.sis.measure.Quantities; @@ -255,10 +254,10 @@ public final class OBBox extends AbstractGeometry { */ public void fromEnvelope(Envelope env) { setCoordinateReferenceSystem(env.getCoordinateReferenceSystem()); - center = new Vector3D.Double(env.getMedian(0), env.getMedian(1), env.getMedian(2)); - xAxis = new Vector3D.Double(env.getSpan(0) / 2.0, 0.0, 0.0); - yAxis = new Vector3D.Double(0.0, env.getSpan(1) / 2.0, 0.0); - zAxis = new Vector3D.Double(0.0, 0.0, env.getSpan(2) / 2.0); + center = Vector.of(env.getMedian(0), env.getMedian(1), env.getMedian(2)); + xAxis = Vector.of(env.getSpan(0) / 2.0, 0.0, 0.0); + yAxis = Vector.of(0.0, env.getSpan(1) / 2.0, 0.0); + zAxis = Vector.of(0.0, 0.0, env.getSpan(2) / 2.0); } /** diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/CurveLinearizer.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/CurveLinearizer.java index 0426cff828..11200b5ad4 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/CurveLinearizer.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/CurveLinearizer.java @@ -35,7 +35,6 @@ import org.apache.sis.maths.NDArrays; import org.apache.sis.maths.NDRange; import org.apache.sis.maths.SampleSystem; import org.apache.sis.maths.Vector; -import org.apache.sis.maths.Vector2D; import org.apache.sis.measure.Quantities; @@ -224,7 +223,7 @@ public final class CurveLinearizer { centre = start.copy(DataType.DOUBLE).lerp(middle, 0.5); radius = distance(start, centre); e1 = start.copy(DataType.DOUBLE).subtract(centre).scale(1 / radius); - e2 = new Vector2D.Double(-e1.get(1), e1.get(0)); + e2 = Vector.of(-e1.get(1), e1.get(0)); } else { u = u.scale(1 / chord); final Vector<?> mid = start.copy(DataType.DOUBLE).lerp(end, 0.5); diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/DefaultArc.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/DefaultArc.java index 0b7e5d76da..0fb4319746 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/DefaultArc.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/DefaultArc.java @@ -28,7 +28,6 @@ import org.apache.sis.maths.Array; import org.apache.sis.maths.DataType; import org.apache.sis.maths.NDRange; import org.apache.sis.maths.Vector; -import org.apache.sis.maths.Vector2D; /** @@ -145,7 +144,7 @@ public non-sealed class DefaultArc extends DefaultConic implements Arc { middle = centre.add(bisector.scale(r / length)); } else if (centre.getDimension() == 2) { // Half turn: counterclockwise by default. - middle = new Vector2D.Double(centre.get(0) - (start.get(1) - centre.get(1)), + middle = Vector.of(centre.get(0) - (start.get(1) - centre.get(1)), centre.get(1) + (start.get(0) - centre.get(0))); } else { throw new IllegalStateException("Arc " + i + " is a half turn, which plane is not determined" diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitive.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitive.java index 4a2872c6c5..58da7a4a65 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitive.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitive.java @@ -881,7 +881,7 @@ public sealed interface MeshPrimitive extends Geometry final DataPoints points = candidate.getDataPoints(); long idx0 = ((Vertex)points.getPoint(0)).getIndex(); long idx1 = ((Vertex)points.getPoint(1)).getIndex(); - final Vector normal = new Vector3D.Float(0,0,1); + final Vector normal = Vector.of(0f,0f,1f); normals.set(idx0, normals.get(idx0).add(normal)); normals.set(idx1, normals.get(idx1).add(normal)); @@ -890,7 +890,7 @@ public sealed interface MeshPrimitive extends Geometry @Override protected void visit(Point candidate) { long idx0 = ((Vertex)candidate).getIndex(); - final Vector normal = new Vector3D.Float(0,0,1); + final Vector normal = Vector.of(0f,0f,1f); normals.set(idx0, normal); } @@ -948,9 +948,9 @@ public sealed interface MeshPrimitive extends Geometry for (Entry<List<Vector<?>>,Array> entry : mapping) { entry.getKey().add(entry.getValue().get(idx)); } - newIndex.add(new Vector1D.Int(newIdx)); + newIndex.add(Vector.of(newIdx)); } else { - newIndex.add(new Vector1D.Int(previous)); + newIndex.add(Vector.of(previous)); } } diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitiveIndexes.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitiveIndexes.java index b789c6ed94..2db5ef0008 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitiveIndexes.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitiveIndexes.java @@ -30,6 +30,7 @@ import org.apache.sis.maths.Cursor; import org.apache.sis.maths.DataType; import org.apache.sis.maths.NDArrays; import org.apache.sis.maths.Vector1D; +import org.apache.sis.maths.Vector; /** @@ -264,9 +265,9 @@ public final class MeshPrimitiveIndexes { Edge edge = root; triangle = edge.triangle; //add the 3 first indices - index.add(new Vector1D.Int(edge.start)); - index.add(new Vector1D.Int(edge.end)); - index.add(new Vector1D.Int(edge.next.end)); + index.add(Vector.of(edge.start)); + index.add(Vector.of(edge.end)); + index.add(Vector.of(edge.next.end)); //add each next triangle new vertex edge = edge.next; @@ -276,7 +277,7 @@ public final class MeshPrimitiveIndexes { triangle.unregister(edges); for (boolean odd = false; edge != null; odd = !odd) { - index.add(new Vector1D.Int(edge.next.end)); + index.add(Vector.of(edge.next.end)); edge = odd ? edge.next : edge.next.next; triangle = edge.triangle; edge = edge.neighbor; @@ -289,7 +290,7 @@ public final class MeshPrimitiveIndexes { boolean odd = true; while (edge.neighbor != null && edge.neighbor.opposite(odd) != null) { edge = edge.neighbor; - index.add(new Vector1D.Int(edge.next.end)); + index.add(Vector.of(edge.next.end)); triangle = edge.triangle; edge = edge.opposite(odd).neighbor; triangle.unregister(edges); diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine1D.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine1D.java index 4eb9e27a29..30acf8e732 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine1D.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine1D.java @@ -120,7 +120,7 @@ public final class Affine1D extends AbstractAffine<Affine1D> implements Transfor @Override public Vector1D.Double transform(Vector<?> source) { - return new Vector1D.Double(m00*source.get(0) + m01); + return Vector.of(m00*source.get(0) + m01); } @Override diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine2D.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine2D.java index 02eb9f480c..158d606fa1 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine2D.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine2D.java @@ -146,7 +146,7 @@ public final class Affine2D extends AbstractAffine<Affine2D> { public Vector2D.Double transform(Vector<?> source) { final double x = source.get(0); final double y = source.get(1); - return new Vector2D.Double( + return Vector.of( m00*x + m01*y + m02, m10*x + m11*y + m12); } diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine3D.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine3D.java index 85fdced776..87d36d2bfe 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine3D.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine3D.java @@ -231,7 +231,7 @@ public final class Affine3D extends AbstractAffine<Affine3D> { final double x = source.get(0); final double y = source.get(1); final double z = source.get(2); - return new Vector3D.Double( + return Vector.of( m00*x + m01*y + m02*z + m03, m10*x + m11*y + m12*z + m13, m20*x + m21*y + m22*z + m23); diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine4D.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine4D.java index db5c710615..706c55d6c1 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine4D.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Affine4D.java @@ -336,7 +336,7 @@ public final class Affine4D extends AbstractAffine<Affine4D> { final double y = source.get(1); final double z = source.get(2); final double w = source.get(3); - return new Vector4D.Double( + return Vector.of( m00*x + m01*y + m02*z + m03*w + m04, m10*x + m11*y + m12*z + m13*w + m14, m20*x + m21*y + m22*z + m23*w + m24, diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrices.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrices.java index 2719e47e90..4a6f3b403e 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrices.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrices.java @@ -617,11 +617,11 @@ public final class Matrices { public static double[][] focusedOrbit(final double xAngle, final double yAngle, double rollAngle, double distance){ - final Vector4D.Double forward = new Vector4D.Double(1*distance, 0, 0, 0); + final Vector4D.Double forward = Vector.of(1*distance, 0.0, 0.0, 0.0); //calculate rotation matrix - final MatrixND rotateMatrix = new MatrixND(createRotation4(xAngle, new Vector3D.Double(0, 0, 1),null)); - final MatrixND mv = new MatrixND(createRotation4(yAngle, new Vector3D.Double(0, -1, 0), null)); + final MatrixND rotateMatrix = new MatrixND(createRotation4(xAngle, Vector.of(0.0, 0.0, 1.0),null)); + final MatrixND mv = new MatrixND(createRotation4(yAngle, Vector.of(0.0, -1.0, 0.0), null)); rotateMatrix.multiply(mv); //calculate translation vector diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrix2D.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrix2D.java index df5aac443c..d9cabac3f5 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrix2D.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrix2D.java @@ -208,7 +208,7 @@ public class Matrix2D extends AbstractMatrix<Matrix2D> { public Vector2D.Double transform(Vector<?> vector) { final double x = vector.get(0); final double y = vector.get(1); - return new Vector2D.Double( + return Vector.of( m00*x + m01*y, m10*x + m11*y); } diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrix3D.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrix3D.java index e13f18b294..5174d4a536 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrix3D.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrix3D.java @@ -271,7 +271,7 @@ public class Matrix3D extends AbstractMatrix<Matrix3D> { final double x = vector.get(0); final double y = vector.get(1); final double z = vector.get(2); - return new Vector3D.Double( + return Vector.of( m00*x + m01*y + m02*z, m10*x + m11*y + m12*z, m20*x + m21*y + m22*z); @@ -326,7 +326,7 @@ public class Matrix3D extends AbstractMatrix<Matrix3D> { } } - return new Vector3D.Double(angle_z, angle_y, angle_x); + return Vector.of(angle_z, angle_y, angle_x); } /** @@ -380,9 +380,9 @@ public class Matrix3D extends AbstractMatrix<Matrix3D> { * @return */ public Matrix3D setFromAngles(double x, double y, double z){ - setFromAngle(x, new Vector3D.Double(1, 0, 0)); - Matrix3D r2 = new Matrix3D().setFromAngle(y, new Vector3D.Double(0, 1, 0)); - Matrix3D r3 = new Matrix3D().setFromAngle(z, new Vector3D.Double(0, 0, 1)); + setFromAngle(x, Vector.of(1.0, 0.0, 0.0)); + Matrix3D r2 = new Matrix3D().setFromAngle(y, Vector.of(0.0, 1.0, 0.0)); + Matrix3D r3 = new Matrix3D().setFromAngle(z, Vector.of(0.0, 0.0, 1.0)); this.multiply(r2); this.multiply(r3); return this; diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrix4D.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrix4D.java index 682b61ccdc..cc608f27ed 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrix4D.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Matrix4D.java @@ -202,7 +202,7 @@ public class Matrix4D extends AbstractMatrix<Matrix4D> { } public Vector<?> getTranslation(){ - return new Vector4D.Double(m03, m13, m23, 1); + return Vector.of(m03, m13, m23, 1.0); } public void setTranslation(Vector<?> translation){ @@ -461,7 +461,7 @@ public class Matrix4D extends AbstractMatrix<Matrix4D> { final double y = vector.get(1); final double z = vector.get(2); final double w = vector.get(3); - return new Vector4D.Double( + return Vector.of( m00*x + m01*y + m02*z + m03*w, m10*x + m11*y + m12*z + m13*w, m20*x + m21*y + m22*z + m23*w, diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Quaternion.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Quaternion.java index 34799b37a3..7424d35027 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Quaternion.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Quaternion.java @@ -30,8 +30,8 @@ import static org.apache.sis.maths.Matrix.ROW_ORDER; */ public class Quaternion { - private static final Vector3D.Double UNIT_X = new Vector3D.Double(1,0,0); - private static final Vector3D.Double UNIT_Y = new Vector3D.Double(0,1,0); + private static final Vector3D.Double UNIT_X = Vector.of(1.0,0.0,0.0); + private static final Vector3D.Double UNIT_Y = Vector.of(0.0,1.0,0.0); /** * Quaternion values x, y, z, w. @@ -223,7 +223,7 @@ public class Quaternion { * @return quaternion values x, y, z, w as a new vector */ public Vector4D.Double toVector() { - return new Vector4D.Double(values[0], values[1], values[2], values[3]); + return Vector.of(values[0], values[1], values[2], values[3]); } /** @@ -327,7 +327,7 @@ public class Quaternion { uuvy *= 2; uuvz *= 2; // return vec3.add(out, a, vec3.add(out, uv, uuv)); - return new Vector3D.Double( + return Vector.of( v.x + uvx + uuvx, v.y + uvy + uuvy, v.z + uvz + uuvz); diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Similarity3D.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Similarity3D.java index ad137ef315..e1eaccaa1d 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Similarity3D.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Similarity3D.java @@ -26,8 +26,8 @@ import java.util.Objects; */ public final class Similarity3D extends AbstractSimilarity<Similarity3D> { - private Vector3D.Double scale = new Vector3D.Double(1, 1, 1); - private Vector3D.Double translation = new Vector3D.Double(0, 0, 0); + private Vector3D.Double scale = Vector.of(1.0, 1.0, 1.0); + private Vector3D.Double translation = Vector.of(0.0, 0.0, 0.0); private final Matrix3D rotation = new Matrix3D(1,0,0, 0,1,0, 0,0,1); public Similarity3D(){ diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Vector.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Vector.java index d983382adc..8dff66dc59 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Vector.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Vector.java @@ -663,7 +663,7 @@ public sealed interface Vector<T extends Vector<T>> permits AbstractVector { } final double x = get(0), y = get(1), z = get(2); final double ox = other.get(0), oy = other.get(1), oz = other.get(2); - return new Vector3D.Double( + return Vector.of( (y * oz) - (z * oy), (z * ox) - (x * oz), (x * oy) - (y * ox)); @@ -685,7 +685,7 @@ public sealed interface Vector<T extends Vector<T>> permits AbstractVector { } final double x = get(0), y = get(1), z = get(2); final double ox = other.get(0), oy = other.get(1), oz = other.get(2); - return new Vector3D.Double( + return Vector.of( LinearCombination.of(y, oz, -z, oy), LinearCombination.of(z, ox, -x, oz), LinearCombination.of(x, oy, -y, ox)); diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Vector3D.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Vector3D.java index c74a4d0429..b533d3fa89 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Vector3D.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/maths/Vector3D.java @@ -120,7 +120,7 @@ public abstract sealed class Vector3D<T extends Vector3D<T>> extends AbstractVec */ public static Vector3D.Double fromLatLon(double latRad, double lonRad) { final double cosLat = Math.cos(latRad); - return new Vector3D.Double( + return Vector.of( cosLat * Math.cos(lonRad), cosLat * Math.sin(lonRad), Math.sin(latRad)); @@ -212,7 +212,7 @@ public abstract sealed class Vector3D<T extends Vector3D<T>> extends AbstractVec ensureDimension(other, 3); final double x = get(0), y = get(1), z = get(2); final double ox = other.get(0), oy = other.get(1), oz = other.get(2); - return new Vector3D.Double( + return Vector.of( (y * oz) - (z * oy), (z * ox) - (x * oz), (x * oy) - (y * ox)); @@ -223,7 +223,7 @@ public abstract sealed class Vector3D<T extends Vector3D<T>> extends AbstractVec ensureDimension(other, 3); final double x = get(0), y = get(1), z = get(2); final double ox = other.get(0), oy = other.get(1), oz = other.get(2); - return new Vector3D.Double( + return Vector.of( LinearCombination.of(y, oz, -z, oy), LinearCombination.of(z, ox, -x, oz), LinearCombination.of(x, oy, -y, ox)); diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/scene/physics/Motion.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/scene/physics/Motion.java index 83efc4e485..473fedc627 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/scene/physics/Motion.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/scene/physics/Motion.java @@ -18,6 +18,7 @@ package org.apache.sis.scene.physics; import org.apache.sis.maths.Quaternion; import org.apache.sis.maths.Vector3D; +import org.apache.sis.maths.Vector; /** @@ -31,11 +32,11 @@ public final class Motion { private boolean isKinematic = false; private double mass = 1.0; - private Vector3D.Double centerOfMass = new Vector3D.Double(0,0,0); - private Vector3D.Double inertialDiagonal = new Vector3D.Double(0,0,0); + private Vector3D.Double centerOfMass = Vector.of(0.0,0.0,0.0); + private Vector3D.Double inertialDiagonal = Vector.of(0.0,0.0,0.0); private Quaternion inertiaOrientation = new Quaternion(); - private Vector3D.Double linearVelocity = new Vector3D.Double(0,0,0); - private Vector3D.Double angularVelocity = new Vector3D.Double(0,0,0); + private Vector3D.Double linearVelocity = Vector.of(0.0,0.0,0.0); + private Vector3D.Double angularVelocity = Vector.of(0.0,0.0,0.0); private double gravityFactor = 1.0; /** diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/adapter/ShapeConverterTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/adapter/ShapeConverterTest.java index b20597f0fa..f7daca7790 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/adapter/ShapeConverterTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/adapter/ShapeConverterTest.java @@ -122,7 +122,7 @@ public final class ShapeConverterTest { final var shape = new GeneralPath(); shape.moveTo(10, 20); assertCoordinatesEqual(shape, Point.class, - new Vector2D.Double(10, 20)); + Vector.of(10.0, 20.0)); } /** @@ -132,8 +132,8 @@ public final class ShapeConverterTest { public void testLine() { final var shape = new Line2D.Double(1, 2, 3, 4); assertCoordinatesEqual(shape, LineString.class, - new Vector2D.Double(1, 2), - new Vector2D.Double(3, 4)); + Vector.of(1.0, 2.0), + Vector.of(3.0, 4.0)); } /** @@ -143,11 +143,11 @@ public final class ShapeConverterTest { public void testRectangle() { final var shape = new Rectangle2D.Double(1, 2, 10, 20); assertCoordinatesEqual(shape, Polygon.class, - new Vector2D.Double( 1, 2), - new Vector2D.Double(11, 2), - new Vector2D.Double(11, 22), - new Vector2D.Double( 1, 22), - new Vector2D.Double( 1, 2)); + Vector.of( 1.0, 2.0), + Vector.of(11.0, 2.0), + Vector.of(11.0, 22.0), + Vector.of( 1.0, 22.0), + Vector.of( 1.0, 2.0)); } /** @@ -165,18 +165,18 @@ public final class ShapeConverterTest { assertEquals(1, polygon.getNumInteriorRing()); assertCoordinatesEqual(polygon.getExteriorRing(), LinearRing.class, - new Vector2D.Double(1, 2), - new Vector2D.Double(1, 22), - new Vector2D.Double(11, 22), - new Vector2D.Double(11, 2), - new Vector2D.Double(1, 2)); + Vector.of(1.0, 2.0), + Vector.of(1.0, 22.0), + Vector.of(11.0, 22.0), + Vector.of(11.0, 2.0), + Vector.of(1.0, 2.0)); assertCoordinatesEqual(polygon.getInteriorRingN(0), LinearRing.class, - new Vector2D.Double(7, 6), - new Vector2D.Double(7, 9), - new Vector2D.Double(5, 9), - new Vector2D.Double(5, 6), - new Vector2D.Double(7, 6)); + Vector.of(7.0, 6.0), + Vector.of(7.0, 9.0), + Vector.of(5.0, 9.0), + Vector.of(5.0, 6.0), + Vector.of(7.0, 6.0)); } /** diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/internal/shared/ArraySequenceTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/internal/shared/ArraySequenceTest.java index b432b6291b..58bd26a283 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/internal/shared/ArraySequenceTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/internal/shared/ArraySequenceTest.java @@ -22,9 +22,8 @@ import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.apache.sis.geometries.Point; import org.apache.sis.geometries.DataPointsType; import org.apache.sis.maths.NDArrays; -import org.apache.sis.maths.Vector2D; -import org.apache.sis.maths.Vector3D; import org.apache.sis.maths.Array; +import org.apache.sis.maths.Vector; import org.apache.sis.referencing.CommonCRS; // Test dependencies @@ -104,31 +103,31 @@ public class ArraySequenceTest { assertEquals(normals, array.getAttribute(DataPointsType.ATT_NORMAL)); assertEquals(2, array.getAttributeNames().size()); - assertEquals(new Vector2D.Double(0, 0), array.getAttribute(0, DataPointsType.ATT_POSITION)); - assertEquals(new Vector2D.Double(1, 0), array.getAttribute(1, DataPointsType.ATT_POSITION)); - assertEquals(new Vector2D.Double(0, 1), array.getAttribute(2, DataPointsType.ATT_POSITION)); - assertEquals(new Vector2D.Double(0, 0), array.getAttribute(3, DataPointsType.ATT_POSITION)); - assertEquals(new Vector2D.Double(0, 0), array.getPosition(0)); - assertEquals(new Vector2D.Double(1, 0), array.getPosition(1)); - assertEquals(new Vector2D.Double(0, 1), array.getPosition(2)); - assertEquals(new Vector2D.Double(0, 0), array.getPosition(3)); - assertEquals(new Vector3D.Double(1, 0, 0), array.getAttribute(0, DataPointsType.ATT_NORMAL)); - assertEquals(new Vector3D.Double(0, 1, 0), array.getAttribute(1, DataPointsType.ATT_NORMAL)); - assertEquals(new Vector3D.Double(0, 0, 1), array.getAttribute(2, DataPointsType.ATT_NORMAL)); - assertEquals(new Vector3D.Double(1, 0, 0), array.getAttribute(3, DataPointsType.ATT_NORMAL)); + assertEquals(Vector.of(0.0, 0.0), array.getAttribute(0, DataPointsType.ATT_POSITION)); + assertEquals(Vector.of(1.0, 0.0), array.getAttribute(1, DataPointsType.ATT_POSITION)); + assertEquals(Vector.of(0.0, 1.0), array.getAttribute(2, DataPointsType.ATT_POSITION)); + assertEquals(Vector.of(0.0, 0.0), array.getAttribute(3, DataPointsType.ATT_POSITION)); + assertEquals(Vector.of(0.0, 0.0), array.getPosition(0)); + assertEquals(Vector.of(1.0, 0.0), array.getPosition(1)); + assertEquals(Vector.of(0.0, 1.0), array.getPosition(2)); + assertEquals(Vector.of(0.0, 0.0), array.getPosition(3)); + assertEquals(Vector.of(1.0, 0.0, 0.0), array.getAttribute(0, DataPointsType.ATT_NORMAL)); + assertEquals(Vector.of(0.0, 1.0, 0.0), array.getAttribute(1, DataPointsType.ATT_NORMAL)); + assertEquals(Vector.of(0.0, 0.0, 1.0), array.getAttribute(2, DataPointsType.ATT_NORMAL)); + assertEquals(Vector.of(1.0, 0.0, 0.0), array.getAttribute(3, DataPointsType.ATT_NORMAL)); Point pt0 = array.getPoint(0); Point pt1 = array.getPoint(1); Point pt2 = array.getPoint(2); Point pt3 = array.getPoint(3); - assertEquals(new Vector2D.Double(0, 0), pt0.getPosition()); - assertEquals(new Vector2D.Double(1, 0), pt1.getPosition()); - assertEquals(new Vector2D.Double(0, 1), pt2.getPosition()); - assertEquals(new Vector2D.Double(0, 0), pt3.getPosition()); - assertEquals(new Vector3D.Double(1, 0, 0), pt0.getAttribute(DataPointsType.ATT_NORMAL)); - assertEquals(new Vector3D.Double(0, 1, 0), pt1.getAttribute(DataPointsType.ATT_NORMAL)); - assertEquals(new Vector3D.Double(0, 0, 1), pt2.getAttribute(DataPointsType.ATT_NORMAL)); - assertEquals(new Vector3D.Double(1, 0, 0), pt3.getAttribute(DataPointsType.ATT_NORMAL)); + assertEquals(Vector.of(0.0, 0.0), pt0.getPosition()); + assertEquals(Vector.of(1.0, 0.0), pt1.getPosition()); + assertEquals(Vector.of(0.0, 1.0), pt2.getPosition()); + assertEquals(Vector.of(0.0, 0.0), pt3.getPosition()); + assertEquals(Vector.of(1.0, 0.0, 0.0), pt0.getAttribute(DataPointsType.ATT_NORMAL)); + assertEquals(Vector.of(0.0, 1.0, 0.0), pt1.getAttribute(DataPointsType.ATT_NORMAL)); + assertEquals(Vector.of(0.0, 0.0, 1.0), pt2.getAttribute(DataPointsType.ATT_NORMAL)); + assertEquals(Vector.of(1.0, 0.0, 0.0), pt3.getAttribute(DataPointsType.ATT_NORMAL)); } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/mesh/PrimitiveVisitorTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/mesh/PrimitiveVisitorTest.java index 2f43941aa3..6515df94ee 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/mesh/PrimitiveVisitorTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/mesh/PrimitiveVisitorTest.java @@ -27,7 +27,7 @@ import org.apache.sis.geometries.internal.shared.Vertex; import org.apache.sis.geometries.surface.TIN; import org.apache.sis.geometries.surface.Triangle; import org.apache.sis.maths.NDArrays; -import org.apache.sis.maths.Vector3D; +import org.apache.sis.maths.Vector; // Test dependencies import static org.junit.jupiter.api.Assertions.*; @@ -65,8 +65,8 @@ public class PrimitiveVisitorTest { //test geometry collection assertEquals(2, geometry.getNumGeometries()); - assertEquals(new Vector3D.Double(0, 1, 2), geometry.getGeometryN(0).getPosition()); - assertEquals(new Vector3D.Double(3, 4, 5), geometry.getGeometryN(1).getPosition()); + assertEquals(Vector.of(0.0, 1.0, 2.0), geometry.getGeometryN(0).getPosition()); + assertEquals(Vector.of(3.0, 4.0, 5.0), geometry.getGeometryN(1).getPosition()); } /** @@ -94,9 +94,9 @@ public class PrimitiveVisitorTest { //test geometry collection assertEquals(3, geometry.getNumGeometries()); - assertEquals(new Vector3D.Double(0, 1, 2), geometry.getGeometryN(0).getPosition()); - assertEquals(new Vector3D.Double(3, 4, 5), geometry.getGeometryN(1).getPosition()); - assertEquals(new Vector3D.Double(0, 1, 2), geometry.getGeometryN(2).getPosition()); + assertEquals(Vector.of(0.0, 1.0, 2.0), geometry.getGeometryN(0).getPosition()); + assertEquals(Vector.of(3.0, 4.0, 5.0), geometry.getGeometryN(1).getPosition()); + assertEquals(Vector.of(0.0, 1.0, 2.0), geometry.getGeometryN(2).getPosition()); } /** diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/SutherlandHogmanTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/SutherlandHogmanTest.java index 0e070fdc77..52f6aaed75 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/SutherlandHogmanTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/SutherlandHogmanTest.java @@ -18,7 +18,6 @@ package org.apache.sis.geometries.operation; import java.util.List; import org.apache.sis.maths.NDArrays; -import org.apache.sis.maths.Vector2D; import org.apache.sis.maths.Array; import org.apache.sis.maths.Vector; @@ -53,9 +52,9 @@ public final class SutherlandHogmanTest { final List<Vector> result = SutherlandHodgman.clip(NDArrays.asList(subject), NDArrays.asList(clip)); assertEquals(4,result.size()); - assertEquals(new Vector2D.Double(5, 8),result.get(0)); - assertEquals(new Vector2D.Double(10, 8),result.get(1)); - assertEquals(new Vector2D.Double(10, 20),result.get(2)); - assertEquals(new Vector2D.Double(5, 20),result.get(3)); + assertEquals(Vector.of(5.0, 8.0),result.get(0)); + assertEquals(Vector.of(10.0, 8.0),result.get(1)); + assertEquals(Vector.of(10.0, 20.0),result.get(2)); + assertEquals(Vector.of(5.0, 20.0),result.get(3)); } } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/GreatCircleArcTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/GreatCircleArcTest.java index 96a4424e84..8b9dda40b1 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/GreatCircleArcTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/GreatCircleArcTest.java @@ -18,7 +18,6 @@ package org.apache.sis.geometries.spherical; import org.apache.sis.geometries.internal.shared.DefaultSphere; import org.apache.sis.maths.Vector; -import org.apache.sis.maths.Vector3D; // Test dependencies import static org.junit.jupiter.api.Assertions.*; @@ -34,8 +33,8 @@ public class GreatCircleArcTest { private static final double TOLERANCE = 1e-12; - private final Vector<?> a = new Vector3D.Double(1, 0, 0); - private final Vector<?> b = new Vector3D.Double(0, 1, 0); + private final Vector<?> a = Vector.of(1.0, 0.0, 0.0); + private final Vector<?> b = Vector.of(0.0, 1.0, 0.0); /** * Length test. @@ -51,7 +50,7 @@ public class GreatCircleArcTest { assertEquals(Math.PI, biggerArc.getLength(), TOLERANCE); // arc between antipodal points spans half a great circle - final GreatCircleArc halfArc = new GreatCircleArc(new DefaultSphere(3), a, new Vector3D.Double(-1, 0, 0)); + final GreatCircleArc halfArc = new GreatCircleArc(new DefaultSphere(3), a, Vector.of(-1.0, 0.0, 0.0)); assertEquals(Math.PI, halfArc.getLength(), TOLERANCE); // arc between a point and itself has no length @@ -68,7 +67,7 @@ public class GreatCircleArcTest { for (final double length : new double[] {1000, 10, 0.1}) { final double angle = length / radius; final GreatCircleArc arc = new GreatCircleArc(new DefaultSphere(3, radius), a, - new Vector3D.Double(Math.cos(angle), Math.sin(angle), 0)); + Vector.of(Math.cos(angle), Math.sin(angle), 0.0)); assertEquals(length, arc.getLength(), length * 1e-12); } } @@ -117,7 +116,7 @@ public class GreatCircleArcTest { assertArrayEquals(a.toArrayDouble(), coincident.pointAt(0.5).toArrayDouble(), TOLERANCE); assertArrayEquals(a.toArrayDouble(), coincident.pointAt(1.0).toArrayDouble(), TOLERANCE); - final GreatCircleArc antipodal = new GreatCircleArc(new DefaultSphere(3), a, new Vector3D.Double(-1, 0, 0)); + final GreatCircleArc antipodal = new GreatCircleArc(new DefaultSphere(3), a, Vector.of(-1.0, 0.0, 0.0)); //the ends themselves are still well defined assertArrayEquals(a.toArrayDouble(), antipodal.pointAt(0.0).toArrayDouble(), TOLERANCE); assertThrows(IllegalArgumentException.class, () -> antipodal.pointAt(0.5)); diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/SphericalConvexPolygonTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/SphericalConvexPolygonTest.java index effe302564..b00ebd5d06 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/SphericalConvexPolygonTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/SphericalConvexPolygonTest.java @@ -22,6 +22,7 @@ import org.apache.sis.maths.Array; import org.apache.sis.maths.DataType; import org.apache.sis.maths.NDArrays; import org.apache.sis.maths.Vector3D; +import org.apache.sis.maths.Vector; // Test dependencies import static org.junit.jupiter.api.Assertions.*; @@ -39,10 +40,10 @@ public class SphericalConvexPolygonTest { * Corners of a spherical square cap centered on the north pole, given in * CCW order viewed from outside the sphere. */ - private final Vector3D.Double a = new Vector3D.Double(1, 0, 1).normalize(); - private final Vector3D.Double b = new Vector3D.Double(0, 1, 1).normalize(); - private final Vector3D.Double c = new Vector3D.Double(-1, 0, 1).normalize(); - private final Vector3D.Double d = new Vector3D.Double(0, -1, 1).normalize(); + private final Vector3D.Double a = Vector.of(1.0, 0.0, 1.0).normalize(); + private final Vector3D.Double b = Vector.of(0.0, 1.0, 1.0).normalize(); + private final Vector3D.Double c = Vector.of(-1.0, 0.0, 1.0).normalize(); + private final Vector3D.Double d = Vector.of(0.0, -1.0, 1.0).normalize(); private final Array points = NDArrays.of(List.of(a, b, c, d, a), 3, DataType.DOUBLE); private final SphericalConvexPolygon polygon = new SphericalConvexPolygon(new DefaultSphere(3), points); @@ -63,7 +64,7 @@ public class SphericalConvexPolygonTest { */ @Test public void containsInteriorTest() { - assertTrue(polygon.contains(new Vector3D.Double(0, 0, 1))); + assertTrue(polygon.contains(Vector.of(0.0, 0.0, 1.0))); } /** @@ -71,7 +72,7 @@ public class SphericalConvexPolygonTest { */ @Test public void containsOppositeSideTest() { - assertFalse(polygon.contains(new Vector3D.Double(0, 0, -1))); + assertFalse(polygon.contains(Vector.of(0.0, 0.0, -1.0))); } /** @@ -80,10 +81,10 @@ public class SphericalConvexPolygonTest { */ @Test public void containsOutsideEquatorTest() { - assertFalse(polygon.contains(new Vector3D.Double(1, 0, 0))); - assertFalse(polygon.contains(new Vector3D.Double(0, 1, 0))); - assertFalse(polygon.contains(new Vector3D.Double(-1, 0, 0))); - assertFalse(polygon.contains(new Vector3D.Double(0, -1, 0))); + assertFalse(polygon.contains(Vector.of(1.0, 0.0, 0.0))); + assertFalse(polygon.contains(Vector.of(0.0, 1.0, 0.0))); + assertFalse(polygon.contains(Vector.of(-1.0, 0.0, 0.0))); + assertFalse(polygon.contains(Vector.of(0.0, -1.0, 0.0))); } @@ -92,12 +93,12 @@ public class SphericalConvexPolygonTest { */ @Test public void marginTest() { - assertTrue(polygon.margin(new Vector3D.Double(0, 0, 1)) > 0); + assertTrue(polygon.margin(Vector.of(0.0, 0.0, 1.0)) > 0); assertEquals(0, polygon.margin(a), 1e-15); - assertTrue(polygon.margin(new Vector3D.Double(0, 0, -1)) < 0); - assertTrue(polygon.margin(new Vector3D.Double(1, 1, 0).normalize()) < 0); + assertTrue(polygon.margin(Vector.of(0.0, 0.0, -1.0)) < 0); + assertTrue(polygon.margin(Vector.of(1.0, 1.0, 0.0).normalize()) < 0); // a point nearer to the center is further inside - assertTrue(polygon.margin(new Vector3D.Double(0, 0, 1)) > polygon.margin(new Vector3D.Double(0.2, 0, 1).normalize())); + assertTrue(polygon.margin(Vector.of(0.0, 0.0, 1.0)) > polygon.margin(Vector.of(0.2, 0.0, 1.0).normalize())); } /** diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/SphericalPolygonTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/SphericalPolygonTest.java index d1a8e59680..8c632e4507 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/SphericalPolygonTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/SphericalPolygonTest.java @@ -116,7 +116,7 @@ public class SphericalPolygonTest { */ @Test public void edgeNormalsTest() { - final Vector<?>[] ring = {new Vector3D.Double(1, 0, 0), new Vector3D.Double(0, 1, 0), new Vector3D.Double(0, 0, 1)}; + final Vector<?>[] ring = {Vector.of(1.0, 0.0, 0.0), Vector.of(0.0, 1.0, 0.0), Vector.of(0.0, 0.0, 1.0)}; final Vector<?>[] normals = SphericalPolygon.edgeNormals(ring); assertArrayEquals(new double[] {0, 0, 1}, normals[0].toArrayDouble(), TOLERANCE); assertArrayEquals(new double[] {1, 0, 0}, normals[1].toArrayDouble(), TOLERANCE); @@ -128,9 +128,9 @@ public class SphericalPolygonTest { */ @Test public void getAreaTest() { - final Vector3D.Double a = new Vector3D.Double(1, 0, 0); - final Vector3D.Double b = new Vector3D.Double(0, 1, 0); - final Vector3D.Double c = new Vector3D.Double(0, 0, 1); + final Vector3D.Double a = Vector.of(1.0, 0.0, 0.0); + final Vector3D.Double b = Vector.of(0.0, 1.0, 0.0); + final Vector3D.Double c = Vector.of(0.0, 0.0, 1.0); assertEquals(Math.PI / 2, new SphericalPolygon(new DefaultSphere(3), ring(a, b, c)).getArea(), TOLERANCE); assertEquals(Math.PI / 2, new SphericalPolygon(new DefaultSphere(3), ring(c, b, a)).getArea(), TOLERANCE, "winding"); assertEquals(2 * Math.PI, new SphericalPolygon(new DefaultSphere(3, 2), ring(a, b, c)).getArea(), TOLERANCE); diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/SphericalTriangleTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/SphericalTriangleTest.java index 54d2e04ca0..ac80031f64 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/SphericalTriangleTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/spherical/SphericalTriangleTest.java @@ -19,7 +19,6 @@ package org.apache.sis.geometries.spherical; import org.apache.sis.geometries.internal.shared.DefaultSphere; import org.apache.sis.maths.Array; import org.apache.sis.maths.Vector; -import org.apache.sis.maths.Vector3D; // Test dependencies import static org.junit.jupiter.api.Assertions.*; @@ -39,9 +38,9 @@ public class SphericalTriangleTest { * Triangle covering the octant of the sphere where x,y,z are all positive. * Corners are given in CCW order viewed from outside the sphere. */ - private final Vector<?> a = new Vector3D.Double(1, 0, 0); - private final Vector<?> b = new Vector3D.Double(0, 1, 0); - private final Vector<?> c = new Vector3D.Double(0, 0, 1); + private final Vector<?> a = Vector.of(1.0, 0.0, 0.0); + private final Vector<?> b = Vector.of(0.0, 1.0, 0.0); + private final Vector<?> c = Vector.of(0.0, 0.0, 1.0); /** * Constructor and corner accessors test. @@ -84,9 +83,9 @@ public class SphericalTriangleTest { @Test public void getSphericalExcessSmallTest() { for (final double s : new double[] {1e-2, 1e-4, 1e-6}) { - final Vector<?> pole = new Vector3D.Double(0, 0, 1); - final Vector<?> east = new Vector3D.Double(Math.sin(s), 0, Math.cos(s)); - final Vector<?> north = new Vector3D.Double(0, Math.sin(s), Math.cos(s)); + final Vector<?> pole = Vector.of(0.0, 0.0, 1.0); + final Vector<?> east = Vector.of(Math.sin(s), 0.0, Math.cos(s)); + final Vector<?> north = Vector.of(0.0, Math.sin(s), Math.cos(s)); final double t = Math.tan(s / 2); final double expected = 2 * Math.atan(t * t); assertEquals(expected, new SphericalTriangle(new DefaultSphere(3), pole, east, north).getSphericalExcess(), expected * 1e-9); @@ -118,9 +117,9 @@ public class SphericalTriangleTest { assertTrue(triangle.contains(triangle.getB())); assertTrue(triangle.contains(triangle.getC())); assertTrue(triangle.contains(triangle.getCentroidVector())); - assertFalse(triangle.contains(new Vector3D.Double(-1, 0, 0))); - assertFalse(triangle.contains(new Vector3D.Double(0, -1, 0))); - assertFalse(triangle.contains(new Vector3D.Double(0, 0, -1))); + assertFalse(triangle.contains(Vector.of(-1.0, 0.0, 0.0))); + assertFalse(triangle.contains(Vector.of(0.0, -1.0, 0.0))); + assertFalse(triangle.contains(Vector.of(0.0, 0.0, -1.0))); } /** @@ -238,7 +237,7 @@ public class SphericalTriangleTest { final SphericalTriangle triangle = new SphericalTriangle(new DefaultSphere(3), a, b, c); assertTrue(triangle.margin(triangle.getCentroidVector()) > 0); assertEquals(0, triangle.margin(a), 1e-15); - assertTrue(triangle.margin(new Vector3D.Double(-1, -1, -1).normalize()) < 0); + assertTrue(triangle.margin(Vector.of(-1.0, -1.0, -1.0).normalize()) < 0); } /** diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/AbstractVectorTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/AbstractVectorTest.java index 2abd49c0a6..fd99666123 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/AbstractVectorTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/AbstractVectorTest.java @@ -379,7 +379,7 @@ public abstract class AbstractVectorTest { */ private void testCross(Vector<?> vector) { if (vector.getDimension() != 3) return; - final Vector<?> second = new Vector3D.Double(5, 5, 5); + final Vector<?> second = Vector.of(5.0, 5.0, 5.0); final double[] expected = Vectors.cross(vector.toArrayDouble(), second.toArrayDouble()); assertArrayEquals(expected, vector.cross(second).toArrayDouble(), TOLERANCE); } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/ArrayConcatenatedTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/ArrayConcatenatedTest.java index 5fc26546c5..694c71c6ef 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/ArrayConcatenatedTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/ArrayConcatenatedTest.java @@ -48,32 +48,32 @@ public class ArrayConcatenatedTest extends AbstractArrayTest { final Array array3 = NDArrays.of(2, new double[]{8,9,10,11}); final Array cnt = NDArrays.concatenate(array1, array2, array3); - assertEquals(new Vector2D.Double(0,1), cnt.get(0)); - assertEquals(new Vector2D.Double(2,3), cnt.get(1)); - assertEquals(new Vector2D.Double(4,5), cnt.get(2)); - assertEquals(new Vector2D.Double(6,7), cnt.get(3)); - assertEquals(new Vector2D.Double(8,9), cnt.get(4)); - assertEquals(new Vector2D.Double(10,11), cnt.get(5)); + assertEquals(Vector.of(0.0,1.0), cnt.get(0)); + assertEquals(Vector.of(2.0,3.0), cnt.get(1)); + assertEquals(Vector.of(4.0,5.0), cnt.get(2)); + assertEquals(Vector.of(6.0,7.0), cnt.get(3)); + assertEquals(Vector.of(8.0,9.0), cnt.get(4)); + assertEquals(Vector.of(10.0,11.0), cnt.get(5)); - cnt.set(0, new Vector2D.Double(100,101)); - cnt.set(1, new Vector2D.Double(102,103)); - cnt.set(2, new Vector2D.Double(104,105)); - cnt.set(3, new Vector2D.Double(106,107)); - cnt.set(4, new Vector2D.Double(108,109)); - cnt.set(5, new Vector2D.Double(110,111)); - assertEquals(new Vector2D.Double(100,101), cnt.get(0)); - assertEquals(new Vector2D.Double(102,103), cnt.get(1)); - assertEquals(new Vector2D.Double(104,105), cnt.get(2)); - assertEquals(new Vector2D.Double(106,107), cnt.get(3)); - assertEquals(new Vector2D.Double(108,109), cnt.get(4)); - assertEquals(new Vector2D.Double(110,111), cnt.get(5)); + cnt.set(0, Vector.of(100.0,101.0)); + cnt.set(1, Vector.of(102.0,103.0)); + cnt.set(2, Vector.of(104.0,105.0)); + cnt.set(3, Vector.of(106.0,107.0)); + cnt.set(4, Vector.of(108.0,109.0)); + cnt.set(5, Vector.of(110.0,111.0)); + assertEquals(Vector.of(100.0,101.0), cnt.get(0)); + assertEquals(Vector.of(102.0,103.0), cnt.get(1)); + assertEquals(Vector.of(104.0,105.0), cnt.get(2)); + assertEquals(Vector.of(106.0,107.0), cnt.get(3)); + assertEquals(Vector.of(108.0,109.0), cnt.get(4)); + assertEquals(Vector.of(110.0,111.0), cnt.get(5)); //check base arrays are modified - assertEquals(new Vector2D.Double(100,101), array1.get(0)); - assertEquals(new Vector2D.Double(102,103), array1.get(1)); - assertEquals(new Vector2D.Double(104,105), array2.get(0)); - assertEquals(new Vector2D.Double(106,107), array2.get(1)); - assertEquals(new Vector2D.Double(108,109), array3.get(0)); - assertEquals(new Vector2D.Double(110,111), array3.get(1)); + assertEquals(Vector.of(100.0,101.0), array1.get(0)); + assertEquals(Vector.of(102.0,103.0), array1.get(1)); + assertEquals(Vector.of(104.0,105.0), array2.get(0)); + assertEquals(Vector.of(106.0,107.0), array2.get(1)); + assertEquals(Vector.of(108.0,109.0), array3.get(0)); + assertEquals(Vector.of(110.0,111.0), array3.get(1)); } @Test @@ -87,22 +87,22 @@ public class ArrayConcatenatedTest extends AbstractArrayTest { final Cursor cursor = cnt.cursor(); assertTrue(cursor.next()); assertEquals(0, cursor.coordinate()); - assertEquals(new Vector2D.Double(0,1), cursor.getSamples()); + assertEquals(Vector.of(0.0,1.0), cursor.getSamples()); assertTrue(cursor.next()); assertEquals(1, cursor.coordinate()); - assertEquals(new Vector2D.Double(2,3), cursor.getSamples()); + assertEquals(Vector.of(2.0,3.0), cursor.getSamples()); assertTrue(cursor.next()); assertEquals(2, cursor.coordinate()); - assertEquals(new Vector2D.Double(4,5), cursor.getSamples()); + assertEquals(Vector.of(4.0,5.0), cursor.getSamples()); assertTrue(cursor.next()); assertEquals(3, cursor.coordinate()); - assertEquals(new Vector2D.Double(6,7), cursor.getSamples()); + assertEquals(Vector.of(6.0,7.0), cursor.getSamples()); assertTrue(cursor.next()); assertEquals(4, cursor.coordinate()); - assertEquals(new Vector2D.Double(8,9), cursor.getSamples()); + assertEquals(Vector.of(8.0,9.0), cursor.getSamples()); assertTrue(cursor.next()); assertEquals(5, cursor.coordinate()); - assertEquals(new Vector2D.Double(10,11), cursor.getSamples()); + assertEquals(Vector.of(10.0,11.0), cursor.getSamples()); assertFalse(cursor.next()); } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/QuaternionTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/QuaternionTest.java index d08467d530..2dce4c0602 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/QuaternionTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/QuaternionTest.java @@ -85,21 +85,21 @@ public class QuaternionTest { @Test public void testFromEuler(){ - Vector euler = new Vector3D.Double(0, 0, 0); + Vector euler = Vector.of(0.0, 0.0, 0.0); Quaternion q = new Quaternion().setFromEuler(euler); assertArrayEquals(new double[]{0, 0, 0, 1}, q.values, DELTA); - euler = new Vector3D.Double(Math.PI, 0, 0); + euler = Vector.of(Math.PI, 0.0, 0.0); q = new Quaternion().setFromEuler(euler); assertArrayEquals(new double[]{0, 0, 1, 0}, q.values, DELTA); - euler = new Vector3D.Double(0, Math.PI / 2.0, 0); + euler = Vector.of(0.0, Math.PI / 2.0, 0.0); q = new Quaternion().setFromEuler(euler); assertArrayEquals(new double[]{0, Math.cos(Math.PI / 4.0), 0, Math.cos(Math.PI / 4.0)}, q.values, DELTA); euler = q.toEuler(); assertArrayEquals(new double[]{0, Math.PI / 2.0, 0}, euler.toArrayDouble(), DELTA); - euler = new Vector3D.Double(0, 0, Math.PI); + euler = Vector.of(0.0, 0.0, Math.PI); q = new Quaternion().setFromEuler(euler); assertArrayEquals(new double[]{1, 0, 0, 0}, q.values, DELTA); diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/Vector3DTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/Vector3DTest.java index 4efc946d4d..0e2a846500 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/Vector3DTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/Vector3DTest.java @@ -66,22 +66,22 @@ public class Vector3DTest { @Test public void toLatLonTest() { assertArrayEquals(new double[]{0, 0}, - new Vector3D.Double(1, 0, 0).toLatLon(), TOLERANCE); + Vector.of(1.0, 0.0, 0.0).toLatLon(), TOLERANCE); assertArrayEquals(new double[]{0, Math.PI / 2}, - new Vector3D.Double(0, 1, 0).toLatLon(), TOLERANCE); + Vector.of(0.0, 1.0, 0.0).toLatLon(), TOLERANCE); assertArrayEquals(new double[]{0, Math.PI}, - new Vector3D.Double(-1, 0, 0).toLatLon(), TOLERANCE); + Vector.of(-1.0, 0.0, 0.0).toLatLon(), TOLERANCE); assertArrayEquals(new double[]{Math.PI / 2, 0}, - new Vector3D.Double(0, 0, 1).toLatLon(), TOLERANCE); + Vector.of(0.0, 0.0, 1.0).toLatLon(), TOLERANCE); assertArrayEquals(new double[]{-Math.PI / 2, 0}, - new Vector3D.Double(0, 0, -1).toLatLon(), TOLERANCE); + Vector.of(0.0, 0.0, -1.0).toLatLon(), TOLERANCE); assertArrayEquals(new double[]{Math.PI / 4, Math.PI / 4}, - new Vector3D.Double(0.5, 0.5, HALF_SQRT2).toLatLon(), TOLERANCE); + Vector.of(0.5, 0.5, HALF_SQRT2).toLatLon(), TOLERANCE); } /** diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXbTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXbTest.java index 230933a754..8cd601824b 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXbTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXbTest.java @@ -30,13 +30,7 @@ public class VectorXbTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { - switch (dim) { - case 1 : return new Vector1D.Byte((byte)0); - case 2 : return new Vector2D.Byte((byte)0, (byte)0); - case 3 : return new Vector3D.Byte((byte)0, (byte)0, (byte)0); - case 4 : return new Vector4D.Byte((byte)0, (byte)0, (byte)0, (byte)0); - default : return new VectorND.Byte(dim); - } + return Vector.of(DataType.BYTE, new double[dim]); } } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXdTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXdTest.java index bfbbed1336..e8b8619c23 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXdTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXdTest.java @@ -30,13 +30,7 @@ public class VectorXdTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { - switch (dim) { - case 1 : return new Vector1D.Double(0); - case 2 : return new Vector2D.Double(0,0); - case 3 : return new Vector3D.Double(0,0,0); - case 4 : return new Vector4D.Double(0,0,0,0); - default : return new VectorND.Double(dim); - } + return Vector.of(DataType.DOUBLE, new double[dim]); } } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXfTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXfTest.java index f55c5cf039..1f03d05d2c 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXfTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXfTest.java @@ -30,13 +30,7 @@ public class VectorXfTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { - switch (dim) { - case 1 : return new Vector1D.Float(0); - case 2 : return new Vector2D.Float(0,0); - case 3 : return new Vector3D.Float(0,0,0); - case 4 : return new Vector4D.Float(0,0,0,0); - default : return new VectorND.Float(dim); - } + return Vector.of(DataType.FLOAT, new double[dim]); } } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXiTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXiTest.java index 118d65192a..beb930b20d 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXiTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXiTest.java @@ -30,13 +30,7 @@ public class VectorXiTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { - switch (dim) { - case 1 : return new Vector1D.Int(0); - case 2 : return new Vector2D.Int(0,0); - case 3 : return new Vector3D.Int(0,0,0); - case 4 : return new Vector4D.Int(0,0,0,0); - default : return new VectorND.Int(dim); - } + return Vector.of(DataType.INT, new double[dim]); } } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXlTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXlTest.java index a8ed697698..8811adea86 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXlTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXlTest.java @@ -30,13 +30,7 @@ public class VectorXlTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { - switch (dim) { - case 1 : return new Vector1D.Long(0); - case 2 : return new Vector2D.Long(0,0); - case 3 : return new Vector3D.Long(0,0,0); - case 4 : return new Vector4D.Long(0,0,0,0); - default : return new VectorND.Long(dim); - } + return Vector.of(DataType.LONG, new double[dim]); } } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXsTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXsTest.java index b509c19cba..88ae466dd4 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXsTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXsTest.java @@ -30,13 +30,7 @@ public class VectorXsTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { - switch (dim) { - case 1 : return new Vector1D.Short((short)0); - case 2 : return new Vector2D.Short((short)0,(short)0); - case 3 : return new Vector3D.Short((short)0,(short)0,(short)0); - case 4 : return new Vector4D.Short((short)0,(short)0,(short)0,(short)0); - default : return new VectorND.Short(dim); - } + return Vector.of(DataType.SHORT, new double[dim]); } } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXubTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXubTest.java index dbef25f440..1452335b05 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXubTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXubTest.java @@ -30,13 +30,7 @@ public class VectorXubTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { - switch (dim) { - case 1 : return new Vector1D.UByte((byte)0); - case 2 : return new Vector2D.UByte((byte)0,(byte)0); - case 3 : return new Vector3D.UByte((byte)0,(byte)0,(byte)0); - case 4 : return new Vector4D.UByte((byte)0,(byte)0,(byte)0,(byte)0); - default : return new VectorND.UByte(dim); - } + return Vector.of(DataType.UBYTE, new double[dim]); } } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXuiTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXuiTest.java index b7ebda4294..a8d68cc199 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXuiTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXuiTest.java @@ -30,13 +30,7 @@ public class VectorXuiTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { - switch (dim) { - case 1 : return new Vector1D.UInt(0); - case 2 : return new Vector2D.UInt(0,0); - case 3 : return new Vector3D.UInt(0,0,0); - case 4 : return new Vector4D.UInt(0,0,0,0); - default : return new VectorND.UInt(dim); - } + return Vector.of(DataType.UINT, new double[dim]); } } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXusTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXusTest.java index 6bf3bbbf1f..a50df6dfcc 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXusTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorXusTest.java @@ -30,13 +30,7 @@ public class VectorXusTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { - switch (dim) { - case 1 : return new Vector1D.UShort((short)0); - case 2 : return new Vector2D.UShort((short)0,(short)0); - case 3 : return new Vector3D.UShort((short)0,(short)0,(short)0); - case 4 : return new Vector4D.UShort((short)0,(short)0,(short)0,(short)0); - default : return new VectorND.UShort(dim); - } + return Vector.of(DataType.USHORT, new double[dim]); } } diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorsTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorsTest.java index 619ac461f7..14ce8d396f 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorsTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorsTest.java @@ -35,42 +35,42 @@ public class VectorsTest { @Test public void octEncodingTest(){ - Vector3D.Float normal = new Vector3D.Float(1,0,0); + Vector3D.Float normal = Vector.of(1f,0f,0f); byte[] bytes = Vectors.toOctByte(normal); Vector3D.Float res = Vectors.octToNormal(bytes[0], bytes[1]); assertArrayEquals(normal.toArrayFloat(), res.toArrayFloat(), .01f); - normal = new Vector3D.Float(0,1,0); + normal = Vector.of(0f,1f,0f); bytes = Vectors.toOctByte(normal); res = Vectors.octToNormal(bytes[0], bytes[1]); assertArrayEquals(normal.toArrayFloat(), res.toArrayFloat(), .01f); - normal = new Vector3D.Float(0,0,1); + normal = Vector.of(0f,0f,1f); bytes = Vectors.toOctByte(normal); res = Vectors.octToNormal(bytes[0], bytes[1]); assertArrayEquals(normal.toArrayFloat(), res.toArrayFloat(), .01f); - normal = new Vector3D.Float(0.5f,0,0.5f).normalize(); + normal = Vector.of(0.5f,0f,0.5f).normalize(); bytes = Vectors.toOctByte(normal); res = Vectors.octToNormal(bytes[0], bytes[1]); assertArrayEquals(normal.toArrayFloat(), res.toArrayFloat(), .01f); - normal = new Vector3D.Float(-1,0,0).normalize(); + normal = Vector.of(-1f,0f,0f).normalize(); bytes = Vectors.toOctByte(normal); res = Vectors.octToNormal(bytes[0], bytes[1]); assertArrayEquals(normal.toArrayFloat(), res.toArrayFloat(), .01f); - normal = new Vector3D.Float(0,-1,0).normalize(); + normal = Vector.of(0f,-1f,0f).normalize(); bytes = Vectors.toOctByte(normal); res = Vectors.octToNormal(bytes[0], bytes[1]); assertArrayEquals(normal.toArrayFloat(), res.toArrayFloat(), .01f); - normal = new Vector3D.Float(0,0,-1).normalize(); + normal = Vector.of(0f,0f,-1f).normalize(); bytes = Vectors.toOctByte(normal); res = Vectors.octToNormal(bytes[0], bytes[1]); assertArrayEquals(normal.toArrayFloat(), res.toArrayFloat(), .01f); - normal = new Vector3D.Float(0,-0.5f,0.5f).normalize(); + normal = Vector.of(0f,-0.5f,0.5f).normalize(); bytes = Vectors.toOctByte(normal); res = Vectors.octToNormal(bytes[0], bytes[1]); assertArrayEquals(normal.toArrayFloat(), res.toArrayFloat(), .02f); @@ -84,14 +84,14 @@ public class VectorsTest { quantizeBox.setRange(1, 100, 300); quantizeBox.setRange(2, -300, -100); - final Vector3D.Double coord1 = new Vector3D.Double(0,100,-300); - final Vector3D.Double coord2 = new Vector3D.Double(100,300,-100); + final Vector3D.Double coord1 = Vector.of(0.0,100.0,-300.0); + final Vector3D.Double coord2 = Vector.of(100.0,300.0,-100.0); final Vector dp1 = Vectors.toQuantizedEncoding(coord1, quantizeBox, 32767); final Vector dp2 = Vectors.toQuantizedEncoding(coord2, quantizeBox, 32767); - assertEquals(new Vector3D.Double(0, 0, 0), dp1); - assertEquals(new Vector3D.Double(32767, 32767, 32767), dp2); + assertEquals(Vector.of(0.0, 0.0, 0.0), dp1); + assertEquals(Vector.of(32767.0, 32767.0, 32767.0), dp2); assertEquals(DataType.USHORT, dp1.getDataType()); assertEquals(DataType.USHORT, dp2.getDataType()); @@ -109,8 +109,8 @@ public class VectorsTest { MathTransform trs = Vectors.quantizedTransform(quantizeBox, 32767); - final Vector3D.Double coord1 = new Vector3D.Double(0,100,-300); - final Vector3D.Double coord2 = new Vector3D.Double(100,300,-100); + final Vector3D.Double coord1 = Vector.of(0.0,100.0,-300.0); + final Vector3D.Double coord2 = Vector.of(100.0,300.0,-100.0); assertArrayEquals(new double[] {0, 0, 0}, coord1.transform(trs).toArrayDouble(), DELTA); assertArrayEquals(new double[] {32767, 32767, 32767}, coord2.transform(trs).toArrayDouble(), DELTA); @@ -221,8 +221,8 @@ public class VectorsTest { */ @Test public void slerpOnVectorTest() { - final Vector3D.Double start = new Vector3D.Double(1, 0, 0); - final Vector3D.Double end = new Vector3D.Double(0, 1, 0); + final Vector3D.Double start = Vector.of(1.0, 0.0, 0.0); + final Vector3D.Double end = Vector.of(0.0, 1.0, 0.0); final Vector3D.Double result = start.slerp(end, 0.5); assertNotSame(start, result); final double h = Math.sqrt(0.5); @@ -265,11 +265,11 @@ public class VectorsTest { @Test public void shortestAngleOnVectorTest() { final double angle = 1e-10; - final Vector3D.Double a = new Vector3D.Double(1, 0, 0); - final Vector3D.Double b = new Vector3D.Double(3 * Math.cos(angle), 3 * Math.sin(angle), 0); + final Vector3D.Double a = Vector.of(1.0, 0.0, 0.0); + final Vector3D.Double b = Vector.of(3 * Math.cos(angle), 3 * Math.sin(angle), 0.0); assertEquals(angle, a.shortestAngle(b), angle * 1e-6); assertEquals(Vectors.shortestAngle(a.toArrayDouble(), b.toArrayDouble()), a.shortestAngle(b), 0); - assertTrue(Double.isNaN(a.shortestAngle(new Vector3D.Double())), "a zero vector has no direction"); + assertTrue(Double.isNaN(a.shortestAngle(Vector.of(0.0,0.0,0.0))), "a zero vector has no direction"); } /** diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/scene/SceneUtilitiesTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/scene/SceneUtilitiesTest.java index e679ea6c42..651ee9923e 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/scene/SceneUtilitiesTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/scene/SceneUtilitiesTest.java @@ -17,7 +17,7 @@ package org.apache.sis.scene; import org.apache.sis.maths.Similarity3D; -import org.apache.sis.maths.Vector3D; +import org.apache.sis.maths.Vector; // Test dependencies import static org.junit.jupiter.api.Assertions.*; @@ -38,10 +38,10 @@ public class SceneUtilitiesTest { final SceneNode n1 = new SceneNode(); final SceneNode n2 = new SceneNode(); final SceneNode n3 = new SceneNode(); - n0.getTransform().setTranslation(new Vector3D.Double(1,2,3)); - n1.getTransform().setTranslation(new Vector3D.Double(4,5,6)); - n2.getTransform().setTranslation(new Vector3D.Double(10,20,30)); - n3.getTransform().setTranslation(new Vector3D.Double(100,200,300)); + n0.getTransform().setTranslation(Vector.of(1.0,2.0,3.0)); + n1.getTransform().setTranslation(Vector.of(4.0,5.0,6.0)); + n2.getTransform().setTranslation(Vector.of(10.0,20.0,30.0)); + n3.getTransform().setTranslation(Vector.of(100.0,200.0,300.0)); root.getChildren().add(n0); root.getChildren().add(n1); @@ -49,15 +49,15 @@ public class SceneUtilitiesTest { n1.getChildren().add(n3); Similarity3D t = SceneUtilities.computeRootOtNodeTransform(n0); - assertEquals(new Vector3D.Double(1,2,3), t.getTranslation()); + assertEquals(Vector.of(1.0,2.0,3.0), t.getTranslation()); t = SceneUtilities.computeRootOtNodeTransform(n1); - assertEquals(new Vector3D.Double(4,5,6), t.getTranslation()); + assertEquals(Vector.of(4.0,5.0,6.0), t.getTranslation()); t = SceneUtilities.computeRootOtNodeTransform(n2); - assertEquals(new Vector3D.Double(14,25,36), t.getTranslation()); + assertEquals(Vector.of(14.0,25.0,36.0), t.getTranslation()); t = SceneUtilities.computeRootOtNodeTransform(n3); - assertEquals(new Vector3D.Double(104,205,306), t.getTranslation()); + assertEquals(Vector.of(104.0,205.0,306.0), t.getTranslation()); } }
