refactored

This commit is contained in:
randogoth 2025-02-02 21:43:12 +02:00
parent 471dbad6aa
commit f039d394a5
12 changed files with 29 additions and 23 deletions

View file

@ -1,3 +0,0 @@
## 1.0.0
- Initial version.

View file

@ -1,8 +1,12 @@
# WhatFreeWords
![bunny](bunny.png)
# Map3Terms
[![](http://www.wtfpl.net/wp-content/uploads/2012/12/wtfpl-badge-4.png")](http://www.wtfpl.net/)
This is the Dart port of the original [JavaScript implementation](https://github.com/pballett/whatfreewords) that was published as a small test to show how one might reversibly map each ~1m² element of the globe onto a 3-tuple of words.
This is the Dart port of the original [JavaScript implementation](https://github.com/pballett/map3terms) of a small but ingenious test to show how one might reversibly map roughly each square meter of the globe onto a 3-tuple of words using a simplified symmetric encryption method called [Feistel cipher](https://en.wikipedia.org/wiki/Feistel_cipher).
It seems inspired by the existing proprietary geocoding service [What3Words](https://wiki.openstreetmap.org/wiki/What3words) but uses a completely different method and list of words.
## Installation
@ -10,15 +14,15 @@ In your Flutter/Dart `pubspec.yaml` file include
```yaml
dependencies:
whatfreewords:
map3terms:
git:
url: https://github.com/randogoth/whatfreewords.git
url: https://github.com/randogoth/map3terms.git
```
## Usage
```dart
import 'package:whatfreewords/whatfreewords.dart';
import 'package:map3terms/map3terms.dart';
// coordinate to wfw
final List<double> coord = [51.50844113, -0.116708278];
@ -30,7 +34,7 @@ final coords = wordsToCoord(words);
print(coords); // [51.5084, -0.1167]
```
Check it out [here](https://pballett.github.io/whatfreewords/).
Check it out [here](https://pballett.github.io/map3terms/).
To do this we needed three things:
1. A function which maps metre-accurate (latitude, longitude) pairs into three 5-digit integers below 40k.

BIN
bunny.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View file

@ -0,0 +1,11 @@
import 'package:map3terms/map3terms.dart';
void main() {
List<double> coordinate = [51.50844113, -0.116708278];
String words = await coordToWords(coordinate);
print("Words: $words");
List<double> backToCoord = await wordsToCoord(words);
print("Coordinates: ${backToCoord[0]}, ${backToCoord[1]}");
}

View file

@ -1,6 +0,0 @@
import 'package:whatfreewords/whatfreewords.dart';
void main() {
var awesome = Awesome();
print('awesome: ${awesome.isAwesome}');
}

3
lib/map3terms.dart Normal file
View file

@ -0,0 +1,3 @@
library map3terms;
export 'src/map3terms_scrambler.dart';

View file

@ -1,5 +1,5 @@
import 'dart:math';
import 'whatfreewords_cipher.dart';
import 'map3terms_map.dart';
final Map<String, String> ilist =
wlist.map((key, value) => MapEntry(value, key));

View file

@ -1,3 +0,0 @@
library whatfreewords;
export 'src/whatfreewords_scrambler.dart';

View file

@ -1,7 +1,7 @@
name: whatfreewords
name: map3terms
description: A library for converting coordinates to words and back using a Feistel network.
version: 1.0.0
homepage: https://github.com/randogoth/whatfreewords
homepage: https://github.com/randogoth/map3terms
environment:
sdk: '>=2.17.0 <3.0.0'

View file

@ -1,11 +1,11 @@
import 'package:test/test.dart';
import 'dart:math';
import 'package:whatfreewords/whatfreewords.dart';
import 'package:map3terms/map3terms.dart';
void main() {
group('WhatFreeWords Tests', () {
group('map3terms Tests', () {
test('Coordinate to Words and Back', () async {
final List<double> coord = [51.50844113, -0.116708278];
final words = await coordToWords(coord);