Skip to content

Commit

Permalink
Merge pull request #28 from kb0/feature/27
Browse files Browse the repository at this point in the history
Feature/27
  • Loading branch information
kb0 authored Sep 18, 2023
2 parents 5dcf54a + 0c1ef68 commit 540da77
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 34 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,13 @@ jobs:
- name: Analyze project source
run: dart analyze --fatal-warnings --fatal-infos --verbose .

- name: Activate code coverage
run: dart pub global activate dart_coveralls

- name: Analyze code coverage
run: dart_coveralls report --debug --exclude-test-files --token=$COVERALLS_REPO_TOKEN test/all_test.dart

test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
sdk: [stable, 2.17.0]
sdk: [stable, 3.0.0]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/[email protected]
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.0.0

* Update Dart DSK version to 3.0.0+
* Fix PolygonUtil.decode on JavaScript (https://github.com/Dammyololade/flutter_polyline_points/issues/40#issuecomment-751765055)

## 2.0.1

* Update Dart DSK version up to 2.17.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ In your dart/flutter project add the dependency:
```
dependencies:
...
maps_toolkit: ^2.0.1
maps_toolkit: ^3.0.0
```

A simple usage example:
Expand Down
9 changes: 1 addition & 8 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ linter:
- flutter_style_todos
- hash_and_equals
- implementation_imports
- invariant_booleans
- iterable_contains_unrelated_type
- collection_methods_unrelated_type
- join_return_with_assignment
- library_names
- library_prefixes
- lines_longer_than_80_chars
- list_remove_unrelated_type
- literal_only_boolean_expressions
- no_adjacent_strings_in_list
- no_duplicate_case_values
Expand All @@ -87,7 +85,6 @@ linter:
- prefer_const_literals_to_create_immutables
- prefer_constructors_over_static_methods
- prefer_contains
- prefer_equal_for_default_values
- prefer_expression_function_bodies
- prefer_final_fields
- prefer_final_in_for_each
Expand Down Expand Up @@ -147,7 +144,3 @@ linter:
# - use_to_and_as_if_applicable
- valid_regexps
- void_checks

analyzer:
strong-mode:
implicit-casts: false
44 changes: 30 additions & 14 deletions lib/src/polygon_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ class PolygonUtil {
return SphericalUtil.computeDistanceBetween(p, su);
}

/// Decodes an encoded path string into a sequence of LatLngs.
static List<LatLng> decode(final String encodedPath) {
final len = encodedPath.length;

Expand All @@ -451,28 +450,45 @@ class PolygonUtil {
var lat = 0;
var lng = 0;

final big0 = BigInt.from(0);
final big0x1f = BigInt.from(0x1f);
final big0x20 = BigInt.from(0x20);

while (index < len) {
var result = 1;
var shift = 0;
int b1;
BigInt b, result;
result = big0;
do {
b1 = encodedPath.codeUnitAt(index++) - 63 - 1;
result += b1 << shift;
b = BigInt.from(encodedPath.codeUnitAt(index++) - 63);
result |= (b & big0x1f) << shift;
shift += 5;
} while (b1 >= 0x1f);
lat += (result & 1) != 0 ? ~(result >> 1) : (result >> 1);
} while (b >= big0x20);
var rShifted = result >> 1;
int dLat;
if (result.isOdd) {
dLat = (~rShifted).toInt();
} else {
dLat = rShifted.toInt();
}
lat += dLat;

result = 1;
shift = 0;
int b2;
result = big0;
do {
b2 = encodedPath.codeUnitAt(index++) - 63 - 1;
result += b2 << shift;
b = BigInt.from(encodedPath.codeUnitAt(index++) - 63);
result |= (b & big0x1f) << shift;
shift += 5;
} while (b2 >= 0x1f);
lng += (result & 1) != 0 ? ~(result >> 1) : (result >> 1);
} while (b >= big0x20);
rShifted = result >> 1;
int dlng;
if (result.isOdd) {
dlng = (~rShifted).toInt();
} else {
dlng = rShifted.toInt();
}
lng += dlng;

path.add(LatLng(lat * 1e-5, lng * 1e-5));
path.add(LatLng((lat / 1E5).toDouble(), (lng / 1E5).toDouble()));
}

return path;
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: maps_toolkit
description: Maps toolkit - geo-measurements utils - area of polygon, distance between point, heading and offset between points (port of SphericalUtil, PolyUtil from `android-maps-utils`).
version: 2.0.1
version: 3.0.0
homepage: https://github.com/kb0/maps_toolkit/

environment:
sdk: ">=2.17.0 <3.0.0"
sdk: '>=3.0.0 <4.0.0'

dependencies:

dev_dependencies:
lints: ^2.0.0
test: ^1.21.0
lints: 2.1.1
test: 1.24.6

0 comments on commit 540da77

Please sign in to comment.