Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement PointsList#copy() and JTSPoints#copy() #1353

Merged
merged 3 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ public Reference( ReferenceResolver resolver, String uri, String baseURL ) {
this.baseURL = baseURL;
}

/**
* Returns the resolver.
*
* @return the resolver, never <code>null</code>
*/
public ReferenceResolver getResolver() {
return resolver;
}

/**
* Returns the URI of the object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
----------------------------------------------------------------------------*/
package org.deegree.geometry.primitive;

import java.util.List;

import org.deegree.commons.tom.gml.property.Property;

/**
* 0-dimensional primitive.
*
Expand All @@ -52,35 +48,35 @@ public interface Point extends GeometricPrimitive {

/**
* Must always return {@link GeometricPrimitive.PrimitiveType#Point}.
*
*
* @return {@link GeometricPrimitive.PrimitiveType#Point}
*/
public PrimitiveType getPrimitiveType();

/**
* Returns the value of the first ordinate.
*
*
* @return value of the first ordinate
*/
public double get0();

/**
* Returns the value of the second ordinate.
*
*
* @return value of the second ordinate, or <code>Double.NAN</code> if the point only has one dimension
*/
public double get1();

/**
* Returns the value of the third ordinate.
*
*
* @return value of the third ordinate, or <code>Double.NAN</code> if the point only has one or two dimensions
*/
public double get2();

/**
* Returns the value of the specified ordinate.
*
*
* @param dimension
* ordinate to be returned (first dimension=0)
* @return ordinate value of the passed dimension, or <code>Double.NAN</code> if <code>dimension</code> is greater
Expand All @@ -90,8 +86,13 @@ public interface Point extends GeometricPrimitive {

/**
* Returns all ordinates.
*
*
* @return all ordinates, the length of the array is equal to the number of dimensions
*/
public double[] getAsArray();

/**
* @return a copy of the point
*/
Point copy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@

import org.deegree.commons.tom.gml.GMLReferenceResolver;
import org.deegree.geometry.primitive.Point;
import org.deegree.geometry.standard.primitive.DefaultPoint;

import java.util.Arrays;

/**
* The <code></code> class TODO add class documentation here.
Expand Down Expand Up @@ -92,4 +95,10 @@ public double get1() {
public double get2() {
return getReferencedObject().get2();
}

@Override
public Point copy() {
return new PointReference( (GMLReferenceResolver) getResolver(), getURI(), getBaseURL() );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ public Coordinate[] toCoordinateArray() {

@Override
public Object clone() {
throw new UnsupportedOperationException();
return copy();
}

@Override
public CoordinateSequence copy() {
throw new UnsupportedOperationException();
return new JTSPoints( crs, seq.copy() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
package org.deegree.geometry.standard.points;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import org.deegree.commons.tom.Reference;
import org.deegree.geometry.points.Points;
Expand Down Expand Up @@ -203,12 +206,13 @@ public Coordinate[] toCoordinateArray() {

@Override
public Object clone() {
return new PointsList( new ArrayList<Point>( points ) );
return copy();
}

@Override
public CoordinateSequence copy() {
throw new UnsupportedOperationException();
List<Point> copiedPoints = points.stream().map( point -> point.copy() ).collect( Collectors.toList() );
return new PointsList( copiedPoints );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

import org.locationtech.jts.geom.Coordinate;

import java.util.Arrays;

/**
* Default implementation of {@link Point}.
*
Expand Down Expand Up @@ -115,6 +117,11 @@ public double get2() {
return Double.NaN;
}

@Override
public Point copy() {
return new DefaultPoint( id, crs, pm, Arrays.copyOf( coordinates, coordinates.length ) );
}

@Override
public boolean equals( Geometry geometry ) {
if ( !( geometry instanceof Point ) ) {
Expand Down