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

Last change on this file since 18494 was 18494, checked in by taylor.smock, 3 years ago

Fix #22115: Extract methods from LatLon into ILatLon where they are generally applicable

This also removes calls to Node#getCoor where possible, which reduces
the number of memory allocations in SearchCompiler#match, and overall
allocations due to Node#getCoor

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