Skip to content

Commit d87d272

Browse files
committed
Updated reference files to 1.81-nohp
1 parent 3a4b4bf commit d87d272

39 files changed

+936908
-942754
lines changed

src/main/java/com/mapcode/Point.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static Point fromUniformlyDistributedRandomPoints(@Nonnull final Random r
118118
assert !Double.isNaN(lonRad);
119119
final double lat = latRad * (180.0 / Math.PI);
120120
final double lon = lonRad * (180.0 / Math.PI);
121-
return fromMicroDeg(degToMicroDeg(lat), degToMicroDeg(lon));
121+
return fromDeg(lat, lon);
122122
}
123123

124124
/**
@@ -242,11 +242,21 @@ static Point fromMicroDeg(final int latMicroDeg, final int lonMicroDeg) {
242242
return new Point(microDegToDeg(latMicroDeg), microDegToDeg(lonMicroDeg), false);
243243
}
244244

245+
/**
246+
* Get latitude as micro-degrees. Note that this looses precision beyond microdegrees!
247+
*
248+
* @return Latitude in microdegrees (may loose precision if latitude has higher precision than microdegrees).
249+
*/
245250
int getLatMicroDeg() {
246251
assert defined;
247252
return degToMicroDeg(latDeg);
248253
}
249254

255+
/**
256+
* Get longitude as micro-degrees. Note that this looses precision beyond microdegrees!
257+
*
258+
* @return Longitude in microdegrees (may loose precision if longitude has higher precision than microdegrees).
259+
*/
250260
int getLonMicroDeg() {
251261
assert defined;
252262
return degToMicroDeg(lonDeg);

src/main/java/com/mapcode/SubArea.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class SubArea {
102102
}
103103
}
104104
}
105-
LOG.info("SubArea: sub-areas initialized: aslat=[{}, {}], lon=[{}, {}]",
105+
LOG.info("SubArea: sub-areas initialized: lat=[{}, {}], lon=[{}, {}]",
106106
Point.microDegToDeg(LAT_MAP.firstKey()), Point.microDegToDeg(LAT_MAP.lastKey()),
107107
Point.microDegToDeg(LON_MAP.firstKey()), Point.microDegToDeg(LON_MAP.lastKey()));
108108
}

src/test/java/com/mapcode/ReferenceFileTest.java

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ private static void checkFile(@Nonnull final String baseFileName) throws Excepti
128128
LOG.debug("checkFile: lat/lon = {}", reference.point);
129129
LOG.debug("checkFile: expected = #{}: {}", reference.mapcodes.size(), GSON.toJson(reference.mapcodes));
130130
}
131+
++i;
131132

132133
// Encode lat/lon to series of mapcodes and check the resulting mapcodes.
133134
final List<Mapcode> results = MapcodeCodec.encode(
@@ -172,53 +173,43 @@ private static void checkFile(@Nonnull final String baseFileName) throws Excepti
172173
}
173174

174175
// For every mapcode in the result set, check if it is contained in the reference set.
176+
int precision = 0;
175177
for (final Mapcode result : results) {
176178
boolean found = false;
177179
for (final MapcodeRec referenceMapcodeRec : reference.mapcodes) {
180+
precision = (referenceMapcodeRec.mapcode.lastIndexOf('-') > 4) ? 2 : 0;
181+
178182
if (referenceMapcodeRec.territory.equals(result.getTerritory())) {
179-
if (referenceMapcodeRec.mapcode.lastIndexOf('-') > 4) {
180-
if (referenceMapcodeRec.mapcode.equals(result.getCode(2))) {
181-
found = true;
182-
break;
183-
}
184-
} else {
185-
if (referenceMapcodeRec.mapcode.equals(result.getCode())) {
186-
found = true;
187-
break;
188-
}
183+
if (referenceMapcodeRec.mapcode.equals(result.getCode(precision))) {
184+
found = true;
185+
break;
189186
}
190187
}
191188
}
192189
if (!found) {
193190

194191
// This does not fail the test, but rather produces an ERROR in the log file.
195192
// It indicates a discrepancy in the C and Java implementations.
196-
LOG.error("checkFile: Mapcode '{}' at {} is not in the reference file!",
197-
result, reference.point);
193+
LOG.error("checkFile: Created '{}' at {} which is not present in the reference file!\nref={}\nresult={}",
194+
result.getCode(precision), reference.point, GSON.toJson(reference), GSON.toJson(result));
198195
++error;
199196
}
200197
}
201198

202199
// For every Mapcode in the reference set, check if it is contained in the result set.
203200
for (final MapcodeRec referenceMapcodeRec : reference.mapcodes) {
201+
precision = (referenceMapcodeRec.mapcode.lastIndexOf('-') > 4) ? 2 : 0;
204202
boolean found = false;
205203
for (final Mapcode result : results) {
206204
if (referenceMapcodeRec.territory.equals(result.getTerritory())) {
207-
if (referenceMapcodeRec.mapcode.lastIndexOf('-') > 4) {
208-
if (referenceMapcodeRec.mapcode.equals(result.getCode(2))) {
209-
found = true;
210-
break;
211-
}
212-
} else {
213-
if (referenceMapcodeRec.mapcode.equals(result.getCode())) {
214-
found = true;
215-
break;
216-
}
205+
if (referenceMapcodeRec.mapcode.equals(result.getCode(precision))) {
206+
found = true;
207+
break;
217208
}
218209
}
219210
}
220211
if (!found) {
221-
LOG.error("checkFile: Mapcode '{} {}' at {} is not produced by the decoder!",
212+
LOG.error("checkFile: Found '{} {}' at {} in reference file, not produced by new decoder!",
222213
referenceMapcodeRec.territory, referenceMapcodeRec.mapcode, reference.point);
223214
++error;
224215
}
@@ -246,11 +237,6 @@ private static void checkFile(@Nonnull final String baseFileName) throws Excepti
246237
++error;
247238
}
248239
}
249-
250-
if (showLogLine) {
251-
LOG.debug("");
252-
}
253-
++i;
254240
}
255241
} catch (final EOFException e) {
256242
// OK.

0 commit comments

Comments
 (0)