From df227018a874a4ceb4718d9a03308bcaf6b8ff7c Mon Sep 17 00:00:00 2001 From: Kirill Bychkov Date: Mon, 18 Sep 2023 16:09:49 +0300 Subject: [PATCH 1/4] update dart sdk to >=3.0.0 fix polyline decode in JS --- lib/src/polygon_util.dart | 44 ++++++++++++++++++++++++++------------- pubspec.yaml | 6 +++--- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/lib/src/polygon_util.dart b/lib/src/polygon_util.dart index d131aaa..f071b1e 100644 --- a/lib/src/polygon_util.dart +++ b/lib/src/polygon_util.dart @@ -440,7 +440,6 @@ class PolygonUtil { return SphericalUtil.computeDistanceBetween(p, su); } - /// Decodes an encoded path string into a sequence of LatLngs. static List decode(final String encodedPath) { final len = encodedPath.length; @@ -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; diff --git a/pubspec.yaml b/pubspec.yaml index 23e8132..410aef8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,10 +4,10 @@ version: 2.0.1 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 From f3a8f02de212a29f37a9eeac00b26be3f10ae5c6 Mon Sep 17 00:00:00 2001 From: Kirill Bychkov Date: Mon, 18 Sep 2023 16:18:52 +0300 Subject: [PATCH 2/4] bump version 3.0.0 --- CHANGELOG.md | 5 +++++ README.md | 2 +- analysis_options.yaml | 9 +-------- pubspec.yaml | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f430ec3..7ad5304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 8c37f5a..ea01b0c 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/analysis_options.yaml b/analysis_options.yaml index 028f08f..3f9af52 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -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 @@ -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 @@ -147,7 +144,3 @@ linter: # - use_to_and_as_if_applicable - valid_regexps - void_checks - -analyzer: - strong-mode: - implicit-casts: false diff --git a/pubspec.yaml b/pubspec.yaml index 410aef8..8aca457 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ 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: From ce176c8c8a63ff9296aa058b5529dea7a42dee83 Mon Sep 17 00:00:00 2001 From: Kirill Bychkov Date: Mon, 18 Sep 2023 16:23:40 +0300 Subject: [PATCH 3/4] remove dart_coveralls --- .github/workflows/dart.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 1ee94ac..ae03989 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -23,12 +23,6 @@ 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: From 0c1ef68cabfbfc3041d8405622885828be9a6930 Mon Sep 17 00:00:00 2001 From: Kirill Bychkov Date: Mon, 18 Sep 2023 16:25:09 +0300 Subject: [PATCH 4/4] fix dart version in github actions --- .github/workflows/dart.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index ae03989..c1b445f 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -29,7 +29,7 @@ jobs: 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/setup-dart@v1.0