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