source: josm/trunk/test/unit/org/openstreetmap/josm/gui/mappaint/RenderingCLIAreaTest.java

Last change on this file was 19086, checked in by stoecker, 10 months ago

fix some test failures

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