Skip to content

Commit d48d946

Browse files
committed
QuadTreeMeta: only log a warning when "Proposed rect has such extreme aspect ratio that it would be zero-width at preferredZoom"
a fatal error is too extreme for such a self-solving problem
1 parent c9ff81d commit d48d946

3 files changed

Lines changed: 66 additions & 4 deletions

File tree

src/org/openstreetmap/josm/plugins/markseen/QuadTreeMeta.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.awt.image.IndexColorModel;
1919
import java.awt.image.WritableRaster;
2020

21+
import org.openstreetmap.josm.Main;
2122
import org.openstreetmap.josm.data.Bounds;
2223

2324
public class QuadTreeMeta {
@@ -119,7 +120,11 @@ public MarkBoundsSeenRequest(Bounds bounds_, double minTilesAcross_, boolean che
119120

120121
@Override
121122
public void run() {
122-
QuadTreeMeta.this.quadTreeRoot.markBoundsSeen(this.bounds, this.minTilesAcross);
123+
try {
124+
QuadTreeMeta.this.quadTreeRoot.markBoundsSeen(this.bounds, this.minTilesAcross);
125+
} catch (QuadTreeNode.ExtremeAspectRatioException e) {
126+
Main.warn(e.getMessage());
127+
}
123128
if (this.checkIntegrity) {
124129
QuadTreeMeta.this.quadTreeRoot.checkIntegrity();
125130
}

src/org/openstreetmap/josm/plugins/markseen/QuadTreeNode.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
import org.openstreetmap.josm.data.Bounds;
1818

1919
class QuadTreeNode {
20+
public static class ExtremeAspectRatioException extends UnsupportedOperationException {
21+
public ExtremeAspectRatioException() {
22+
super("Proposed rect has such extreme aspect ratio that it would be zero-width at preferredZoom");
23+
}
24+
}
25+
2026
private SoftReference<BufferedImage> mask;
2127
private BufferedImage canonicalMask;
2228

@@ -486,9 +492,7 @@ public void markBoundsSeen(Bounds bbox, double minTilesAcross) {
486492
double y1s = Math.rint(y1*preferredZoomFactor)/preferredZoomFactor;
487493

488494
if (x0s == x1s || y0s == y1s) {
489-
throw new UnsupportedOperationException(
490-
"Proposed rect has such extreme aspect ratio that it would be zero-width at preferredZoom"
491-
);
495+
throw new ExtremeAspectRatioException();
492496
}
493497

494498
this.markRectSeenInner(
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.openstreetmap.josm.plugins.markseen;
2+
3+
import java.io.IOException;
4+
import java.lang.Math;
5+
import java.util.Arrays;
6+
import java.util.Collection;
7+
8+
import java.awt.Color;
9+
10+
import org.openstreetmap.josm.data.Bounds;
11+
12+
import org.junit.Test;
13+
import org.junit.runner.RunWith;
14+
import org.junit.runners.Parameterized;
15+
import org.junit.runners.Parameterized.Parameters;
16+
17+
18+
@RunWith(Parameterized.class)
19+
public class QuadTreeNodeExtremeAspectRatioTest extends BaseTest {
20+
@Parameters()
21+
public static Collection<Object[]> getParameters() throws IOException {
22+
return Arrays.asList(scenarios);
23+
}
24+
25+
protected final static Object[][] scenarios = new Object[][] {
26+
{ 256, new Bounds(51.36, -0.35, 51.3601, 0.10), 1.1 },
27+
{ 128, new Bounds(20.22, -35.2, 20.23, -35.1999999), 4.2 },
28+
{ 161, new Bounds(-0.0001, -1.0, 0.0001, 1.0), 8.3 },
29+
{ 161, new Bounds(-1.0001, -1.0, -0.9999, 1.0), 8.3 }
30+
};
31+
32+
protected final int tileSize;
33+
protected final Bounds bounds;
34+
protected final double minTilesAcross;
35+
36+
public QuadTreeNodeExtremeAspectRatioTest(int tileSize_, Bounds bounds_, double minTilesAcross_) {
37+
this.tileSize = tileSize_;
38+
this.bounds = bounds_;
39+
this.minTilesAcross = minTilesAcross_;
40+
}
41+
42+
@Test(expected=QuadTreeNode.ExtremeAspectRatioException.class)
43+
public void test() {
44+
QuadTreeMeta quadTreeMeta = new QuadTreeMeta(this.tileSize, Color.PINK, 0.5);
45+
quadTreeMeta.quadTreeRWLock.writeLock().lock();
46+
47+
try {
48+
quadTreeMeta.quadTreeRoot.markBoundsSeen(this.bounds, this.minTilesAcross);
49+
} finally {
50+
quadTreeMeta.quadTreeRWLock.writeLock().unlock();
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)