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 9636a7cdc8ee94bd93ef2a2f446b6f6204ea5dc7 Author: jsorel <[email protected]> AuthorDate: Mon Nov 2 11:23:18 2026 +0100 refactor(Mesh): reused ArrayDataPoints in Mesh classes, Merge ArrayDataPoints.Indexed and MeshPrimitive.Vertex --- .../main/org/apache/sis/geometries/Point.java | 6 +- .../internal/shared/ArrayDataPoints.java | 77 +----- .../sis/geometries/internal/shared/Vertex.java | 82 ++++++ .../apache/sis/geometries/mesh/MeshPrimitive.java | 286 +++++++-------------- .../geometries/mesh/MeshPrimitiveComparator.java | 9 +- .../sis/geometries/mesh/MeshPrimitiveVisitor.java | 20 +- .../sis/geometries/operation/ComputeAttribute.java | 4 +- .../geometries/operation/GeometryProcessor.java | 4 +- .../sis/geometries/operation/Intersection.java | 4 +- .../operation/spatialanalysis2d/ISOBand.java | 4 +- .../operation/spatialanalysis2d/ISOLine.java | 4 +- .../operation/triangulate/delaunay/Delaunay.java | 15 +- .../triangulate/delaunay/OrientedEdge.java | 19 +- .../triangulate/delaunay/OrientedTriangle.java | 5 +- .../sis/geometries/mesh/PrimitiveVisitorTest.java | 3 +- .../triangulate/delaunay/OrientedEdgeTest.java | 2 +- .../org/apache/sis/maths/AbstractVectorTest.java | 25 +- .../test/org/apache/sis/maths/NDRangeTest.java | 10 +- .../test/org/apache/sis/maths/Vector3DTest.java | 2 +- .../test/org/apache/sis/maths/VectorTest.java | 6 +- .../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 +- 29 files changed, 294 insertions(+), 365 deletions(-) diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/Point.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/Point.java index 1ad38a28c6..4581376796 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/Point.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/Point.java @@ -28,10 +28,9 @@ import org.opengis.referencing.cs.CoordinateSystem; import org.opengis.referencing.cs.EllipsoidalCS; import org.opengis.referencing.cs.SphericalCS; import org.apache.sis.geometries.cs.Bearing; -import org.apache.sis.geometries.internal.shared.ArrayDataPoints; import org.apache.sis.geometries.internal.shared.DefaultPoint; import org.apache.sis.geometries.internal.shared.IndexedPoint; -import org.apache.sis.geometries.mesh.MeshPrimitive; +import org.apache.sis.geometries.internal.shared.Vertex; import org.apache.sis.maths.DataType; import org.apache.sis.maths.NDRange; import org.apache.sis.maths.Vector; @@ -69,8 +68,7 @@ import org.apache.sis.util.Utilities; public sealed interface Point extends Primitive permits DefaultPoint, IndexedPoint, - ArrayDataPoints.Indexed, - MeshPrimitive.Vertex, + Vertex, DataPoints.InterpolatedPoint { diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/ArrayDataPoints.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/ArrayDataPoints.java index 69f7698582..5d02e25e6a 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/ArrayDataPoints.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/ArrayDataPoints.java @@ -63,6 +63,14 @@ public final class ArrayDataPoints implements DataPoints, DataPointsType { } } + public ArrayDataPoints(DataPointsType attDef) { + for (String name : attDef.getAttributeNames()) { + attributes.put(name, NDArrays.of(attDef.getAttributeSystem(name), attDef.getAttributeType(name), 0)); + } + positions = attributes.get(DataPointsType.ATT_POSITION); + ArgumentChecks.ensureNonNull(DataPointsType.ATT_POSITION, positions); + } + @Override public CoordinateReferenceSystem getCoordinateReferenceSystem() { return positions.getCoordinateReferenceSystem(); @@ -89,8 +97,8 @@ public final class ArrayDataPoints implements DataPoints, DataPointsType { } @Override - public Point getPoint(int index) { - return new Indexed(this, index); + public Vertex getPoint(int index) { + return new Vertex(this, index); } @Override @@ -207,69 +215,4 @@ public final class ArrayDataPoints implements DataPoints, DataPointsType { return DataPoints.equals(this, obj); } - /** - * An indexed point in the {@code DataPoints} - */ - public static non-sealed class Indexed implements Point { - - private final ArrayDataPoints parent; - private final int index; - - public Indexed(ArrayDataPoints geometry, int index) { - this.parent = geometry; - this.index = index; - } - - @Override - public boolean isEmpty() { - return false; - } - - @Override - public Vector getPosition() { - final Cursor cursor = parent.positions.cursor(); - cursor.moveTo(index); - return cursor.getSamples(); - } - - /** - * @return index in the parent mesh. - */ - public int getIndex() { - return index; - } - - @Override - public Vector getAttribute(String key) { - final Array tupleGrid = parent.attributes.get(key); - if (tupleGrid == null) return null; - final Cursor cursor = tupleGrid.cursor(); - cursor.moveTo(index); - return cursor.getSamples(); - } - - @Override - public void setAttribute(String name, Vector tuple) { - final Array tupleGrid = parent.attributes.get(name); - if (tupleGrid == null) throw new IllegalArgumentException("Attribute " + name + " do not exist"); - final Cursor cursor = tupleGrid.cursor(); - cursor.moveTo(index); - cursor.setSamples(tuple); - } - - @Override - public CoordinateReferenceSystem getCoordinateReferenceSystem() { - return parent.getCoordinateReferenceSystem(); - } - - @Override - public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) { - throw new UnsupportedOperationException("Not supported."); - } - - @Override - public DataPointsType getDataPointsType() { - return parent.getType(); - } - } } diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/Vertex.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/Vertex.java new file mode 100644 index 0000000000..2763cf886f --- /dev/null +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/Vertex.java @@ -0,0 +1,82 @@ +/* + * 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.sis.geometries.internal.shared; + +import org.apache.sis.geometries.DataPoints; +import org.apache.sis.geometries.DataPointsType; +import org.apache.sis.geometries.Point; +import org.apache.sis.maths.Vector; +import org.opengis.referencing.crs.CoordinateReferenceSystem; + +/** + * An indexed point in the {@code DataPoints} + * + * @author Johann Sorel (Geomatys) + */ +public final class Vertex implements Point { + + private final DataPoints parent; + private final int index; + + public Vertex(DataPoints geometry, long index) { + this.parent = geometry; + this.index = Math.toIntExact(index); + } + + @Override + public boolean isEmpty() { + return false; + } + + @Override + public Vector getPosition() { + return parent.getPosition(index); + } + + /** + * @return index in the parent mesh. + */ + public long getIndex() { + return index; + } + + @Override + public Vector getAttribute(String key) { + return parent.getAttribute(index, key); + } + + @Override + public void setAttribute(String name, Vector tuple) { + parent.setAttribute(index, name, tuple); + } + + @Override + public CoordinateReferenceSystem getCoordinateReferenceSystem() { + return parent.getCoordinateReferenceSystem(); + } + + @Override + public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) { + throw new UnsupportedOperationException("Not supported."); + } + + @Override + public DataPointsType getDataPointsType() { + return parent.getType(); + } + +} 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 7978dbcd57..e4dabfa4a7 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 @@ -21,13 +21,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.Set; -import java.util.TreeSet; import java.util.logging.Level; import java.util.logging.Logger; import org.opengis.geometry.Envelope; @@ -39,8 +37,17 @@ import org.apache.sis.geometries.GeometryFactory; import org.apache.sis.geometries.GeometryType; import org.apache.sis.geometries.Point; import org.apache.sis.geometries.DataPointsType; +import static org.apache.sis.geometries.DataPointsType.ATT_COLOR; +import static org.apache.sis.geometries.DataPointsType.ATT_JOINTS; +import static org.apache.sis.geometries.DataPointsType.ATT_NORMAL; +import static org.apache.sis.geometries.DataPointsType.ATT_POSITION; +import static org.apache.sis.geometries.DataPointsType.ATT_TANGENT; +import static org.apache.sis.geometries.DataPointsType.ATT_TEXCOORD; +import static org.apache.sis.geometries.DataPointsType.ATT_WEIGHTS; import org.apache.sis.geometries.GeometryCollection; import org.apache.sis.geometries.curve.LineString; +import org.apache.sis.geometries.internal.shared.ArrayDataPoints; +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.geometry.GeneralEnvelope; @@ -55,7 +62,6 @@ import org.apache.sis.maths.Vector; import org.apache.sis.maths.Vector1D; import org.apache.sis.maths.Vector3D; import org.apache.sis.util.ArgumentChecks; -import org.apache.sis.util.collection.Containers; /** @@ -102,16 +108,22 @@ public sealed interface MeshPrimitive extends Geometry } } - public static MeshPrimitive createEmpty(Type type, DataPointsType attDef) { - Abs p = (Abs) create(type); - for (String name : attDef.getAttributeNames()) { - p.attributes.put(name, NDArrays.of(attDef.getAttributeSystem(name), attDef.getAttributeType(name), 0)); + public static MeshPrimitive create(Type type, ArrayDataPoints dataPoints) { + switch (type) { + case POINTS: return new Points(dataPoints); + case LINES: return new Lines(dataPoints); + case LINE_LOOP: return new LineLoop(dataPoints); + case LINE_STRIP: return new LineStrip(dataPoints); + case TRIANGLES: return new Triangles(dataPoints); + case TRIANGLE_FAN: return new TriangleFan(dataPoints); + case TRIANGLE_STRIP: return new TriangleStrip(dataPoints); + default: throw new IllegalArgumentException("Unknown type " + type); } - p.positions = p.attributes.get(DataPointsType.ATT_POSITION); - ArgumentChecks.ensureNonNull(DataPointsType.ATT_POSITION, p.positions); - return p; } + public static MeshPrimitive createEmpty(Type type, DataPointsType attDef) { + return create(type, new ArrayDataPoints(attDef)); + } /** * @return primitive (and positions) CRS. @@ -243,7 +255,7 @@ public sealed interface MeshPrimitive extends Geometry * @param index vertex index. * @return Vertex */ - Vertex getVertex(int index); + Vertex getVertex(long index); /** * Create a deep copy of this primitive. @@ -277,7 +289,7 @@ public sealed interface MeshPrimitive extends Geometry */ void removeDuplicatesByPosition(); - public static abstract sealed class Abs implements MeshPrimitive, DataPointsType + public static abstract sealed class Abs implements MeshPrimitive permits Points, Lines, LineLoop, @@ -290,7 +302,7 @@ public sealed interface MeshPrimitive extends Geometry /** * Checks Array change for position is in the same crs as the geometry. */ - protected final LinkedHashMap<String,Array> attributes = new LinkedHashMap<>(); + protected final ArrayDataPoints dataPoints; protected Array index; protected final Type type; //keep it as variable for fast access, used a lot @@ -299,8 +311,12 @@ public sealed interface MeshPrimitive extends Geometry private Map<String, Object> userProperties; protected Abs(Type type) { - positions = NDArrays.of(SampleSystem.of(Geometries.RIGHT_HAND_3D), new double[0]); - attributes.put(DataPointsType.ATT_POSITION, positions); + this(type, new ArrayDataPoints(NDArrays.of(SampleSystem.of(Geometries.RIGHT_HAND_3D), new double[0]))); + } + + protected Abs(Type type, ArrayDataPoints dataPoints) { + this.dataPoints = dataPoints; + this.positions = dataPoints.getAttribute(ATT_POSITION); this.type = type; } @@ -321,27 +337,13 @@ public sealed interface MeshPrimitive extends Geometry } @Override - public DataPointsType getDataPointsType() { - return this; - } - - @Override - public List<String> getAttributeNames() { - return Containers.copyToImmutableList(attributes.keySet(), String.class); + public ArrayDataPoints getDataPoints() { + return dataPoints; } @Override - public SampleSystem getAttributeSystem(String name) { - final Array ta = attributes.get(name); - if (ta == null) return null; - return ta.getSampleSystem(); - } - - @Override - public DataType getAttributeType(String name) { - final Array ta = attributes.get(name); - if (ta == null) return null; - return ta.getDataType(); + public DataPointsType getDataPointsType() { + return dataPoints.getType(); } /** @@ -351,7 +353,7 @@ public sealed interface MeshPrimitive extends Geometry */ @Override public Envelope getEnvelope() { - final Array positions = getAttribute(ATT_POSITION); + final Array positions = getDataPoints().getAttribute(ATT_POSITION); if (positions.isEmpty()) { final GeneralEnvelope env = new GeneralEnvelope(getCoordinateReferenceSystem()); env.setToNaN(); @@ -369,7 +371,7 @@ public sealed interface MeshPrimitive extends Geometry final List<Geometry> elements = new ArrayList<>(); MeshPrimitiveVisitor visitor = new MeshPrimitiveVisitor(this) { @Override - protected void visit(MeshPrimitive.Vertex vertex) { + protected void visit(Vertex vertex) { } @Override @@ -422,7 +424,7 @@ public sealed interface MeshPrimitive extends Geometry */ @Override public Array getAttribute(String name) { - return attributes.get(name); + return dataPoints.getAttribute(name); } /** @@ -435,9 +437,9 @@ public sealed interface MeshPrimitive extends Geometry //makes extract verifications setPositions(array); } else if (array == null) { - attributes.remove(name); + dataPoints.setAttribute(name, null); } else { - attributes.put(name, array); + dataPoints.setAttribute(name, array); } } @@ -489,23 +491,6 @@ public sealed interface MeshPrimitive extends Geometry return positions; } - /** - * Returns the positions this primitive draws, in the order it draws them. When the - * primitive carries an index, the positions appear in the order that index names them, - * and a position the index names several times appears as many times. - */ - @Override - public DataPoints getDataPoints() { - final int[] indices; - if (index == null) { - indices = new int[Math.toIntExact(getPositions().getLength())]; - for (int i = 0; i < indices.length; i++) indices[i] = i; - } else { - indices = index.toArrayInt(); - } - return new Sequence(this, indices); - } - /** * Change positions. * Caution : changing the positions will change the primitive CRS, @@ -517,7 +502,7 @@ public sealed interface MeshPrimitive extends Geometry ArgumentChecks.ensureNonNull(ATT_POSITION, array); ArgumentChecks.ensureNonNull("positions crs", array.getCoordinateReferenceSystem()); this.positions = array; - attributes.put(ATT_POSITION, array); + getDataPoints().setAttribute(ATT_POSITION, array); } /** @@ -525,12 +510,12 @@ public sealed interface MeshPrimitive extends Geometry */ @Override public Array getNormals() { - return getAttribute(ATT_NORMAL); + return getDataPoints().getAttribute(ATT_NORMAL); } @Override public void setNormals(Array array) { - attributes.put(ATT_NORMAL, array); + getDataPoints().setAttribute(ATT_NORMAL, array); } /** @@ -543,7 +528,7 @@ public sealed interface MeshPrimitive extends Geometry @Override public void setTangents(Array array) { - attributes.put(ATT_TANGENT, array); + getDataPoints().setAttribute(ATT_TANGENT, array); } /** @@ -556,7 +541,7 @@ public sealed interface MeshPrimitive extends Geometry @Override public void setColors(int index, Array array) { - attributes.put(ATT_COLOR + "_" + index, array); + getDataPoints().setAttribute(ATT_COLOR + "_" + index, array); } /** @@ -569,7 +554,7 @@ public sealed interface MeshPrimitive extends Geometry @Override public void setTexCoords(int index, Array array) { - attributes.put(ATT_TEXCOORD + "_" + index, array); + getDataPoints().setAttribute(ATT_TEXCOORD + "_" + index, array); } /** @@ -582,7 +567,7 @@ public sealed interface MeshPrimitive extends Geometry @Override public void setJoints(int index, Array array) { - attributes.put(ATT_JOINTS + "_" + index, array); + getDataPoints().setAttribute(ATT_JOINTS + "_" + index, array); } /** @@ -595,7 +580,7 @@ public sealed interface MeshPrimitive extends Geometry @Override public void setWeights(int index, Array array) { - attributes.put(ATT_WEIGHTS + "_" + index, array); + getDataPoints().setAttribute(ATT_WEIGHTS + "_" + index, array); } /** @@ -609,11 +594,12 @@ public sealed interface MeshPrimitive extends Geometry } long size = -1; - for (Map.Entry<String,Array> entry : attributes.entrySet()) { - validate(entry.getKey(), entry.getValue()); + for (String attName : getDataPoints().getAttributeNames()) { + Array array = getDataPoints().getAttribute(attName); + validate(attName, array); if (size == -1) { - size = entry.getValue().getLength(); - } else if (size != entry.getValue().getLength()) { + size = array.getLength(); + } else if (size != array.getLength()) { throw new IllegalArgumentException("Attributes have different tuple array lengths."); } } @@ -710,8 +696,8 @@ public sealed interface MeshPrimitive extends Geometry * @return Vertex */ @Override - public Vertex getVertex(int index) { - return new Vertex(this, index); + public Vertex getVertex(long index) { + return dataPoints.getPoint(Math.toIntExact(index)); } /** @@ -725,15 +711,15 @@ public sealed interface MeshPrimitive extends Geometry public MeshPrimitive deepCopy() { final Abs copy = (Abs) create(type); - for (Map.Entry<String,Array> entry : attributes.entrySet()) { - copy.attributes.put(entry.getKey(), entry.getValue().copy()); + for (String attName : getDataPoints().getAttributeNames()) { + copy.dataPoints.setAttribute(attName, dataPoints.getAttribute(attName).copy()); } //copy index and ranges if (index != null) { copy.setIndex(index.copy()); } - copy.positions = copy.attributes.get(DataPointsType.ATT_POSITION); + copy.positions = copy.dataPoints.getAttribute(DataPointsType.ATT_POSITION); return copy; } @@ -807,15 +793,15 @@ public sealed interface MeshPrimitive extends Geometry new MeshPrimitiveVisitor(this) { @Override - protected void visit(MeshPrimitive.Vertex vertex) { + protected void visit(Vertex vertex) { } @Override protected void visit(Triangle candidate) { final DataPoints points = candidate.getExteriorRing().getDataPoints(); - long idx0 = ((MeshPrimitive.Vertex)points.getPoint(0)).getIndex(); - long idx1 = ((MeshPrimitive.Vertex)points.getPoint(1)).getIndex(); - long idx2 = ((MeshPrimitive.Vertex)points.getPoint(2)).getIndex(); + long idx0 = ((Vertex)points.getPoint(0)).getIndex(); + long idx1 = ((Vertex)points.getPoint(1)).getIndex(); + long idx2 = ((Vertex)points.getPoint(2)).getIndex(); if (idx0 == idx1 || idx0 == idx2 || idx1 == idx2) { //flat triangle ignore it return; @@ -844,8 +830,8 @@ public sealed interface MeshPrimitive extends Geometry @Override protected void visit(LineString candidate) { final DataPoints points = candidate.getDataPoints(); - long idx0 = ((MeshPrimitive.Vertex)points.getPoint(0)).getIndex(); - long idx1 = ((MeshPrimitive.Vertex)points.getPoint(1)).getIndex(); + long idx0 = ((Vertex)points.getPoint(0)).getIndex(); + long idx1 = ((Vertex)points.getPoint(1)).getIndex(); final Vector normal = new Vector3D.Float(0,0,1); normals.set(idx0, normals.get(idx0).add(normal)); @@ -886,13 +872,13 @@ public sealed interface MeshPrimitive extends Geometry @Override public void removeDuplicatesByPosition() { - final Set<String> attNames = attributes.keySet(); + final List<String> attNames = dataPoints.getAttributeNames(); final Map<String,List<Vector<?>>> atts = new HashMap<>(); final List<Entry<List<Vector<?>>,Array>> mapping = new ArrayList<>(); for (String attName : attNames) { final List<Vector<?>> lst = new ArrayList<>(); atts.put(attName, lst); - mapping.add(new AbstractMap.SimpleImmutableEntry<>(lst, attributes.get(attName))); + mapping.add(new AbstractMap.SimpleImmutableEntry<>(lst, dataPoints.getAttribute(attName))); } final List<Vector<?>> aNewAttribute = mapping.get(0).getKey(); @@ -921,21 +907,18 @@ public sealed interface MeshPrimitive extends Geometry setIndex(NDArrays.of(newIndex, 1, index.getDataType())); - final Map<String, Array> newAttributes = new HashMap<>(); for (String attName : attNames) { - final Array model = attributes.get(attName); + final Array model = dataPoints.getAttribute(attName); final Array array = NDArrays.of(atts.get(attName), model.getSampleSystem(), model.getDataType()); - newAttributes.put(attName, array); + getDataPoints().setAttribute(attName, array); } - attributes.clear(); - attributes.putAll(newAttributes); - positions = attributes.get(DataPointsType.ATT_POSITION); + positions = dataPoints.getAttribute(DataPointsType.ATT_POSITION); } @Override public int hashCode() { int hash = 7; - hash = 23 * hash + Objects.hashCode(this.attributes); + hash = 23 * hash + Objects.hashCode(this.dataPoints); hash = 23 * hash + Objects.hashCode(this.index); hash = 23 * hash + Objects.hashCode(this.type); return hash; @@ -953,7 +936,7 @@ public sealed interface MeshPrimitive extends Geometry return false; } final Abs other = (Abs) obj; - if (!Objects.equals(this.attributes, other.attributes)) { + if (!Objects.equals(this.dataPoints, other.dataPoints)) { return false; } if (!Objects.equals(this.index, other.index)) { @@ -974,91 +957,6 @@ public sealed interface MeshPrimitive extends Geometry } } - - /** - * A vertex is a indexed point in a geometry. - */ - public static final class Vertex implements Point { - - private final Abs parent; - private long index; - - public Vertex(MeshPrimitive geometry, long index) { - this.parent = (Abs) geometry; - this.index = index; - } - - @Override - public Vector getPosition() { - final Cursor cursor = parent.getPositions().cursor(); - cursor.moveTo(index); - return cursor.getSamples(); - } - - @Override - public boolean isEmpty() { - return false; - } - - /** - * @return index in the parent mesh. - */ - public long getIndex() { - return index; - } - - public void setIndex(long index) { - this.index = index; - } - - @Override - public Vector getAttribute(String key) { - final Array tupleGrid = parent.attributes.get(key); - if (tupleGrid == null) return null; - final Cursor cursor = tupleGrid.cursor(); - cursor.moveTo(index); - return cursor.getSamples(); - } - - @Override - public void setAttribute(String name, Vector tuple) { - final Array tupleGrid = parent.attributes.get(name); - if (tupleGrid == null) throw new IllegalArgumentException("Attribute " + name + " do not exist"); - final Cursor cursor = tupleGrid.cursor(); - cursor.moveTo(index); - cursor.setSamples(tuple); - } - - @Override - public CoordinateReferenceSystem getCoordinateReferenceSystem() { - return parent.getCoordinateReferenceSystem(); - } - - @Override - public void setCoordinateReferenceSystem(CoordinateReferenceSystem crs) { - throw new UnsupportedOperationException("Not supported."); - } - - @Override - public DataPointsType getDataPointsType() { - return parent.getDataPointsType(); - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("V:"); - sb.append(getIndex()); - final TreeSet<String> properties = new TreeSet<>(getDataPointsType().getAttributeNames()); - for (String name : properties) { - sb.append(" "); - sb.append(name); - final Vector tuple = getAttribute(name); - sb.append(Arrays.toString(tuple.toArrayDouble())); - } - return sb.toString(); - } - } - public static final class Sequence implements DataPoints { private final Abs primitive; @@ -1086,7 +984,7 @@ public sealed interface MeshPrimitive extends Geometry @Override public Point getPoint(int index) { - return new Vertex(primitive, this.index[index]); + return primitive.dataPoints.getPoint(this.index[index]); } @Override @@ -1125,6 +1023,10 @@ public sealed interface MeshPrimitive extends Geometry super(Type.POINTS); } + public Points(ArrayDataPoints dp) { + super(Type.POINTS, dp); + } + @Override public GeometryType getGeometryType() { return GeometryType.COLLECTION; @@ -1154,6 +1056,10 @@ public sealed interface MeshPrimitive extends Geometry super(Type.LINES); } + public Lines(ArrayDataPoints dp) { + super(Type.LINES, dp); + } + @Override public GeometryType getElementType() { return GeometryType.LINESTRING; @@ -1177,21 +1083,8 @@ public sealed interface MeshPrimitive extends Geometry public LineLoop() { super(Type.LINE_LOOP); } - - @Override - public DataPoints getDataPoints() { - //select all points, duplicate first point as last - int[] indices; - if (index == null) { - indices = new int[Math.toIntExact(getPositions().getLength() + 1)]; - for (int i = 0; i < indices.length; i++) indices[i] = i; - indices[indices.length - 1] = 0; - } else { - indices = index.toArrayInt(); - indices = Arrays.copyOf(indices, indices.length + 1); - indices[indices.length - 1] = indices[0]; - } - return new Sequence(this, indices); + public LineLoop(ArrayDataPoints dp) { + super(Type.LINE_LOOP, dp); } } @@ -1200,6 +1093,9 @@ public sealed interface MeshPrimitive extends Geometry super(Type.LINE_STRIP); } + public LineStrip(ArrayDataPoints dp) { + super(Type.LINE_STRIP, dp); + } } public static final class Triangles extends Abs implements TIN { @@ -1207,6 +1103,10 @@ public sealed interface MeshPrimitive extends Geometry super(Type.TRIANGLES); } + public Triangles(ArrayDataPoints dp) { + super(Type.TRIANGLES, dp); + } + @Override public int getNumPatches() { long nb = (index == null) ? getPositions().getLength() : this.index.getLength(); @@ -1233,6 +1133,10 @@ public sealed interface MeshPrimitive extends Geometry super(Type.TRIANGLE_FAN); } + public TriangleFan(ArrayDataPoints dp) { + super(Type.TRIANGLE_FAN, dp); + } + @Override public int getNumPatches() { long nb = (index == null) ? getPositions().getLength() : this.index.getLength(); @@ -1261,6 +1165,10 @@ public sealed interface MeshPrimitive extends Geometry super(Type.TRIANGLE_STRIP); } + public TriangleStrip(ArrayDataPoints dp) { + super(Type.TRIANGLE_STRIP, dp); + } + @Override public int getNumPatches() { long nb = (index == null) ? getPositions().getLength() : this.index.getLength(); diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitiveComparator.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitiveComparator.java index 77aba3d270..678efce761 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitiveComparator.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitiveComparator.java @@ -25,7 +25,8 @@ import org.apache.sis.geometries.DataPoints; import org.apache.sis.geometries.Geometry; import org.apache.sis.geometries.Point; import org.apache.sis.geometries.curve.LineString; -import org.apache.sis.geometries.mesh.MeshPrimitive.Vertex; +import org.apache.sis.geometries.internal.shared.ArrayDataPoints; +import org.apache.sis.geometries.internal.shared.Vertex; import org.apache.sis.geometries.surface.Triangle; import org.apache.sis.maths.Array; import org.apache.sis.maths.Vector; @@ -190,7 +191,7 @@ public final class MeshPrimitiveComparator { if (expected instanceof Point && candidate instanceof Point) { final Point e1 = (Point) expected; final Point e2 = (Point) candidate; - return compareVertex((MeshPrimitive.Vertex) e1, (MeshPrimitive.Vertex) e2); + return compareVertex((Vertex) e1, (Vertex) e2); } else if (expected instanceof LineString && candidate instanceof LineString) { final LineString e1 = (LineString) expected; @@ -225,7 +226,7 @@ public final class MeshPrimitiveComparator { * Compare two mesh vertex attributes. * @return true if vertex are equal. */ - private boolean compareVertex(MeshPrimitive.Vertex expected, MeshPrimitive.Vertex candidate) { + private boolean compareVertex(Vertex expected, Vertex candidate) { Collection<String> toTest = comparedAttributes; if (toTest.isEmpty()) { @@ -279,7 +280,7 @@ public final class MeshPrimitiveComparator { final List<Geometry> elements = new ArrayList<>(); final MeshPrimitiveVisitor visitor = new MeshPrimitiveVisitor(p) { @Override - protected void visit(MeshPrimitive.Vertex vertex) { + protected void visit(Vertex vertex) { } @Override diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitiveVisitor.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitiveVisitor.java index 31fc30117c..f1e66cbcc5 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitiveVisitor.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/mesh/MeshPrimitiveVisitor.java @@ -22,6 +22,8 @@ import org.apache.sis.geometries.Geometry; import org.apache.sis.geometries.GeometryFactory; import org.apache.sis.geometries.Point; import org.apache.sis.geometries.curve.LineString; +import org.apache.sis.geometries.internal.shared.ArrayDataPoints; +import org.apache.sis.geometries.internal.shared.Vertex; import org.apache.sis.geometries.surface.Triangle; import org.apache.sis.maths.Array; import org.apache.sis.maths.Cursor; @@ -189,7 +191,7 @@ public abstract class MeshPrimitiveVisitor { } private Point readPoint(int idx0) { - return new MeshPrimitive.Vertex(primitive, idx0); + return primitive.getDataPoints().getPoint(idx0); } private Triangle readTriangle(int idx0, int idx1, int idx2) { @@ -205,9 +207,9 @@ public abstract class MeshPrimitiveVisitor { */ protected void visit(Triangle candidate) { final DataPoints points = candidate.getExteriorRing().getDataPoints(); - visit((MeshPrimitive.Vertex) points.getPoint(0)); - visit((MeshPrimitive.Vertex) points.getPoint(1)); - visit((MeshPrimitive.Vertex) points.getPoint(2)); + visit((Vertex) points.getPoint(0)); + visit((Vertex) points.getPoint(1)); + visit((Vertex) points.getPoint(2)); } /** @@ -215,24 +217,24 @@ public abstract class MeshPrimitiveVisitor { */ protected void visit(LineString candidate) { final DataPoints points = candidate.getDataPoints(); - visit((MeshPrimitive.Vertex) points.getPoint(0)); - visit((MeshPrimitive.Vertex) points.getPoint(1)); + visit((Vertex) points.getPoint(0)); + visit((Vertex) points.getPoint(1)); } /** * Override this method to process a point. */ protected void visit(Point candidate) { - visit((MeshPrimitive.Vertex) candidate); + visit((Vertex) candidate); } /** * Called when visiting a mesh vertex. * @param vertex visited vertex. */ - protected abstract void visit(MeshPrimitive.Vertex vertex); + protected abstract void visit(Vertex vertex); - public boolean isVisited(MeshPrimitive.Vertex vertex) { + public boolean isVisited(Vertex vertex) { return visited.contains(vertex.getIndex()); } diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/ComputeAttribute.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/ComputeAttribute.java index 06e627eefa..340e5eeb6b 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/ComputeAttribute.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/ComputeAttribute.java @@ -21,6 +21,8 @@ import java.util.List; import java.util.function.Function; import org.apache.sis.geometries.Geometry; import org.apache.sis.geometries.Point; +import org.apache.sis.geometries.internal.shared.ArrayDataPoints; +import org.apache.sis.geometries.internal.shared.Vertex; import org.apache.sis.geometries.mesh.MeshPrimitive; import org.apache.sis.geometries.mesh.MeshPrimitiveVisitor; import org.apache.sis.geometries.mesh.MultiMeshPrimitive; @@ -56,7 +58,7 @@ public final class ComputeAttribute { if (valueGenerator != null) { new MeshPrimitiveVisitor(copy3d) { @Override - protected void visit(org.apache.sis.geometries.mesh.MeshPrimitive.Vertex vertex) { + protected void visit(Vertex vertex) { vertex.setAttribute(attributeName, valueGenerator.apply(vertex)); } }.visit(); diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/GeometryProcessor.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/GeometryProcessor.java index 7a59ed9664..f0b6b46967 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/GeometryProcessor.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/GeometryProcessor.java @@ -40,6 +40,8 @@ import org.apache.sis.geometries.Point; import org.apache.sis.geometries.Prism; import org.apache.sis.geometries.curve.LineString; import org.apache.sis.geometries.curve.LinearRing; +import org.apache.sis.geometries.internal.shared.ArrayDataPoints; +import org.apache.sis.geometries.internal.shared.Vertex; import org.apache.sis.geometries.mesh.MeshPrimitive; import org.apache.sis.geometries.mesh.MeshPrimitiveVisitor; import org.apache.sis.geometries.mesh.MultiMeshPrimitive; @@ -594,7 +596,7 @@ public final class GeometryProcessor { } @Override - protected void visit(MeshPrimitive.Vertex vertex) {} + protected void visit(Vertex vertex) {} }; pv.visit(); diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/Intersection.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/Intersection.java index a45f5baaef..f27490fb05 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/Intersection.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/Intersection.java @@ -30,9 +30,11 @@ import org.apache.sis.geometries.Point; import org.apache.sis.geometries.DataPointsType; import org.apache.sis.geometries.GeometryCollection; import org.apache.sis.geometries.curve.LineString; +import org.apache.sis.geometries.internal.shared.ArrayDataPoints; import org.apache.sis.geometries.internal.shared.DefaultDataPoints; import org.apache.sis.geometries.internal.shared.DefaultNurbCurve; import org.apache.sis.geometries.internal.shared.DefaultNurbSurface; +import org.apache.sis.geometries.internal.shared.Vertex; import org.apache.sis.geometries.mesh.MeshPrimitive; import org.apache.sis.geometries.mesh.MeshPrimitiveVisitor; import org.apache.sis.geometries.mesh.MultiMeshPrimitive; @@ -106,7 +108,7 @@ public final class Intersection { final PreparedTIN.Evaluator evaluator = tin.evaluator(); new MeshPrimitiveVisitor(primitive) { @Override - protected void visit(MeshPrimitive.Vertex vertex) { + protected void visit(Vertex vertex) { if (isVisited(vertex)) return; final Optional<Point> opt = evaluator.evaluate(vertex.getCoordinateReferenceSystem(), vertex.getPosition()); if (opt.isEmpty()) return; diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/spatialanalysis2d/ISOBand.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/spatialanalysis2d/ISOBand.java index 99a31f9ebb..6a9ced0b47 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/spatialanalysis2d/ISOBand.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/spatialanalysis2d/ISOBand.java @@ -29,6 +29,8 @@ import org.locationtech.jts.geom.impl.PackedCoordinateSequence; import org.locationtech.jts.geom.impl.PackedCoordinateSequenceFactory; import org.opengis.util.FactoryException; import org.apache.sis.geometries.DataPoints; +import org.apache.sis.geometries.internal.shared.ArrayDataPoints; +import org.apache.sis.geometries.internal.shared.Vertex; import org.apache.sis.geometries.mesh.MeshPrimitive; import org.apache.sis.geometries.mesh.MeshPrimitiveVisitor; import static org.apache.sis.geometries.operation.spatialanalysis2d.ISOLine.interpolateToArray; @@ -114,7 +116,7 @@ public final class ISOBand { } @Override - protected void visit(MeshPrimitive.Vertex vertex) { + protected void visit(Vertex vertex) { } }; visitor.visit(); diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/spatialanalysis2d/ISOLine.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/spatialanalysis2d/ISOLine.java index 294d0595d5..607b8c780a 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/spatialanalysis2d/ISOLine.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/spatialanalysis2d/ISOLine.java @@ -23,6 +23,8 @@ import org.locationtech.jts.geom.Coordinate; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.opengis.util.FactoryException; import org.apache.sis.geometries.DataPoints; +import org.apache.sis.geometries.internal.shared.ArrayDataPoints; +import org.apache.sis.geometries.internal.shared.Vertex; import org.apache.sis.geometries.mesh.MeshPrimitive; import org.apache.sis.geometries.mesh.MeshPrimitiveVisitor; import org.apache.sis.geometries.surface.Triangle; @@ -97,7 +99,7 @@ public final class ISOLine { } @Override - protected void visit(MeshPrimitive.Vertex vertex) { + protected void visit(Vertex vertex) { } }; visitor.visit(); diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/delaunay/Delaunay.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/delaunay/Delaunay.java index 279d475806..c4b431fbe7 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/delaunay/Delaunay.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/delaunay/Delaunay.java @@ -28,9 +28,10 @@ import java.util.logging.Logger; import org.opengis.geometry.Envelope; import org.apache.sis.geometries.Geometries; import org.apache.sis.geometries.index.KdTree; +import org.apache.sis.geometries.internal.shared.ArrayDataPoints; import org.apache.sis.geometries.internal.shared.Planar; +import org.apache.sis.geometries.internal.shared.Vertex; import org.apache.sis.geometries.mesh.MeshPrimitive; -import org.apache.sis.geometries.mesh.MeshPrimitive.Vertex; import org.apache.sis.geometries.operation.OperationException; import org.apache.sis.geometry.GeneralEnvelope; import org.apache.sis.maths.Array; @@ -317,9 +318,9 @@ public final class Delaunay { indexToEdge = new OrientedEdge[Math.toIntExact(positionsPlusRoot.getLength())]; //base triangle - final Vertex v0 = new Vertex(pointsPlusRoot, rootOffset); - final Vertex v1 = new Vertex(pointsPlusRoot, rootOffset+1); - final Vertex v2 = new Vertex(pointsPlusRoot, rootOffset+2); + final Vertex v0 = pointsPlusRoot.getVertex(rootOffset); + final Vertex v1 = pointsPlusRoot.getVertex(rootOffset+1); + final Vertex v2 = pointsPlusRoot.getVertex(rootOffset+2); final OrientedTriangle triangle = new OrientedTriangle(v0, v1, v2); triangles.add(triangle); @@ -368,7 +369,7 @@ public final class Delaunay { */ private void insertPoint(long index) throws OperationException, IllegalArgumentException { if (index < 0 || index >= rootOffset) throw new IllegalArgumentException("Index do not exist : " + index); - final Vertex vertex = new Vertex(pointsPlusRoot, index); + final Vertex vertex = pointsPlusRoot.getVertex(index); final Vector position = vertex.getPosition(); //find nearest vertex and tst all triangles using this vertex @@ -454,7 +455,7 @@ public final class Delaunay { if (endIndex < 0 || endIndex >= rootOffset) throw new IllegalArgumentException("Constraint segment index do not exist : " + endIndex); // System.out.println("e " + startIndex +" " + endIndex); - final Vertex E = new Vertex(pointsPlusRoot, endIndex); + final Vertex E = pointsPlusRoot.getVertex(endIndex); //find the starting triangle /* @@ -1016,7 +1017,7 @@ public final class Delaunay { * @throws OperationException if an algorithm exception occurs */ private OrientedEdge searchTriangle(long startIndex, long endIndex) throws OperationException { - final Vertex end = new Vertex(pointsPlusRoot, endIndex); + final Vertex end = pointsPlusRoot.getVertex(endIndex); final Vector endPosition = end.getPosition(); OrientedEdge edge = indexToEdge[Math.toIntExact(startIndex)]; diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/delaunay/OrientedEdge.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/delaunay/OrientedEdge.java index eb03c85629..610a985d02 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/delaunay/OrientedEdge.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/delaunay/OrientedEdge.java @@ -24,8 +24,9 @@ import org.apache.sis.geometries.DataPointsType; import org.apache.sis.geometries.Geometries; import org.apache.sis.geometries.curve.LineString; import org.apache.sis.geometries.internal.shared.AbstractGeometry; +import org.apache.sis.geometries.internal.shared.ArrayDataPoints; +import org.apache.sis.geometries.internal.shared.Vertex; import org.apache.sis.geometries.mesh.MeshPrimitive; -import org.apache.sis.geometries.mesh.MeshPrimitive.Vertex; import org.apache.sis.maths.Maths; import org.apache.sis.maths.Vector; @@ -67,7 +68,7 @@ public final class OrientedEdge extends AbstractGeometry implements LineString, * @param start starting vertex * @param end ending vertex */ - public OrientedEdge(MeshPrimitive.Vertex start, MeshPrimitive.Vertex end) { + public OrientedEdge(Vertex start, Vertex end) { this.structure = new Structure(start, end); } @@ -80,7 +81,7 @@ public final class OrientedEdge extends AbstractGeometry implements LineString, * @param end ending vertex * @param triangle parent triangle */ - public OrientedEdge(MeshPrimitive.Vertex start, MeshPrimitive.Vertex end, OrientedTriangle triangle) { + public OrientedEdge(Vertex start, Vertex end, OrientedTriangle triangle) { this.structure = new Structure(start, end); this.triangle = triangle; } @@ -128,7 +129,7 @@ public final class OrientedEdge extends AbstractGeometry implements LineString, /** * @return true if point is on the edge */ - public boolean isOnEdge(MeshPrimitive.Vertex pt) { + public boolean isOnEdge(Vertex pt) { assert (!structure.obsolete); return Maths.isOnLine(structure.start.getPosition(), structure.end.getPosition(), pt.getPosition()); } @@ -138,7 +139,7 @@ public final class OrientedEdge extends AbstractGeometry implements LineString, * equal 0 if point is on the line * inferior than 0 if point is on the right side */ - public double getSide(MeshPrimitive.Vertex pt) { + public double getSide(Vertex pt) { return Maths.lineSide( getStart().getPosition(), getEnd().getPosition(), @@ -171,7 +172,7 @@ public final class OrientedEdge extends AbstractGeometry implements LineString, /** * @return true if one of the two edge vertices is the same as given vertex. */ - public boolean hasPoint(MeshPrimitive.Vertex pt) { + public boolean hasPoint(Vertex pt) { assert (!structure.obsolete); return structure.start.getIndex() == pt.getIndex() || structure.end.getIndex() == pt.getIndex(); } @@ -286,10 +287,10 @@ public final class OrientedEdge extends AbstractGeometry implements LineString, private static class Structure { private boolean obsolete = false; - final MeshPrimitive.Vertex start; - final MeshPrimitive.Vertex end; + final Vertex start; + final Vertex end; - public Structure(MeshPrimitive.Vertex start, MeshPrimitive.Vertex end) { + public Structure(Vertex start, Vertex end) { this.start = start; this.end = end; } diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/delaunay/OrientedTriangle.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/delaunay/OrientedTriangle.java index 22f2eff793..360933ed69 100644 --- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/delaunay/OrientedTriangle.java +++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/operation/triangulate/delaunay/OrientedTriangle.java @@ -26,8 +26,9 @@ import org.apache.sis.geometries.DataPointsType; import org.apache.sis.geometries.Geometries; import org.apache.sis.geometries.curve.LinearRing; import org.apache.sis.geometries.internal.shared.AbstractGeometry; +import org.apache.sis.geometries.internal.shared.ArrayDataPoints; +import org.apache.sis.geometries.internal.shared.Vertex; import org.apache.sis.geometries.mesh.MeshPrimitive; -import org.apache.sis.geometries.mesh.MeshPrimitive.Vertex; import org.apache.sis.geometries.operation.OperationException; import org.apache.sis.geometries.surface.Triangle; import org.apache.sis.maths.Vector; @@ -128,7 +129,7 @@ public final class OrientedTriangle extends AbstractGeometry implements Triangle /** * Returns the opposite vertex of given edge. */ - MeshPrimitive.Vertex oppositePoint(OrientedEdge edge) { + Vertex oppositePoint(OrientedEdge edge) { assert (!obsolete); if (edge == ab) { return c; 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 618685b35c..2f43941aa3 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 @@ -23,6 +23,7 @@ import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.apache.sis.geometries.Geometries; import org.apache.sis.geometries.Point; import org.apache.sis.geometries.curve.LineString; +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; @@ -575,7 +576,7 @@ public class PrimitiveVisitorTest { } @Override - protected void visit(MeshPrimitive.Vertex vertex) { + protected void visit(Vertex vertex) { assertEquals(expected.remove(0), vertex.toString()); } }; diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/triangulate/delaunay/OrientedEdgeTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/triangulate/delaunay/OrientedEdgeTest.java index af080cf24a..0ff36599c9 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/triangulate/delaunay/OrientedEdgeTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/geometries/operation/triangulate/delaunay/OrientedEdgeTest.java @@ -17,9 +17,9 @@ package org.apache.sis.geometries.operation.triangulate.delaunay; import java.util.Iterator; +import org.apache.sis.geometries.internal.shared.Vertex; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.apache.sis.geometries.mesh.MeshPrimitive; -import org.apache.sis.geometries.mesh.MeshPrimitive.Vertex; import org.apache.sis.maths.NDArrays; import org.apache.sis.maths.Array; import org.apache.sis.referencing.CommonCRS; 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 e17886dc11..f64ebb7d0f 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 @@ -283,9 +283,6 @@ public abstract class AbstractVectorTest { //test equals itself assertEquals(tuple, tuple); - //test equals a copy - assertEquals(tuple, tuple.copy()); - //test a equals a newly created tuple assertFalse(zero.equals(tuple)); assertEquals(tuple, vector(zero, sequence(dim, 1))); @@ -363,9 +360,6 @@ public abstract class AbstractVectorTest { //test get assertEquals(value, vector.get(i), 0.0); - //test copy - assertEquals(value, vector.copy().get(i), 0.0); - //test array assertEquals(value, vector.toArrayDouble()[i], 0.0); } @@ -399,7 +393,7 @@ public abstract class AbstractVectorTest { final Vector<?> second = Vectors.create(values, DataType.DOUBLE); final double expected = Vectors.dot(vector.toArrayDouble(), second.toArrayDouble()); assertEquals(expected, vector.dot(second), TOLERANCE); - assertThrows(IllegalArgumentException.class, () -> vector.dot(Vectors.createDouble(vector.getDimension() + 1))); + assertThrows(IllegalArgumentException.class, () -> vector.dot(Vector.of(new double[vector.getDimension() + 1]))); } /** @@ -423,7 +417,7 @@ public abstract class AbstractVectorTest { assertEquals(Vectors.lengthSquare(diff), vector.distanceSquare(second), TOLERANCE); assertEquals(Vectors.length(diff), vector.distance(second), TOLERANCE); assertEquals(0, vector.distance(vector), TOLERANCE); - assertThrows(IllegalArgumentException.class, () -> vector.distance(Vectors.createDouble(vector.getDimension() + 1))); + assertThrows(IllegalArgumentException.class, () -> vector.distance(Vector.of(new double[vector.getDimension() + 1]))); } /** @@ -504,7 +498,7 @@ public abstract class AbstractVectorTest { final Vector<?> vector = vector(tuple, v); final Vector<?> second = Vectors.create(s, DataType.DOUBLE); final Vector<?> unit = Vectors.create(u, DataType.DOUBLE); - final Vector<?> original = vector.copy(); + final Vector<?> original = vector; final double[] perpendicular = v.clone(); perpendicular[0] = 0; @@ -531,19 +525,6 @@ public abstract class AbstractVectorTest { } } - /* - * Same operations through the default implementations of Vector. - * The result is a new vector of the same data type. - */ - final Vector<?> unmodifiable = Vectors.unmodifiable(vector); - Vector<?> result = unmodifiable.add(second); - assertEquals(vector.getClass(), result.getClass()); - assertArrayEquals(Vectors.add(v, s), result.toArrayDouble(), TOLERANCE); - result = unmodifiable.lerp(second, 0.5); - assertArrayEquals(Vectors.lerp(v, s, 0.5, null), result.toArrayDouble(), TOLERANCE); - result = unmodifiable.transform(MathTransforms.scale(factors)); - assertArrayEquals(Vectors.scale(v, 3), result.toArrayDouble(), TOLERANCE); - assertEquals(original, vector, "Vector must not be modified"); } private static void assertNewVector(Vector<?> vector, Vector<?> original, Vector<?> result, double[] expected, double tolerance) { diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/NDRangeTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/NDRangeTest.java index fe9bb7eef0..30be179252 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/NDRangeTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/NDRangeTest.java @@ -104,7 +104,7 @@ public class NDRangeTest { @Test public void testInvalid() { - assertThrows(MismatchedDimensionException.class, () -> new NDRange(vector(1, 2, 3), Vectors.createDouble(2))); + assertThrows(MismatchedDimensionException.class, () -> new NDRange(vector(1, 2, 3), Vector.of(0.0,0.0))); assertThrows(IllegalArgumentException.class, () -> new NDRange(vector(5, 2, 3), vector(4, 6, 3))); assertThrows(MismatchedDimensionException.class, () -> new NDRange(CommonCRS.WGS84.geographic(), vector(1, 2, 3), vector(4, 6, 3))); @@ -132,9 +132,9 @@ public class NDRangeTest { range.add(vector(Double.NaN, 8, 5)); assertArrayEquals(new double[] {4, 8, 10}, range.getUpper().toArrayDouble()); // The same with a direct position. - range.add(Vectors.asDirectPostion(vector(-1, 2, 3))); + range.add(vector(-1, 2, 3).asDirectPostion(null)); assertEquals(-1, range.getMinimum(0)); - assertThrows(MismatchedDimensionException.class, () -> range.add(Vectors.createDouble(2))); + assertThrows(MismatchedDimensionException.class, () -> range.add(Vector.of(0.0, 0.0))); } /** @@ -177,8 +177,8 @@ public class NDRangeTest { assertFalse(range.contains(vector(0, 3, 3))); assertFalse(range.contains(vector(2, 3, 4))); assertFalse(range.contains(vector(Double.NaN, 3, 3))); - assertTrue (range.contains(Vectors.asDirectPostion(vector(4, 2, 3)))); - assertThrows(MismatchedDimensionException.class, () -> range.contains(Vectors.createDouble(2))); + assertTrue (range.contains(vector(4, 2, 3).asDirectPostion(null))); + assertThrows(MismatchedDimensionException.class, () -> range.contains(Vector.of(0.0, 0.0))); } /** 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 b4c9f62752..4efc946d4d 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 @@ -94,7 +94,7 @@ public class Vector3DTest { final double[] latitudes = {-Math.PI / 3, -Math.PI / 6, 0, Math.PI / 6, Math.PI / 3}; final double[] longitudes = {-3 * Math.PI / 4, -Math.PI / 3, 0, Math.PI / 3, 3 * Math.PI / 4}; - Vector3D.Double v = new Vector3D.Double(); + Vector3D.Double v; for (double lat : latitudes) { for (double lon : longitudes) { v = Vector3D.fromLatLon(lat, lon); diff --git a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorTest.java b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorTest.java index e92df9cc94..1ab69c8647 100644 --- a/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorTest.java +++ b/incubator/src/org.apache.sis.geometry/test/org/apache/sis/maths/VectorTest.java @@ -89,14 +89,14 @@ public class VectorTest { final Vector3D.Double v = Vector.of(1e8, 1.0, 1e8); assertEquals(1.0, u.dotAccurate(v), 0.0); assertEquals(1.0, Vector.of(1e8, 1.0, -1e8, 0.0, 0.0).dotAccurate(Vector.of(1e8, 1.0, 1e8, 0.0, 0.0)), 0.0); - assertEquals(1.0, Vectors.unmodifiable(u).dotAccurate(v), 0.0); + assertEquals(1.0, u.dotAccurate(v), 0.0); assertEquals(0.0, u.dot(v), 0.0, "plain arithmetic loses all digits"); //cross product of nearly parallel vectors final Vector3D.Double a = Vector.of(0.0, 101394113.74178699, 101394113.80164877); final Vector3D.Double b = Vector.of(0.0, 101394123.88119836, 101394123.94106016); assertEquals(0.9039268278985468, a.crossAccurate(b).x, 1e-15); - assertEquals(0.9039268278985468, Vectors.unmodifiable(a).crossAccurate(b).get(0), 1e-15); + assertEquals(0.9039268278985468, a.crossAccurate(b).get(0), 1e-15); assertEquals(0.0, a.cross(b).x, 0.0, "plain arithmetic loses all digits"); } @@ -115,7 +115,7 @@ public class VectorTest { assertEquals(p, p.lerpAccurate(p, 0.3)); //same with the default implementation and with VectorND - assertEquals(q, Vectors.unmodifiable(p).lerp(q, 1)); + assertEquals(q, p.lerp(q, 1)); final Vector<?> nd = Vector.of(0.1, -7.3, 1e-3, 4.0, 5.0); assertEquals(nd, nd.lerp(nd, 0.3)); assertArrayEquals(new double[] {0.5, 0.5, 0.5, 4.5, 5.0}, 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 4242b8b655..230933a754 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 @@ -31,10 +31,10 @@ public class VectorXbTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { switch (dim) { - case 1 : return new Vector1D.Byte(); - case 2 : return new Vector2D.Byte(); - case 3 : return new Vector3D.Byte(); - case 4 : return new Vector4D.Byte(); + 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); } } 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 dc1af25438..bfbbed1336 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 @@ -31,10 +31,10 @@ public class VectorXdTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { switch (dim) { - case 1 : return new Vector1D.Double(); - case 2 : return new Vector2D.Double(); - case 3 : return new Vector3D.Double(); - case 4 : return new Vector4D.Double(); + 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); } } 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 aa2a8c33b3..f55c5cf039 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 @@ -31,10 +31,10 @@ public class VectorXfTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { switch (dim) { - case 1 : return new Vector1D.Float(); - case 2 : return new Vector2D.Float(); - case 3 : return new Vector3D.Float(); - case 4 : return new Vector4D.Float(); + 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); } } 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 106e086712..118d65192a 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 @@ -31,10 +31,10 @@ public class VectorXiTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { switch (dim) { - case 1 : return new Vector1D.Int(); - case 2 : return new Vector2D.Int(); - case 3 : return new Vector3D.Int(); - case 4 : return new Vector4D.Int(); + 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); } } 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 14ab8f55c9..a8ed697698 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 @@ -31,10 +31,10 @@ public class VectorXlTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { switch (dim) { - case 1 : return new Vector1D.Long(); - case 2 : return new Vector2D.Long(); - case 3 : return new Vector3D.Long(); - case 4 : return new Vector4D.Long(); + 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); } } 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 9637d6e064..b509c19cba 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 @@ -31,10 +31,10 @@ public class VectorXsTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { switch (dim) { - case 1 : return new Vector1D.Short(); - case 2 : return new Vector2D.Short(); - case 3 : return new Vector3D.Short(); - case 4 : return new Vector4D.Short(); + 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); } } 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 dbf222236a..dbef25f440 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 @@ -31,10 +31,10 @@ public class VectorXubTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { switch (dim) { - case 1 : return new Vector1D.UByte(); - case 2 : return new Vector2D.UByte(); - case 3 : return new Vector3D.UByte(); - case 4 : return new Vector4D.UByte(); + 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); } } 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 fc22176881..b7ebda4294 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 @@ -31,10 +31,10 @@ public class VectorXuiTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { switch (dim) { - case 1 : return new Vector1D.UInt(); - case 2 : return new Vector2D.UInt(); - case 3 : return new Vector3D.UInt(); - case 4 : return new Vector4D.UInt(); + 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); } } 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 0abcc18d9d..6bf3bbbf1f 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 @@ -31,10 +31,10 @@ public class VectorXusTest extends AbstractVectorTest{ @Override protected Vector create(int dim) { switch (dim) { - case 1 : return new Vector1D.UShort(); - case 2 : return new Vector2D.UShort(); - case 3 : return new Vector3D.UShort(); - case 4 : return new Vector4D.UShort(); + 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); } }
