diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 7916361..1ee94ac 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -24,7 +24,7 @@ jobs: run: dart analyze --fatal-warnings --fatal-infos --verbose . - name: Activate code coverage - run: pub global activate dart_coveralls + 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 @@ -35,7 +35,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - sdk: [stable, 2.12.0, 2.13.1] + sdk: [stable, 2.17.0] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v1.0 @@ -59,4 +59,4 @@ jobs: run: dart pub get - name: Publish project - run: pub publish --dry-run + run: dart pub publish --dry-run diff --git a/CHANGELOG.md b/CHANGELOG.md index ec74cc9..f430ec3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.1 + +* Update Dart DSK version up to 2.17.0 +* Add LatLng.toString, Location.toString + ## 2.0.0 * BREAKING CHANGE: This version requires Dart SDK 2.12.0 or later (null safety). diff --git a/README.md b/README.md index 3579466..8c37f5a 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ In your dart/flutter project add the dependency: ``` dependencies: ... - maps_toolkit: ^2.0.0 + maps_toolkit: ^2.0.1 ``` A simple usage example: @@ -32,6 +32,13 @@ main() { LatLng(51.5073509, -0.1277583), LatLng(48.856614, 2.3522219) ); + + final p1 = LatLng(45.153474463955796, 39.33852195739747); + final p2 = LatLng(45.153474463955796, 39.33972358703614); + final p3 = LatLng(45.15252112936569, 39.33972358703614); + final p4 = LatLng(45.1525022138355, 39.3385460972786); + + val areaInSquareMeters = SphericalUtil.computeArea([p1, p2, p3, p4, p1]); } ``` diff --git a/analysis_options.yaml b/analysis_options.yaml index 4532cbb..028f08f 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,4 +1,4 @@ -include: package:pedantic/analysis_options.yaml +include: package:lints/recommended.yaml linter: rules: @@ -12,7 +12,7 @@ linter: - avoid_bool_literals_in_conditional_expressions - avoid_catches_without_on_clauses - avoid_catching_errors - - avoid_classes_with_only_static_members + # - avoid_classes_with_only_static_members - avoid_double_and_int_checks - avoid_empty_else - avoid_field_initializers_in_const_classes @@ -150,4 +150,4 @@ linter: analyzer: strong-mode: - implicit-casts: false \ No newline at end of file + implicit-casts: false diff --git a/lib/src/latlng.dart b/lib/src/latlng.dart index a76f245..b1eae7d 100644 --- a/lib/src/latlng.dart +++ b/lib/src/latlng.dart @@ -28,7 +28,5 @@ class LatLng { } @override - String toString() { - return 'Lat: ${latitude}, Lng: ${longitude}'; - } + String toString() => 'Lat: $latitude, Lng: $longitude'; } diff --git a/lib/src/location.dart b/lib/src/location.dart index 919595b..127f9c9 100644 --- a/lib/src/location.dart +++ b/lib/src/location.dart @@ -12,6 +12,9 @@ class Location { required this.time, }); + @override + String toString() => 'LatLng: $latlng, Accuracy: $accuracy, Time: $time'; + // factory LatLng.fromMap(Map dataMap) { // return LatLng(dataMap['latitude'], dataMap['longitude']); // } diff --git a/lib/src/polygon_util.dart b/lib/src/polygon_util.dart index 1880d7c..d131aaa 100644 --- a/lib/src/polygon_util.dart +++ b/lib/src/polygon_util.dart @@ -112,7 +112,7 @@ class PolygonUtil { return (nIntersect & 1) != 0; } - static const num DEFAULT_TOLERANCE = 0.1; // meters. + static const num defaultTolerance = 0.1; // meters. /// Computes whether the given point lies on or near the edge of a polygon, /// within a specified tolerance in meters. The polygon edge is composed of @@ -121,7 +121,7 @@ class PolygonUtil { /// between the first point and the last point is included. static bool isLocationOnEdge( LatLng point, List polygon, bool geodesic, - {num tolerance = DEFAULT_TOLERANCE}) => + {num tolerance = defaultTolerance}) => _isLocationOnEdgeOrPath(point, polygon, true, geodesic, tolerance); /// Computes whether the given point lies on or near a polyline, within a @@ -131,7 +131,7 @@ class PolygonUtil { /// and the last point is not included. static bool isLocationOnPath( LatLng point, List polyline, bool geodesic, - {num tolerance = DEFAULT_TOLERANCE}) => + {num tolerance = defaultTolerance}) => _isLocationOnEdgeOrPath(point, polyline, false, geodesic, tolerance); static bool _isLocationOnEdgeOrPath(LatLng point, List poly, @@ -157,7 +157,7 @@ class PolygonUtil { /// ..., /// poly.size()-2 if between poly[poly.size() - 2] and poly[poly.size() - 1] static int locationIndexOnPath(LatLng point, List poly, bool geodesic, - {num tolerance = DEFAULT_TOLERANCE}) => + {num tolerance = defaultTolerance}) => locationIndexOnEdgeOrPath(point, poly, false, geodesic, tolerance); /// Computes whether (and where) a given point lies on or near a polyline, @@ -336,12 +336,12 @@ class PolygonUtil { if (closedPolygon) { // Add a small offset to the last point for Douglas-Peucker on polygons // (see #201) - const OFFSET = 0.00000000001; + const offset = 0.00000000001; lastPoint = poly.last; // LatLng.latitude and .longitude are immutable, so replace the last point poly.removeLast(); poly.add( - LatLng(lastPoint.latitude + OFFSET, lastPoint.longitude + OFFSET)); + LatLng(lastPoint.latitude + offset, lastPoint.longitude + offset)); } int idx; diff --git a/pubspec.yaml b/pubspec.yaml index 90b3efb..23e8132 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.0 +version: 2.0.1 homepage: https://github.com/kb0/maps_toolkit/ environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.17.0 <3.0.0" dependencies: dev_dependencies: - pedantic: '>=1.8.0 <3.0.0' - test: any + lints: ^2.0.0 + test: ^1.21.0 diff --git a/test/maps_toolkit_test.dart b/test/maps_toolkit_test.dart index 1894d40..1ca00a1 100644 --- a/test/maps_toolkit_test.dart +++ b/test/maps_toolkit_test.dart @@ -364,6 +364,13 @@ void main() { SphericalUtil.computeArea([right, down, front, up, right]), closeTo( pi * SphericalUtil.earthRadius * SphericalUtil.earthRadius, .4)); + + final p1 = LatLng(45.153474463955796, 39.33852195739747); + final p2 = LatLng(45.153474463955796, 39.33972358703614); + final p3 = LatLng(45.15252112936569, 39.33972358703614); + final p4 = LatLng(45.1525022138355, 39.3385460972786); + + expect(SphericalUtil.computeArea([p1, p2, p3, p4, p1]), closeTo(9987, 1)); }); test('testComputeSignedArea', () { diff --git a/test/polygon_util_test.dart b/test/polygon_util_test.dart index deaae1f..7f5734f 100644 --- a/test/polygon_util_test.dart +++ b/test/polygon_util_test.dart @@ -135,10 +135,10 @@ void main() { }); test('simplify polygon', () { - const POLYGON_LINE = + const polygonLine = 'elfjD~a}uNOnFN~Em@fJv@tEMhGDjDe@hG^nF??@lA?n@IvAC`Ay@A{@DwCA{CF_EC{CEi@PBTFDJBJ?V?n@?D@?A@?@?F?F?LAf@?n@@`@@T@~@FpA?fA?p@?r@?vAH`@OR@^ETFJCLD?JA^?J?P?fAC`B@d@?b@A\\@`@Ad@@\\?`@?f@?V?H?DD@DDBBDBD?D?B?B@B@@@B@B@B@D?D?JAF@H@FCLADBDBDCFAN?b@Af@@x@@'; - final line = PolygonUtil.decode(POLYGON_LINE); + final line = PolygonUtil.decode(polygonLine); expect(line.length, equals(95)); final data = [ @@ -191,10 +191,10 @@ void main() { }); test('simplify polygon - oval', () { - const POLYGON_OVAL = + const polygonOval = '}wgjDxw_vNuAd@}AN{A]w@_Au@kAUaA?{@Ke@@_@C]D[FULWFOLSNMTOVOXO\\I\\CX?VJXJTDTNXTVVLVJ`@FXA\\AVLZBTATBZ@ZAT?\\?VFT@XGZ'; - final oval = PolygonUtil.decode(POLYGON_OVAL); + final oval = PolygonUtil.decode(polygonOval); expect(PolygonUtil.isClosedPolygon(oval), equals(false)); final simplifiedOval10 = PolygonUtil.simplify(oval, 10);