Skip to content

Commit d5eb5ee

Browse files
2.2 Solved 1-microdegree gap in a few spots on Earth, noticable now extreme precision is possible
1 parent 5e89a54 commit d5eb5ee

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

src/main/java/com/mapcode/DataAccess.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,25 @@ class DataAccess {
6262
final byte[] bytes = outputStream.toByteArray();
6363
assert total == bytes.length;
6464

65-
// read array sizes
66-
assert total > 4;
67-
nrTerritoryRecords = (bytes[0] & 255) + ((bytes[1] & 255) << 8);
68-
nrTerritories = (bytes[2] & 255) + ((bytes[3] & 255) << 8);
69-
LOG.info("nrTerritories={} nrTerritoryRecords={}",nrTerritories,nrTerritoryRecords);
70-
assert (2 + 2 + ((nrTerritories + 1) * 2) + (nrTerritoryRecords * 20) == total);
71-
72-
// read DATA+START array
65+
// read 8-byte header: SIGNATURE "MC", VERSION, NR TERRITORIES, NR RECTRANGLE RECORD
66+
assert total > 8;
67+
assert (char) bytes[0] == 'M';
68+
assert (char) bytes[1] == 'C';
69+
final int dataVersion = (bytes[2] & 255) + ((bytes[3] & 255) << 8);
70+
nrTerritoryRecords = (bytes[4] & 255) + ((bytes[5] & 255) << 8);
71+
nrTerritories = (bytes[6] & 255) + ((bytes[7] & 255) << 8);
72+
LOG.info("version={} nrTerritories={} nrTerritoryRecords={}",dataVersion,nrTerritories,nrTerritoryRecords);
73+
assert (8 + ((nrTerritories + 1) * 2) + (nrTerritoryRecords * 20) == total);
74+
75+
// read DATA+START array (2 bytes per territory, plus closing record)
7376
DATA_START = new int[nrTerritories + 1];
74-
int i = 4;
77+
int i = 8;
7578
for (int k=0; k <= nrTerritories; k++) {
7679
DATA_START[k] = (bytes[i] & 255) + ((bytes[i + 1] & 255) << 8);
7780
i += 2;
7881
}
7982

80-
// read territory rectangle data (mminfo)
83+
// read territory rectangle data (5 longs per record)
8184
FILE_DATA = new int[nrTerritoryRecords * 5];
8285
for (int k=0; k < nrTerritoryRecords * 5; k++) {
8386
FILE_DATA[k] = ((bytes[i] & 255)) +
244 Bytes
Binary file not shown.

src/site/apt/ReleaseNotes.apt.vm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
In any case, never depend on them for your own non-<<<SNAPSHOT>>> releases.
1010
#end
1111

12+
* 2.2.0
13+
14+
* Solved 1-microdegree gap in a few spots on Earth, noticable now extreme precision is possible;
15+
16+
* Replaced floating point by fixed point math; Improved speed;
17+
18+
* Enforce encode(decode(M))=M, except at territory border corners;
19+
20+
* Cleaned up source; moved hard-coded data into mminfo.dat;
1221

1322
* 2.1.0
1423

src/test/java/com/mapcode/EncoderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public void encodeToShortest4() throws Exception {
226226
@Test
227227
public void legalArguments() {
228228
LOG.info("legalArguments");
229-
assertEquals(MapcodeCodec.encode(-90, 0).size(), 2); // ATA and AAA
229+
assertEquals(MapcodeCodec.encode(-90, 0).size(), 3); // 2 x ATA and AAA
230230
assertEquals(MapcodeCodec.encode(-60, 0).size(), 2); // ATA and AAA
231231
assertEquals(MapcodeCodec.encode(90, 0).size(), 1); // AAA only
232232
assertEquals(MapcodeCodec.encode(0, -180),MapcodeCodec.encode(0, 180));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private static ReferenceRec getNextReferenceRecord(@Nonnull final ChunkedFile ch
301301
(args.length == 3) || (args.length == 6));
302302

303303
final int count = Integer.parseInt(args[0]);
304-
assertTrue("Expecting between 1 and 21 mapcodes", (1 <= count) && (count <= 21));
304+
assertTrue("Expecting between 1 and 22 mapcodes", (1 <= count) && (count <= 22));
305305

306306
// Read lat/lon.
307307
final double latDeg = Double.parseDouble(args[1]);

0 commit comments

Comments
 (0)