You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2022/09/21 16:03:11 UTC
[sis] 02/02: Rename `GridGeometry.translate(…)` as `shiftGrid(…)` for making clearer that this method changes grid coordinates without changing real world coordinates.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 32b875d621abb41775ca7a200bb087c175402b7c
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Sep 21 16:26:53 2022 +0200
Rename `GridGeometry.translate(…)` as `shiftGrid(…)` for making clearer that
this method changes grid coordinates without changing real world coordinates.
---
.../java/org/apache/sis/gui/map/StatusBar.java | 2 +-
.../sis/coverage/grid/GridCoverageProcessor.java | 8 ++++----
.../org/apache/sis/coverage/grid/GridExtent.java | 2 +-
.../org/apache/sis/coverage/grid/GridGeometry.java | 24 +++++++++++++++++++---
.../sis/coverage/grid/TranslatedGridCoverage.java | 2 +-
.../internal/coverage/j2d/DeferredProperty.java | 2 +-
.../apache/sis/coverage/grid/GridGeometryTest.java | 6 +++---
.../coverage/grid/ResampledGridCoverageTest.java | 2 +-
.../coverage/grid/TranslatedGridCoverageTest.java | 2 +-
.../sis/internal/storage/image/WritableStore.java | 2 +-
10 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/StatusBar.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/StatusBar.java
index 33049342e8..6823ef709c 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/StatusBar.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/StatusBar.java
@@ -728,7 +728,7 @@ public class StatusBar extends Widget implements EventHandler<MouseEvent> {
offset[i] = Math.negateExact(sliceExtent.getLow(i));
}
sliceExtent = sliceExtent.translate(offset);
- geometry = geometry.translate(offset); // Does not change the "real world" envelope.
+ geometry = geometry.shiftGrid(offset); // Does not change the "real world" envelope.
try {
geometry = geometry.relocate(sliceExtent); // Changes the "real world" envelope.
} catch (TransformException e) {
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageProcessor.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageProcessor.java
index 67a458a3d0..db6cc2652b 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageProcessor.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageProcessor.java
@@ -183,7 +183,7 @@ public class GridCoverageProcessor implements Cloneable {
* <div class="note"><b>Example:</b>
* if the {@link #resample(GridCoverage, GridGeometry) resample(…)} method is invoked with parameter values
* that cause the resampling to be a translation of the grid by an integer amount of cells, then by default
- * {@link GridCoverageProcessor} will use the {@link #translateGrid(GridCoverage, long...) translateGrid(…)}
+ * {@link GridCoverageProcessor} will use the {@link #shiftGrid(GridCoverage, long[]) shiftGrid(…)}
* algorithm instead. This option can be cleared for forcing a full resampling operation in all cases.</div>
*/
REPLACE_OPERATION,
@@ -345,7 +345,7 @@ public class GridCoverageProcessor implements Cloneable {
}
/**
- * Returns a coverage with a grid translated by the given amount of cells compared to the source.
+ * Translates grid coordinates by the given amount of cells without changing "real world" coordinates.
* The translated grid has the same {@linkplain GridExtent#getSize(int) size} than the source,
* i.e. both low and high grid coordinates are displaced by the same amount of cells.
* The "grid to CRS" transforms are adjusted accordingly in order to map to the same
@@ -371,11 +371,11 @@ public class GridCoverageProcessor implements Cloneable {
* @throws ArithmeticException if the translation results in coordinates that overflow 64-bits integer.
*
* @see GridExtent#translate(long...)
- * @see GridGeometry#translate(long...)
+ * @see GridGeometry#shiftGrid(long...)
*
* @since 1.3
*/
- public GridCoverage translateGrid(final GridCoverage source, long... translation) {
+ public GridCoverage shiftGrid(final GridCoverage source, long... translation) {
ArgumentChecks.ensureNonNull("source", source);
ArgumentChecks.ensureNonNull("translation", translation);
final boolean allowSourceReplacement;
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
index 7e75053252..9d0f41cfba 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
@@ -1697,7 +1697,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable
* @throws ArithmeticException if the translation results in coordinates that overflow 64-bits integer.
*
* @see #startsAtZero()
- * @see GridGeometry#translate(long...)
+ * @see GridGeometry#shiftGrid(long...)
*
* @since 1.1
*/
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
index 5bc761668d..7261071b29 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
@@ -233,6 +233,7 @@ public class GridGeometry implements LenientComparable, Serializable {
* @see #getGridToCRS(PixelInCell)
* @see PixelInCell#CELL_CENTER
*/
+ @SuppressWarnings("serial") // Not statically typed as Serializable.
protected final MathTransform gridToCRS;
/**
@@ -242,6 +243,7 @@ public class GridGeometry implements LenientComparable, Serializable {
* @serial This field is serialized because it may be a value specified explicitly at construction time,
* in which case it can be more accurate than a computed value.
*/
+ @SuppressWarnings("serial") // Not statically typed as Serializable.
final MathTransform cornerToCRS;
/**
@@ -1444,7 +1446,7 @@ public class GridGeometry implements LenientComparable, Serializable {
}
/**
- * Returns a grid geometry translated by the given amount of cells compared to this grid.
+ * Translates grid coordinates by the given amount of cells without changing "real world" coordinates.
* The returned grid has the same {@linkplain GridExtent#getSize(int) size} than this grid,
* i.e. both low and high grid coordinates are displaced by the same amount of cells.
* The "grid to CRS" transforms are adjusted accordingly in order to map to the same
@@ -1463,9 +1465,9 @@ public class GridGeometry implements LenientComparable, Serializable {
*
* @see GridExtent#translate(long...)
*
- * @since 1.1
+ * @since 1.3
*/
- public GridGeometry translate(final long... translation) {
+ public GridGeometry shiftGrid(final long... translation) {
ArgumentChecks.ensureNonNull("translation", translation);
GridExtent newExtent = extent;
if (newExtent != null) {
@@ -1489,6 +1491,22 @@ public class GridGeometry implements LenientComparable, Serializable {
return new GridGeometry(newExtent, t1, t2, envelope, resolution, nonLinears);
}
+ /**
+ * Returns a grid geometry translated by the given amount of cells compared to this grid.
+ *
+ * @param translation translation to apply on each grid axis in order.
+ * @return a grid geometry whose coordinates and the "grid to CRS" transforms have been translated by given amounts.
+ *
+ * @since 1.1
+ *
+ * @deprecated Renamed {@link #shiftGrid(long...)} for making clearer that this method changes
+ * grid coordinates without changing "real world" coordinates.
+ */
+ @Deprecated
+ public GridGeometry translate(final long... translation) {
+ return shiftGrid(translation);
+ }
+
/**
* Returns a grid geometry with the given grid extent, which implies a new "real world" computation.
* The "grid to CRS" transforms and the resolution stay the same than this {@code GridGeometry}.
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/TranslatedGridCoverage.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/TranslatedGridCoverage.java
index 51cd5969bf..577c887ddc 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/TranslatedGridCoverage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/TranslatedGridCoverage.java
@@ -85,7 +85,7 @@ final class TranslatedGridCoverage extends DerivedGridCoverage {
}
final GridGeometry gridGeometry = source.getGridGeometry();
if (domain == null) {
- domain = gridGeometry.translate(translation);
+ domain = gridGeometry.shiftGrid(translation);
} else if (!domain.extent.isSameSize(gridGeometry.extent)) {
return null;
}
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/DeferredProperty.java b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/DeferredProperty.java
index 18743cdb45..25f9bcb55f 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/DeferredProperty.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/DeferredProperty.java
@@ -121,7 +121,7 @@ public final class DeferredProperty {
@Override
public GridGeometry apply(final RenderedImage image) {
final GridExtent extent = grid.getExtent();
- return grid.selectDimensions(dimX, dimY).translate(
+ return grid.selectDimensions(dimX, dimY).shiftGrid(
Math.subtractExact(image.getMinX(), extent.getLow(dimX)),
Math.subtractExact(image.getMinY(), extent.getLow(dimY)));
}
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
index 86fcf19682..5a4b41c690 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
@@ -500,10 +500,10 @@ public final strictfp class GridGeometryTest extends TestCase {
}
/**
- * Tests {@link GridGeometry#translate(long...)}.
+ * Tests {@link GridGeometry#shiftGrid(long[])}.
*/
@Test
- public void testTranslate() {
+ public void testShiftGrid() {
GridGeometry grid = new GridGeometry(
new GridExtent(17, 10),
PixelInCell.CELL_CENTER,
@@ -516,7 +516,7 @@ public final strictfp class GridGeometryTest extends TestCase {
* The "real world" envelope should be unchanged by grid translation.
*/
final Envelope envelope = grid.getEnvelope();
- grid = grid.translate(12, 15);
+ grid = grid.shiftGrid(12, 15);
assertExtentEquals(new long[] {12, 15}, new long[] {12 + 16, 15 + 9}, grid.getExtent());
assertEquals(envelope, grid.getEnvelope());
}
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/ResampledGridCoverageTest.java b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/ResampledGridCoverageTest.java
index 98f5783b5e..0dc02ef9bf 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/ResampledGridCoverageTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/ResampledGridCoverageTest.java
@@ -303,7 +303,7 @@ public final strictfp class ResampledGridCoverageTest extends TestCase {
final GridCoverageProcessor processor = new GridCoverageProcessor(); // With all optimization enabled.
final GridCoverage source = createCoverage2D();
final GridGeometry sourceGG = source.getGridGeometry();
- final GridGeometry targetGG = sourceGG.translate(-10, 15);
+ final GridGeometry targetGG = sourceGG.shiftGrid(-10, 15);
final GridCoverage target = processor.resample(source, targetGG);
assertInstanceOf("Expected fast path.", TranslatedGridCoverage.class, target);
assertSame(targetGG, target.getGridGeometry());
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/TranslatedGridCoverageTest.java b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/TranslatedGridCoverageTest.java
index 7fcb43fd01..ea1216eb26 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/TranslatedGridCoverageTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/TranslatedGridCoverageTest.java
@@ -72,7 +72,7 @@ public final strictfp class TranslatedGridCoverageTest extends TestCase {
public void testUsingProcessor() {
final GridCoverageProcessor processor = new GridCoverageProcessor();
final GridCoverage source = createCoverage();
- final GridCoverage target = processor.translateGrid(source, 30, -5);
+ final GridCoverage target = processor.shiftGrid(source, 30, -5);
assertExtentStarts(source.getGridGeometry().getExtent(), -20, -10);
assertExtentStarts(target.getGridGeometry().getExtent(), 10, -15);
/*
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/WritableStore.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/WritableStore.java
index cb7956c0eb..3fe15bd0fa 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/WritableStore.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/WritableStore.java
@@ -216,7 +216,7 @@ class WritableStore extends WorldFileStore {
for (int i=0; i<translation.length; i++) {
translation[i] = Math.negateExact(extent.getLow(i));
}
- gg = gg.translate(translation);
+ gg = gg.shiftGrid(translation);
/*
* If the data store already contains a coverage, then the given grid geometry
* must be identical to the existing one, in which case there is nothing to do.