Skip to content

Commit cb01444

Browse files
committed
MarkSeenRootTest: add testScaleHintBounds
1 parent 8f16494 commit cb01444

1 file changed

Lines changed: 187 additions & 0 deletions

File tree

test/unit/org/openstreetmap/josm/plugins/markseen/MarkSeenRootTest.java

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.concurrent.Callable;
1414
import java.util.function.Consumer;
1515
import java.util.function.IntFunction;
16+
import java.util.regex.Matcher;
1617
import java.lang.AssertionError;
1718

1819
import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -32,6 +33,8 @@
3233

3334
import static org.junit.Assert.assertEquals;
3435
import static org.junit.Assert.assertFalse;
36+
import static org.junit.Assert.assertNotNull;
37+
import static org.junit.Assert.assertNull;
3538
import static org.junit.Assert.assertTrue;
3639
import static org.junit.Assert.fail;
3740

@@ -329,4 +332,188 @@ public void testSetMaxViewportFromCurrent() throws Exception {
329332
GuiHelper.runInEDTAndWaitWithException(() -> this.mainMenuSetMaxViewportItem.doClick());
330333
this.assertControlStates(10, true, true);
331334
}
335+
336+
@Test
337+
public void testScaleHintBounds() throws Exception {
338+
IntFunction<String> palMapFn = stripAlpha(ImmutableMap.of(
339+
0xffffff, "w",
340+
0x0, "b",
341+
0xf0d1d1, "p"
342+
));
343+
MapFrame mainMap = MainApplication.getMap();
344+
Config.getPref().put("markseen.mapstyle", "White Tiles");
345+
Config.getPref().putInt("markseen.recordMinZoom", 10);
346+
Config.getPref().putBoolean("markseen.recordActive", true);
347+
mainMap.mapView.zoomTo(new Bounds(-77.9024496, -41.6807301, -77.8268961, -41.3232887));
348+
349+
this.setUpMarkSeenRoot();
350+
351+
this.dialog.showDialog();
352+
353+
this.assertControlStates(10, true, false);
354+
assertTrue(this.recordToggleButton.getToolTipText().contains("disabled"));
355+
this.renderAndAssert(i -> {
356+
ImagePatternMatching.rowMatch(i, i.getHeight()/2, palMapFn, "w+bp+bw+", true);
357+
ImagePatternMatching.columnMatch(i, i.getWidth()/2, palMapFn, "w+bp+bw+", true);
358+
});
359+
360+
this.recordMinZoom.setValueIsAdjusting(true);
361+
this.recordMinZoom.setValue(11);
362+
363+
this.assertControlStates(11, true, false);
364+
assertTrue(this.recordToggleButton.getToolTipText().contains("disabled"));
365+
this.renderAndAssert(i -> {
366+
Matcher r_m = ImagePatternMatching.rowMatch(i, i.getHeight()/2, palMapFn, "w+b(p+)b(p+)b(p+)bw+", true);
367+
Matcher c_m = ImagePatternMatching.columnMatch(i, i.getWidth()/2, palMapFn, "w+b(p+)b(p+)b(p+)bw+", true);
368+
369+
assertTrue(
370+
Math.max(Math.max(r_m.group(1).length(), r_m.group(3).length()), Math.max(c_m.group(1).length(), c_m.group(3).length()))
371+
- Math.min(Math.min(r_m.group(1).length(), r_m.group(3).length()), Math.min(c_m.group(1).length(), c_m.group(3).length()))
372+
< 3
373+
);
374+
assertTrue(
375+
Math.max(r_m.group(2).length(), c_m.group(2).length())
376+
- Math.min(r_m.group(2).length(), c_m.group(2).length())
377+
< 3
378+
);
379+
});
380+
381+
Bounds shb = (Bounds)TestUtils.getPrivateField(this.slippyMap, "scaleHintBounds");
382+
assertTrue(Math.abs(shb.getMinLat() - -77.8712701) < 0.003);
383+
assertTrue(Math.abs(shb.getMinLon() - -41.532751) < 0.003);
384+
assertTrue(Math.abs(shb.getMaxLat() - -77.8582611) < 0.003);
385+
assertTrue(Math.abs(shb.getMaxLon() - -41.4708681) < 0.003);
386+
387+
this.recordMinZoom.setValue(13);
388+
389+
this.assertControlStates(13, true, false);
390+
assertTrue(this.recordToggleButton.getToolTipText().contains("disabled"));
391+
this.renderAndAssert(i -> {
392+
Matcher r_m = ImagePatternMatching.rowMatch(i, i.getHeight()/2, palMapFn, "w+b(p+)b(p+)b(p+)bw+", true);
393+
Matcher c_m = ImagePatternMatching.columnMatch(i, i.getWidth()/2, palMapFn, "w+b(p+)b(p+)b(p+)bw+", true);
394+
395+
assertTrue(
396+
Math.max(Math.max(r_m.group(1).length(), r_m.group(3).length()), Math.max(c_m.group(1).length(), c_m.group(3).length()))
397+
- Math.min(Math.min(r_m.group(1).length(), r_m.group(3).length()), Math.min(c_m.group(1).length(), c_m.group(3).length()))
398+
< 3
399+
);
400+
assertTrue(
401+
Math.max(r_m.group(2).length(), c_m.group(2).length())
402+
- Math.min(r_m.group(2).length(), c_m.group(2).length())
403+
< 3
404+
);
405+
});
406+
407+
shb = (Bounds)TestUtils.getPrivateField(this.slippyMap, "scaleHintBounds");
408+
assertTrue(Math.abs(shb.getMinLat() - -77.8907578) < 0.003);
409+
assertTrue(Math.abs(shb.getMinLon() - -41.6255752) < 0.003);
410+
assertTrue(Math.abs(shb.getMaxLat() - -77.8387218) < 0.003);
411+
assertTrue(Math.abs(shb.getMaxLon() - -41.3780439) < 0.003);
412+
413+
this.recordMinZoom.setValue(14);
414+
415+
this.assertControlStates(14, true, true);
416+
assertFalse(this.recordToggleButton.getToolTipText().contains("disabled"));
417+
this.renderAndAssert(i -> {
418+
Matcher r_m = ImagePatternMatching.rowMatch(i, i.getHeight()/2, palMapFn, "w+b(w+)b(p+)b(w+)bw+", true);
419+
Matcher c_m = ImagePatternMatching.columnMatch(i, i.getWidth()/2, palMapFn, "w+b(w+)b(p+)b(w+)bw+", true);
420+
421+
assertTrue(
422+
Math.max(Math.max(r_m.group(1).length(), r_m.group(3).length()), Math.max(c_m.group(1).length(), c_m.group(3).length()))
423+
- Math.min(Math.min(r_m.group(1).length(), r_m.group(3).length()), Math.min(c_m.group(1).length(), c_m.group(3).length()))
424+
< 3
425+
);
426+
assertTrue(
427+
Math.max(r_m.group(2).length(), c_m.group(2).length())
428+
- Math.min(r_m.group(2).length(), c_m.group(2).length())
429+
< 3
430+
);
431+
});
432+
433+
shb = (Bounds)TestUtils.getPrivateField(this.slippyMap, "scaleHintBounds");
434+
assertTrue(Math.abs(shb.getMinLat() - -77.9166935) < 0.004);
435+
assertTrue(Math.abs(shb.getMinLon() - -41.749341) < 0.004);
436+
assertTrue(Math.abs(shb.getMaxLat() - -77.8126213) < 0.004);
437+
assertTrue(Math.abs(shb.getMaxLon() - -41.2542782) < 0.004);
438+
439+
this.recordMinZoom.setValueIsAdjusting(false);
440+
441+
this.assertControlStates(14, true, true);
442+
assertFalse(this.recordToggleButton.getToolTipText().contains("disabled"));
443+
this.renderAndAssert(i -> {
444+
Matcher r_m = ImagePatternMatching.rowMatch(i, i.getHeight()/2, palMapFn, "w+b(p+)bw+", true);
445+
Matcher c_m = ImagePatternMatching.columnMatch(i, i.getWidth()/2, palMapFn, "w+b(p+)bw+", true);
446+
447+
assertTrue(
448+
Math.max(r_m.group(1).length(), c_m.group(1).length())
449+
- Math.min(r_m.group(1).length(), c_m.group(1).length())
450+
< 3
451+
);
452+
});
453+
454+
assertNull(TestUtils.getPrivateField(this.slippyMap, "scaleHintBounds"));
455+
456+
this.slippyMap.setZoom(this.slippyMap.getZoom()-3);
457+
458+
this.recordMinZoom.setValueIsAdjusting(true);
459+
this.recordMinZoom.setValue(18);
460+
461+
this.assertControlStates(18, true, true);
462+
assertFalse(this.recordToggleButton.getToolTipText().contains("disabled"));
463+
this.renderAndAssert(i -> {
464+
Matcher r_m = ImagePatternMatching.rowMatch(i, i.getHeight()/2, palMapFn, "w+b(w+)b(p+)b(w+)bw+", true);
465+
Matcher c_m = ImagePatternMatching.columnMatch(i, i.getWidth()/2, palMapFn, "w+b(w+)b(p+)b(w+)bw+", true);
466+
467+
// even at high scales this should continue to match the aspec ratio of the viewport but only
468+
// because the slippy map's projection matches that of the mapview.
469+
470+
assertTrue(
471+
Math.max(Math.max(r_m.group(1).length(), r_m.group(3).length()), Math.max(c_m.group(1).length(), c_m.group(3).length()))
472+
- Math.min(Math.min(r_m.group(1).length(), r_m.group(3).length()), Math.min(c_m.group(1).length(), c_m.group(3).length()))
473+
< 3
474+
);
475+
assertTrue(
476+
Math.max(r_m.group(2).length(), c_m.group(2).length())
477+
- Math.min(r_m.group(2).length(), c_m.group(2).length())
478+
< 3
479+
);
480+
});
481+
482+
shb = (Bounds)TestUtils.getPrivateField(this.slippyMap, "scaleHintBounds");
483+
484+
assertTrue(Math.abs(shb.getMinLat() - -78.6698339) < 0.005);
485+
assertTrue(Math.abs(shb.getMinLon() - -45.4624486) < 0.005);
486+
assertTrue(Math.abs(shb.getMaxLat() - -77.0034155) < 0.005);
487+
assertTrue(Math.abs(shb.getMaxLon() - -37.5411705) < 0.005);
488+
489+
this.recordMinZoom.setValue(this.recordMinZoom.getMaximum());
490+
491+
this.assertControlStates(this.recordMinZoom.getMaximum(), true, true);
492+
assertFalse(this.recordToggleButton.getToolTipText().contains("disabled"));
493+
assertNull(TestUtils.getPrivateField(this.slippyMap, "scaleHintBounds"));
494+
495+
this.recordMinZoom.setValue(this.recordMinZoom.getMaximum()-1);
496+
497+
this.assertControlStates(this.recordMinZoom.getMaximum()-1, true, true);
498+
assertFalse(this.recordToggleButton.getToolTipText().contains("disabled"));
499+
this.renderAndAssert(i -> {
500+
Matcher r_m = ImagePatternMatching.rowMatch(i, i.getHeight()/2, palMapFn, "w+b(p+)bw+", true);
501+
Matcher c_m = ImagePatternMatching.columnMatch(i, i.getWidth()/2, palMapFn, "w+b(p+)bw+", true);
502+
503+
// scaleHintBounds should all be beyond bounds of slippy map, but not fail or affect rendering
504+
505+
assertTrue(
506+
Math.max(r_m.group(1).length(), c_m.group(1).length())
507+
- Math.min(r_m.group(1).length(), c_m.group(1).length())
508+
< 3
509+
);
510+
});
511+
// probably a slightly nonsensical value at this latitude
512+
assertNotNull(TestUtils.getPrivateField(this.slippyMap, "scaleHintBounds"));
513+
514+
this.recordMinZoom.setValue(this.recordMinZoom.getMinimum());
515+
516+
this.assertControlStates(4, true, false);
517+
assertTrue(this.recordToggleButton.getToolTipText().contains("disabled"));
518+
}
332519
}

0 commit comments

Comments
 (0)