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 b03c4e065bb70e444ea25bae46a7ab362ac89d68 Author: Martin Desruisseaux <[email protected]> AuthorDate: Sun Jan 26 20:36:26 2020 +0100 Fix an error in check for y bounds when RenderedImage.getMinY() is not zero. Numbers shown in header column and header row should starts at RenderedImage.getMinX() and getMinY(). --- .../java/org/apache/sis/gui/coverage/GridRow.java | 16 +++++-------- .../java/org/apache/sis/gui/coverage/GridView.java | 28 +++++++--------------- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridRow.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridRow.java index 0c6baaf..56b8bf2 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridRow.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridRow.java @@ -35,6 +35,10 @@ import javafx.scene.text.FontWeight; * for reusing cells. A relatively small amount of {@code GridRow} instances should be created * even if the image contains millions of rows.</p> * + * <p>The {@code GridRow} index value is zero-based. This is not necessarily the <var>y</var> coordinate + * in the image since {@link RenderedImage} coordinate system do not necessarily starts at zero. + * This value may be outside image bounds, in which case this {@code GridRow} should be rendered as empty. + * * @author Martin Desruisseaux (Geomatys) * @version 1.1 * @since 1.1 @@ -47,16 +51,9 @@ final class GridRow extends IndexedCell<Void> { final GridView view; /** - * The arbitrary-based <var>y</var> coordinate in the image. This is not necessarily the {@code row} - * index in the table since {@link RenderedImage} coordinate system do not necessarily starts at zero. - * This value may be outside image bounds, in which case this {@code GridRow} should be rendered as empty. - */ - private int y; - - /** * The <var>y</var> coordinate of the tile in the {@link RenderedImage}. * Note that those coordinates do not necessarily start at zero; negative values may be valid. - * This value is computed from {@link #y} value and cached for efficiency. + * This value is computed from {@link #getIndex()} value and cached for efficiency. */ private int tileY; @@ -80,7 +77,6 @@ final class GridRow extends IndexedCell<Void> { @Override public void updateIndex(final int row) { super.updateIndex(row); - y = view.toImageY(row); tileY = view.toTileY(row); final Skin<?> skin = getSkin(); if (skin != null) { @@ -97,7 +93,7 @@ final class GridRow extends IndexedCell<Void> { * @return the sample value in the specified column, or {@code null} if not yet available. */ final String getSampleValue(final int column) { - return view.getSampleValue(y, tileY, column); + return view.getSampleValue(tileY, getIndex(), column); } /** diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java index 3e330fe..550bb17 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java @@ -409,18 +409,6 @@ public class GridView extends Control { } /** - * Converts a grid row index to image <var>y</var> coordinate. Those values may differ - * because the image coordinate system does not necessarily starts at zero. - * - * @param row zero-based index of a row in this grid view. - * @return image <var>y</var> coordinate (may be outside image bounds). - * @throws ArithmeticException if image row for the given index is too large. - */ - final int toImageY(final int row) { - return Math.addExact(row, minY); - } - - /** * Converts a grid row index to tile index. Note that those {@link RenderedImage} * tile coordinates do not necessarily start at 0; negative values may be valid. * @@ -435,11 +423,10 @@ public class GridView extends Control { * time this method is invoked, then the tile will loaded in a background thread and the grid view will * be refreshed when the tile become available. * - * <p>The {@code y} parameter is computed by {@link #toImageY(int)} and the {@code tileY} parameter - * is computed by {@link #toTileY(int)}. Those values are stored in {@link GridRow}.</p> + * <p>The {@code tileY} parameter is computed by {@link #toTileY(int)} and stored in {@link GridRow}.</p> * - * @param y arbitrary-based <var>y</var> coordinate in the image (may differ from table {@code row}). * @param tileY arbitrary-based <var>y</var> coordinate of the tile. + * @param row zero-based <var>y</var> coordinate of sample to get (may differ from image coordinate Y). * @param column zero-based <var>x</var> coordinate of sample to get (may differ from image coordinate X). * @return the sample value in the specified column, or {@code null} if unknown (because the loading process * is still under progress), or the empty string ({@code ""}) if out of bounds. @@ -447,8 +434,8 @@ public class GridView extends Control { * * @see GridRow#getSampleValue(int) */ - final String getSampleValue(final int y, final int tileY, final int column) { - if (y < 0 || y >= height || column < 0 || column >= width) { + final String getSampleValue(final int tileY, final int row, final int column) { + if (row < 0 || row >= height || column < 0 || column >= width) { return OUT_OF_BOUNDS; } /* @@ -476,6 +463,7 @@ public class GridView extends Control { * It may happen in particular with fill values. */ final int x = Math.addExact(column, minX); + final int y = Math.addExact(row, minY); final int b = getBand(); buffer.setLength(0); if (dataTypeisInteger) { @@ -504,11 +492,11 @@ public class GridView extends Control { */ final String formatHeaderValue(final int index, final boolean vertical) { if (index >= 0 && index < (vertical ? height : width)) { + final long value = index + (long) (vertical ? minY : minX); buffer.setLength(0); - return headerFormat.format(index, buffer, formatField).toString(); - } else { - return OUT_OF_BOUNDS; + return headerFormat.format(value, buffer, formatField).toString(); } + return OUT_OF_BOUNDS; } /**
