Skip to content

Commit f9e53b4

Browse files
committed
improve readme & test examples
1 parent d67e31c commit f9e53b4

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ normal usage:
1111
```d
1212
import openlocationcode;
1313
14+
double lat = 54;
15+
double lon = 4;
16+
1417
// get geo coordinates from plus code string
1518
OpenLocationCode plusCode = OpenLocationCode.fromString("8FVC2222+22GCCCC");
1619
writeln(plusCode.decode());
17-
// ->
20+
// -> OpenLocationCodeArea(47.0001, 8.00006, 47.0001, 8.00006, 15)
1821
1922
// get plus code string from geo coordinates
2023
OpenLocationCode generatedPlusCode = OpenLocationCode.encode(lat, lon);
2124
writeln(generatedPlusCode.code);
25+
// -> 9F662222+22
2226
```
2327

2428
---
@@ -28,20 +32,25 @@ writeln(generatedPlusCode.code);
2832
```d
2933
import openlocationcode;
3034
35+
double lat = 54;
36+
double lon = 4;
37+
3138
// get geo coordinates from plus code string
3239
string input = "8FVC2222+22GCCCC";
33-
if (!input.isValidCode)
40+
// make sure to only use uppercase characters in your input!
41+
if (!input.isValidUppercaseCode)
3442
return error;
3543
OpenLocationCode plusCode = OpenLocationCode.fromTrustedString(input);
3644
3745
if (!plusCode.isFull)
3846
return error;
3947
OpenLocationCodeArea area = plusCode.decodeTrustedFull();
40-
printf("area around %d, %d", area.centerLatitude, area.centerLongitude);
48+
printf("area around %f, %f\n", area.centerLatitude, area.centerLongitude);
49+
// -> area around 47.000062, 8.000063
4150
4251
// get plus code string from geo coordinates
4352
ubyte[maxOLCLength] buffer;
4453
scope ubyte[] generatedPlusCodeString = OpenLocationCode.encode(buffer, lat, lon);
45-
printf("%s", cast(char[])generatedPlusCodeString);
46-
54+
printf("%.*s\n", generatedPlusCodeString.length, &generatedPlusCodeString[0]);
55+
// -> 9F662222+22
4756
```

benchmark/source/app.d

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ void main()
2727
}
2828
}
2929

30+
// get geo coordinates from plus code string
31+
OpenLocationCode plusCode = OpenLocationCode.fromString("8FVC2222+22GCCCC");
32+
writeln(plusCode.decode());
33+
34+
// get plus code string from geo coordinates
35+
OpenLocationCode generatedPlusCode = OpenLocationCode.encode(54, 4);
36+
writeln(generatedPlusCode.code);
37+
38+
testNogc();
39+
3040
TestData[] list;
3141
list.length = loops;
3242
foreach (i; 0 .. loops)
@@ -51,3 +61,24 @@ void main()
5161
dur = end - start;
5262
writefln("Decode %s loops in %s;\n\t%s per call", loops, dur, dur / loops);
5363
}
64+
65+
void testNogc() @nogc
66+
{
67+
import core.stdc.stdio;
68+
69+
// get geo coordinates from plus code string
70+
string input = "8FVC2222+22GCCCC";
71+
if (!input.isValidUppercaseCode)
72+
return;
73+
OpenLocationCode plusCode = OpenLocationCode.fromTrustedString(input);
74+
75+
if (!plusCode.isFull)
76+
return;
77+
OpenLocationCodeArea area = plusCode.decodeTrustedFull();
78+
printf("area around %f, %f\n", area.centerLatitude, area.centerLongitude);
79+
80+
// get plus code string from geo coordinates
81+
ubyte[maxOLCLength] buffer;
82+
scope ubyte[] generatedPlusCodeString = OpenLocationCode.encode(buffer, 54, 4);
83+
printf("%.*s\n", generatedPlusCodeString.length, &generatedPlusCodeString[0]);
84+
}

0 commit comments

Comments
 (0)