diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 1ee94ac..c1b445f 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -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/setup-dart@v1.0 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/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..8aca457 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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