[12906] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
| 3 |
|
---|
| 4 | import static org.CustomMatchers.isFP;
|
---|
[16618] | 5 | import static org.hamcrest.MatcherAssert.assertThat;
|
---|
[12906] | 6 |
|
---|
| 7 | import java.util.ArrayList;
|
---|
| 8 | import java.util.Collection;
|
---|
| 9 |
|
---|
| 10 | import org.CustomMatchers;
|
---|
| 11 | import org.CustomMatchers.ErrorMode;
|
---|
| 12 | import org.hamcrest.CoreMatchers;
|
---|
| 13 | import org.hamcrest.Matcher;
|
---|
[17275] | 14 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
[17276] | 15 | import org.junit.jupiter.params.ParameterizedTest;
|
---|
| 16 | import org.junit.jupiter.params.provider.MethodSource;
|
---|
[12906] | 17 | import org.openstreetmap.josm.data.Bounds;
|
---|
| 18 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
| 19 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
| 20 |
|
---|
| 21 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | * Tests the method {@link RenderingCLI#determineRenderingArea(org.openstreetmap.josm.data.osm.DataSet)}.
|
---|
| 25 | */
|
---|
[17275] | 26 | class RenderingCLIAreaTest {
|
---|
[12906] | 27 | /**
|
---|
| 28 | * Setup rule
|
---|
| 29 | */
|
---|
[17275] | 30 | @RegisterExtension
|
---|
[12906] | 31 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
[12907] | 32 | public JOSMTestRules test = new JOSMTestRules().projection().territories();
|
---|
[12906] | 33 |
|
---|
| 34 | public static Collection<Object[]> runs() {
|
---|
| 35 | Collection<Object[]> runs = new ArrayList<>();
|
---|
| 36 |
|
---|
| 37 | final double SCALE_Z18 = 0.5971642834779395;
|
---|
| 38 | final double SCALE_Z19 = 0.29858214173896974;
|
---|
| 39 |
|
---|
| 40 | // area of imagery tile z=19/x=292949/y=174587
|
---|
| 41 | Bounds bTile = new Bounds(51.40091918770498, 21.152114868164077, 51.4013475612123, 21.15280151367189, false);
|
---|
| 42 |
|
---|
| 43 | // 0
|
---|
| 44 | runs.add(new Object[] {"--zoom 19 --bounds " + param(bTile),
|
---|
| 45 | CoreMatchers.is(SCALE_Z19),
|
---|
| 46 | CoreMatchers.is(bTile)});
|
---|
| 47 |
|
---|
| 48 | Bounds bFeldberg = new Bounds(53.33, 13.43, 53.333, 13.44); // rectangular area in the city Feldberg
|
---|
| 49 | double scaleFeldberg4000 = 1.7722056827012918;
|
---|
| 50 |
|
---|
| 51 | // 1
|
---|
| 52 | runs.add(new Object[] {"--scale 4000 --bounds " + param(bFeldberg),
|
---|
| 53 | CoreMatchers.is(scaleFeldberg4000),
|
---|
| 54 | CoreMatchers.is(bFeldberg)});
|
---|
| 55 |
|
---|
| 56 | // 2
|
---|
| 57 | runs.add(new Object[] {"--width-px 628 --bounds " + param(bFeldberg),
|
---|
| 58 | isFP(scaleFeldberg4000, ErrorMode.RELATIVE, 1e-3),
|
---|
| 59 | CoreMatchers.is(bFeldberg)});
|
---|
| 60 |
|
---|
| 61 | // 3
|
---|
| 62 | runs.add(new Object[] {"--height-px 316 --bounds " + param(bFeldberg),
|
---|
| 63 | isFP(scaleFeldberg4000, ErrorMode.RELATIVE, 1.5e-3),
|
---|
| 64 | CoreMatchers.is(bFeldberg)});
|
---|
| 65 |
|
---|
| 66 | LatLon aFeldberg = bFeldberg.getMin();
|
---|
| 67 | LatLon aFeldberg200mRight = new LatLon(aFeldberg.lat(), 13.433008399004041);
|
---|
| 68 | LatLon aFeldberg150mUp = new LatLon(53.33134745249311, aFeldberg.lon());
|
---|
[16618] | 69 | assertThat(aFeldberg.greatCircleDistance(aFeldberg200mRight), isFP(200.0, 0.01));
|
---|
| 70 | assertThat(aFeldberg.greatCircleDistance(aFeldberg150mUp), isFP(150.0, 0.01));
|
---|
[12906] | 71 |
|
---|
| 72 | Bounds bFeldberg200x150m = new Bounds(
|
---|
| 73 | bFeldberg.getMin(), new LatLon(aFeldberg150mUp.lat(), aFeldberg200mRight.lon()));
|
---|
| 74 |
|
---|
| 75 | // 4
|
---|
| 76 | runs.add(new Object[] {"--width-m 200 --height-m 150 -z 18 --anchor " + param(aFeldberg),
|
---|
| 77 | CoreMatchers.is(SCALE_Z18),
|
---|
| 78 | CustomMatchers.is(bFeldberg200x150m, 1e-7)});
|
---|
| 79 | // -> image size 561x421 px
|
---|
| 80 |
|
---|
| 81 | // 5
|
---|
| 82 | runs.add(new Object[] {"--width-m 200 --height-m 150 --scale 4000 --anchor " + param(aFeldberg),
|
---|
| 83 | isFP(scaleFeldberg4000, ErrorMode.RELATIVE, 1e-3),
|
---|
| 84 | CustomMatchers.is(bFeldberg200x150m, 1e-7)});
|
---|
| 85 | // -> image size 189x142 px
|
---|
| 86 |
|
---|
| 87 | // 6
|
---|
| 88 | runs.add(new Object[] {"--width-px 561 --height-px 421 -z 18 --anchor " + param(aFeldberg),
|
---|
| 89 | CoreMatchers.is(SCALE_Z18),
|
---|
| 90 | CustomMatchers.is(bFeldberg200x150m, 1e-5)});
|
---|
| 91 |
|
---|
| 92 | // 7
|
---|
| 93 | runs.add(new Object[] {"--width-px 189 --height-px 142 --scale 4000 --anchor " + param(aFeldberg),
|
---|
| 94 | isFP(scaleFeldberg4000, ErrorMode.RELATIVE, 1e-3),
|
---|
| 95 | CustomMatchers.is(bFeldberg200x150m, 1e-5)});
|
---|
| 96 |
|
---|
| 97 | // 8
|
---|
| 98 | runs.add(new Object[] {"--width-px 561 --height-m 150 -z 18 --anchor " + param(aFeldberg),
|
---|
| 99 | CoreMatchers.is(SCALE_Z18),
|
---|
| 100 | CustomMatchers.is(bFeldberg200x150m, 1e-5)});
|
---|
| 101 |
|
---|
| 102 | // 9
|
---|
| 103 | runs.add(new Object[] {"--width-px 189 --height-m 150 --scale 4000 --anchor " + param(aFeldberg),
|
---|
| 104 | isFP(scaleFeldberg4000, ErrorMode.RELATIVE, 1e-3),
|
---|
| 105 | CustomMatchers.is(bFeldberg200x150m, 1e-5)});
|
---|
| 106 |
|
---|
| 107 | // 10
|
---|
| 108 | runs.add(new Object[] {"--width-m 200 --height-px 421 -z 18 --anchor " + param(aFeldberg),
|
---|
| 109 | CoreMatchers.is(SCALE_Z18),
|
---|
| 110 | CustomMatchers.is(bFeldberg200x150m, 1e-5)});
|
---|
| 111 |
|
---|
| 112 | // 11
|
---|
| 113 | runs.add(new Object[] {"--width-m 200 --height-px 142 --scale 4000 --anchor " + param(aFeldberg),
|
---|
| 114 | isFP(scaleFeldberg4000, ErrorMode.RELATIVE, 1e-3),
|
---|
| 115 | CustomMatchers.is(bFeldberg200x150m, 1e-5)});
|
---|
| 116 |
|
---|
| 117 | // 12
|
---|
| 118 | runs.add(new Object[] {"--width-m 200 --height-m 150 --width-px 561 --anchor " + param(aFeldberg),
|
---|
| 119 | isFP(SCALE_Z18, ErrorMode.RELATIVE, 1e-3),
|
---|
| 120 | CustomMatchers.is(bFeldberg200x150m, 1e-5)});
|
---|
| 121 |
|
---|
| 122 | // 13
|
---|
| 123 | runs.add(new Object[] {"--width-m 200 --height-m 150 --height-px 421 --anchor " + param(aFeldberg),
|
---|
| 124 | isFP(SCALE_Z18, ErrorMode.RELATIVE, 1e-3),
|
---|
| 125 | CustomMatchers.is(bFeldberg200x150m, 1e-5)});
|
---|
| 126 |
|
---|
| 127 | // 14
|
---|
| 128 | runs.add(new Object[] {"--width-px 561 --height-px 421 --width-m 200 --anchor " + param(aFeldberg),
|
---|
| 129 | isFP(SCALE_Z18, ErrorMode.RELATIVE, 1e-3),
|
---|
| 130 | CustomMatchers.is(bFeldberg200x150m, 1e-5)});
|
---|
| 131 |
|
---|
| 132 | // 15
|
---|
| 133 | runs.add(new Object[] {"--width-px 561 --height-px 421 --height-m 150 --anchor " + param(aFeldberg),
|
---|
| 134 | isFP(SCALE_Z18, ErrorMode.RELATIVE, 1e-3),
|
---|
| 135 | CustomMatchers.is(bFeldberg200x150m, 1e-5)});
|
---|
| 136 |
|
---|
| 137 | return runs;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | private static String param(Bounds b) {
|
---|
| 141 | return b.getMinLon() + "," + b.getMinLat() + "," + b.getMaxLon() + "," + b.getMaxLat();
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | private static String param(LatLon ll) {
|
---|
| 145 | return ll.lon() + "," + ll.lat();
|
---|
| 146 | }
|
---|
| 147 |
|
---|
[17276] | 148 | @ParameterizedTest
|
---|
| 149 | @MethodSource("runs")
|
---|
| 150 | void testDetermineRenderingArea(String args, Matcher<Double> scaleMatcher, Matcher<Bounds> boundsMatcher) {
|
---|
[12906] | 151 | RenderingCLI cli = new RenderingCLI();
|
---|
[17276] | 152 | cli.parseArguments(args.split("\\s+", -1));
|
---|
[12906] | 153 | RenderingCLI.RenderingArea ra = cli.determineRenderingArea(null);
|
---|
[16618] | 154 | assertThat(ra.scale, scaleMatcher);
|
---|
| 155 | assertThat(ra.bounds, boundsMatcher);
|
---|
[12906] | 156 | }
|
---|
| 157 | }
|
---|