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
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new ceca796 Fix initial image display, which was sometime partially
outside the window. More accurate detection of drag gestures.
ceca796 is described below
commit ceca796a7474d2790a5c50136ffb01b51afb1888
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Sat May 16 00:43:06 2020 +0200
Fix initial image display, which was sometime partially outside the window.
More accurate detection of drag gestures.
---
.../java/org/apache/sis/gui/map/MapCanvas.java | 25 +++++++++++-----
.../sis/referencing/operation/matrix/Matrices.java | 35 +++++++++++++---------
2 files changed, 38 insertions(+), 22 deletions(-)
diff --git
a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java
index 11c7799..1d26b16 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java
@@ -226,6 +226,13 @@ public abstract class MapCanvas extends PlanarCanvas {
private double xPanStart, yPanStart;
/**
+ * {@code true} if a drag even is in progress.
+ *
+ * @see #onDrag(MouseEvent)
+ */
+ private boolean isDragging;
+
+ /**
* Whether a rendering is in progress. This property is set to {@code
true} when {@code MapCanvas}
* is about to start a background thread for performing a rendering, and
is reset to {@code false}
* after the {@code MapCanvas} has been updated with new rendering result.
@@ -304,18 +311,21 @@ public abstract class MapCanvas extends PlanarCanvas {
final double x = event.getX();
final double y = event.getY();
final EventType<? extends MouseEvent> type = event.getEventType();
- if (type == MouseEvent.MOUSE_PRESSED) {
+ if (type == MouseEvent.MOUSE_PRESSED && event.isPrimaryButtonDown()) {
floatingPane.setCursor(Cursor.CLOSED_HAND);
floatingPane.requestFocus();
- xPanStart = x;
- yPanStart = y;
- } else {
+ isDragging = true;
+ xPanStart = x;
+ yPanStart = y;
+ event.consume();
+ } else if (isDragging) {
if (type != MouseEvent.MOUSE_DRAGGED) {
floatingPane.setCursor(renderingInProgress != null ?
Cursor.WAIT : Cursor.CROSSHAIR);
+ isDragging = false;
}
applyTranslation(x - xPanStart, y - yPanStart, type ==
MouseEvent.MOUSE_RELEASED);
+ event.consume();
}
- event.consume();
}
/**
@@ -686,7 +696,7 @@ public abstract class MapCanvas extends PlanarCanvas {
CoordinateReferenceSystem crs;
if (objectiveBounds != null) {
final MatrixSIS m =
Matrices.createTransform(objectiveBounds, target);
- Matrices.forceUniformScale(m, 0, new double[]
{target.width / 2, target.height / 2});
+ Matrices.forceUniformScale(m, 0, new double[]
{target.getCenterX(), target.getCenterY()});
crsToDisplay = MathTransforms.linear(m);
crs = objectiveBounds.getCoordinateReferenceSystem();
if (crs == null) {
@@ -707,10 +717,9 @@ public abstract class MapCanvas extends PlanarCanvas {
}
/*
* If a temporary zoom, rotation or translation has been applied using
JavaFX transform API,
- * replaced that temporary transform by a "permanent" adjustment of
the `objectiveToDisplay`
+ * replace that temporary transform by a "permanent" adjustment of the
`objectiveToDisplay`
* transform. It allows SIS to get new data for the new visible area
and resolution.
*/
- assert changeInProgress.isIdentity() : changeInProgress;
changeInProgress.setToTransform(transform);
transformOnNewImage.setToIdentity();
isRendering.set(true);
diff --git
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
index 50dcff0..57ff192 100644
---
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
+++
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
@@ -830,17 +830,17 @@ public final class Matrices extends Static {
* directly the scale factors on the matrix diagonal and {@code
selector=0} sets all those scales to the smallest
* value while {@code selector=1} sets all those scales to the largest
value (ignoring sign).
*
- * <p>Translation terms can be compensated for scale changes if the {@code
shift} argument is non-null.
- * The {@code shift} values should be proportional to {@linkplain
Envelope#getSpan(int) envelope spans}.
- * For example if the matrix is for transforming coordinates to a screen
device, then:</p>
+ * <p>Translation terms can be compensated for scale changes if the {@code
anchor} argument is non-null.
+ * The anchor gives coordinates of the point to keep at fixed position in
target coordinates.
+ * For example if the matrix is for transforming coordinates to a screen
device
+ * and {@code target} is an {@link Envelope} with device position and size
in pixels, then:</p>
*
* <ul>
- * <li>{@code shift[i] = 0} will keep translation term unchanged in the
dimension <var>i</var>.
- * For rendering on screen, it means that the image will stay on the
left border (<var>i</var> = 0)
+ * <li>{@code anchor[i] = target.getMinimum(i)} keeps the image on the
left border (<var>i</var> = 0)
* or upper border (<var>i</var> = 1).</li>
- * <li>{@code shift[i] = span} where {@code span} is the window width
(<var>i</var> = 0) or height
- * (<var>i</var> = 1) will translate the image to the right border
or to the bottom border respectively.</li>
- * <li>{@code shift[i] = span / 2} where {@code span} is as above will
translate the image to the window center.</li>
+ * <li>{@code anchor[i] = target.getMaximum(i)} translates the image to
the right border (<var>i</var> = 0)
+ * or to the bottom border (<var>i</var> = 1).</li>
+ * <li>{@code anchor[i] = target.getMedian(i)} translates the image to
the device center.</li>
* <li>Any intermediate values are allowed.</li>
* </ul>
*
@@ -848,17 +848,17 @@ public final class Matrices extends Static {
* @param selector a value between 0 for smallest scale magnitude and 1
for largest scale magnitude (inclusive).
* Values outside [0 … 1] range are authorized, but will
result in scale factors outside the
* range of current scale factors in the given matrix.
- * @param shift compensation for the translation terms, or {@code
null} if none.
+ * @param anchor point to keep at fixed position in target
coordinates, or {@code null} if none.
* @return {@code true} if the given matrix changed as a result of this
method call.
*
* @since 1.1
*/
- public static boolean forceUniformScale(final Matrix matrix, final double
selector, final double[] shift) {
+ public static boolean forceUniformScale(final Matrix matrix, final double
selector, final double[] anchor) {
ArgumentChecks.ensureNonNull("matrix", matrix);
ArgumentChecks.ensureFinite("selector", selector);
final int srcDim = matrix.getNumCol() - 1;
final int tgtDim = matrix.getNumRow() - 1;
- ArgumentChecks.ensureDimensionMatches("shift", tgtDim, shift);
+ ArgumentChecks.ensureDimensionMatches("anchor", tgtDim, anchor);
final double[] row = new double[srcDim];
final double[] mgn = new double[tgtDim];
double min = Double.POSITIVE_INFINITY;
@@ -872,6 +872,10 @@ public final class Matrices extends Static {
if (m > max) max = m;
mgn[j] = m;
}
+ /*
+ * Found the magnitude of each rows together with minimum and maximum
magnitude values.
+ * The `scale` value below is the constant magnitude that we want to
get on all rows.
+ */
boolean changed = false;
if (min < max) {
final double scale = (1 - selector)*min + selector*max;
@@ -882,9 +886,12 @@ public final class Matrices extends Static {
changed |= (e != (e *= rescale));
matrix.setElement(j, i, e);
}
- double e = matrix.getElement(j, srcDim);
- changed |= (e != (e += shift[j] * (1 - rescale)));
- matrix.setElement(j, srcDim, e);
+ if (anchor != null) {
+ final double p = anchor[j];
+ double e = matrix.getElement(j, srcDim);
+ changed |= (e != (e = (e-p)*rescale + p));
+ matrix.setElement(j, srcDim, e);
+ }
}
}
return changed;