From 1259c9acd97041517a11adce8b284668a499a978 Mon Sep 17 00:00:00 2001 From: Jonas Siedentop Date: Thu, 1 Feb 2024 12:16:40 +0100 Subject: [PATCH] release 0.0.9 (#164) * initial null-safety implementation * attributes non-nullable + tests, fix meta tests * make altitude for Position and BBox nullable * update action deps, build runner * delete conflicting outputs, dart test on PR action * Strongly type and refactor geomEach meta function This commit also renames Geometry to GeometryObject * simplify geomEach * Add coverage reporting to pull requests tests * Allow PR coverage comment to fail This allows PRs from forks to still run the tests successfully * Refactor coverage reporting into its own job The coverage job is allowed to continue on error, letting the entire workflow 'pass' if we hit issues running or reporting coverage * Move coverage reporting into separate workflow * geomEach: nullable fields #36 * fix types in tests * Update to latest romeovs/lcov-reporter-action This should resolve an issue where the 'comment code coverage on PR' action fails after being merged into main. See https://github.com/romeovs/lcov-reporter-action/issues/16 * raise version for release 0.0.3 * [meta] add implementation and test for featureEach and propEach (#24) * Assemble different types, refactor GeoJSON serialization, general improvements (#43) * #19, #20, #21, refactor * convert GeoJSONObjectType to enum, rename * rm overridden bboxes * Implement vector operations #23 * statically type 'round' helper func, fix unit test * gen coverage * fix typo * geojson unit tests, type fixes * fix deserialization with GeoJSONObjectType, implement hashCode * initial unit tests for new constructors * integration tests * fix path * test bbox on other geojson types * update enum tests * required params for new constructors, unit tests * license notices * bump version for release * Add basic benchmarking framework (#51) * Add pub version badge * [meta] add coordeach implementation (#50) * [meta] add coordeach implementation * [benchmark] add coordeach benchmark using test fixtures * Add implementation for getCoord & getCoords // invariant package (#53) * initial getCoord & getCoords implementation * WIP test coords/coord * test gitpod flutter config * ports invariants package (#62) * dart pub get added * wip, type problem * fixed return error of the test * Gitpod config * new test cases, changed comments * standardized the comments * wrapped List in brackets * some minor typo edit * added highlight in documentation * formatted conflicting files * deleted the gitpod files Co-authored-by: Arman Torkzaban Co-authored-by: arman Co-authored-by: arman Co-authored-by: Arman Torkzaban * Add flattenEach function and tests (#48) * Add flattenEach function and tests * Refactor flattenEach slightly * Refactor meta -- breaking of iterations tests * Explicitly do not support nested GeometryCollections * Update documentation links * Use more specific type checks in flattenEach test * rm duplicate fcMixed * remove geometryCollection clause * warning for nested GeometryCollection Co-authored-by: Lukas Himsel * refactor coordEach with geomEach, change type in geomEach callback (#68) * [meta] add coordeach implementation * Rework coordEach implementation to match setup more from geomEach * cleanup * optimize for geometry collection * refactor coordEach with geomEach, change type in geomEach callback Co-authored-by: Tobrun Van Nuland * Port coordAll function and test, also: refactor coordEach callback (#64) * beginning * wip coordAll * coordAll test, WIP * changes CoordEachCallback's signature * typecast removed, test corrected * changes before merging * refactor for Position in CoordEachCallback Co-authored-by: Lukas Himsel * Update README.md * Feature reducers (#49) * Temporarily type geomEach callback to GeometryType * Add geomReduce function and tests * propReduce function * WIP - featureReduce() * WIP * added examples and documentations * flattenReduce WIP * WIP * coordReduce * documentation * add static types * merge readme * prepare new merge * generic types for all reducer functions * TurfJS compatible solution with type checks * add cloning * fixed types passed to callbacks, propReduce test * flattenReduce and featureReduce test * coordReduce * minor type conv. num to int Co-authored-by: Arman Torkzaban Co-authored-by: Lukas Himsel * Port cluster functions and tests (#69) * port functions * getCluster documentation * WIP documentation * Did the documentation * wrote tests * benchmarks - in process * moved benchmarks to separate file * exported clusters.dart Co-authored-by: armantorkzaban * Port meta segment functions & lineSegment (#70) * initial commit to segment file * beginning * lineSegment() * lineSegment * refactor * lineSegment tests * polygon test * wip segmentEach * rewrite segmentEach witohut coordEach * fix flattenEachCallback * combine units * tests for segmentEach * segmentEach id check tests * segmentReduce impltd. * updated README * Documentation * benchmark init Co-authored-by: Arman Torkzaban * split up meta into separate files (#72) * Meta functions extension methods (#73) * initial setup * fix export, add all *each functions * implement 'other' functions * implement *reduce functions * fix tests * rm geojson param for reducers * Update functions and packages in README.md (#67) * WIP - updating README.md * missing new functions & packages * helpers function aint needed anymore - constructor * Links added and unnecessary funtioncs deleted Co-authored-by: Lukas Himsel * Raise version to 0.0.5 * Documentation (#75) * in process - early analysis of the work * linked the meta functions in readme * CONTRIBUTING.md * links to the sources * edited typos * documentation work * closes #77, closes #16 * proofread * improves pub.dev score, closes #79, #78, #75 * Added deleted model, complemented contributing.md Co-authored-by: Lukas Himsel * raise to version 0.0.6 * Improve pub score & raise to version 0.0.6+2 (#82) * add examples, fix segment * callbacks * raise version to 0.0.6+2 * Improve pub score (rename example file, raise to 0.0.6+3) (#84) * add examples, fix segment * callbacks * raise version to 0.0.6+2 * Rename example file, raise to 0.0.6+3 * Implement `nearestPointOn(Multi)Line` and `internal` intersects helper (Attempt 2) (#87) * Implement `nearestPointOn(Multi)Line` (#86) Co-authored-by: Levente Morva * localIndex and index * add documentation * Fix `globalIndex` behaviour Co-authored-by: Levente Morva * fix test, according to new globalIndex behaviour * add intersection test Co-authored-by: Levente Morva * Port explode function and test (#93) * initial version without tests * closes #93 * updated readme for explode * fixed formatting Co-authored-by: armantorkzaban * Merge bbox-polygon and bbox, center, polyline decode (#99) * Added coordEach translation * Added bBox translation * Added center translation * Added decode points from polyline * Update read me * Remove and exclude .idea from git indexing * Convert double to Position * Use existing coord each implementation * Return bBox points in the correct order * Add bbox unit test * Change libraries namespaces * Code refactor * Add doc blocs and some more missing functions * Add encode polyline feature * Add tests for both encode and decode polylines * Add bbox tests * Add helper functions * Convert array to Bbox * Remove redundant helper functions * Add documentation * implementation * tests init, documentation, addition of types and debug * implemented, docs * test initiation * added it to /lib, updated readme, can close 97 * renamed the test file * comments resolved * typo * unused lib removed * merge bbox-polygon * missing center_test.dart * imported bbox_polygon to center_test * test error fixes Co-authored-by: Dennis Mwea Co-authored-by: Lukas Himsel * Added missing alt1, alt2 in BBox constructor, BBox put in README (#100) * Added coordEach translation * Added bBox translation * Added center translation * Added decode points from polyline * Update read me * Remove and exclude .idea from git indexing * Convert double to Position * Use existing coord each implementation * Return bBox points in the correct order * Add bbox unit test * Change libraries namespaces * Code refactor * Add doc blocs and some more missing functions * Add encode polyline feature * Add tests for both encode and decode polylines * Add bbox tests * Add helper functions * Convert array to Bbox * Remove redundant helper functions * Add documentation * implementation * tests init, documentation, addition of types and debug * implemented, docs * test initiation * added it to /lib, updated readme, can close 97 * renamed the test file * comments resolved * typo * unused lib removed * merge bbox-polygon * missing center_test.dart * imported bbox_polygon to center_test * test error fixes * added alt 1,2 to Bbox * added bbox to readme * Fix typos * bbox constructure changed to standard * bbox optional positional param. set accordingly * Documentation on limitation of optional prms. Bbox * Update geojson.dart * fix order of BBox default constructor in test * update doc comment * fix previously missed null exceptions Co-authored-by: Dennis Mwea Co-authored-by: Lukas Himsel * Implement rhumbBearing function and test (#109) * initial commit, stolen from @armantorkzaban * fix formatting * cleanup comments * Ports lineToPolygon, polygonToLine, and their tests (#104) * line_to_polygon ported * test init of lineToPolygon * debugging the test on line to polygon * line_to_polygon_test done * polygonToLine init * check for features' tyope in FeatureCollections * file name change * test and impl. done for polygonToLine * refactor autocomplete, lineStringToPolygon * comments resolved * type added * implementation and test and type setting Co-authored-by: Lukas Himsel * Adds proper documentation to feature-conversion Part I (#115) * line_to_polygon ported * test init of lineToPolygon * debugging the test on line to polygon * line_to_polygon_test done * polygonToLine init * check for features' tyope in FeatureCollections * file name change * test and impl. done for polygonToLine * refactor autocomplete, lineStringToPolygon * comments resolved * type added * implementation and test and type setting * corrected documentation Co-authored-by: Lukas Himsel * Update impl status of feature conversion package * Ports truncate package and its test (#111) * implemented * test init * moving on with the test * test finished. * comments resolved * add truncate reference * Ports clean_coords and its test (#112) * init * implemented * test init - imported * test, moving on * implemented points in comments * resolving comments * test done * readme updated, js removed * fix turf_equality dep, replace forEach with for * update types * trying to fix mutation * refactor, fix tests * another variance * simplified, cleaned comments * seems like it works! Co-authored-by: Lukas Himsel * Debugs GeometryCollection condition in truncate (#121) * implemented * test init * moving on with the test * test finished. * comments resolved * updated readme.md * changed from forEach to for and used the element * changed forEach to a for loop * variable name changed - resolving a comment * rid of redundant case for GeometryCollection, test Co-authored-by: Lukas Himsel * close #116 - add src path to README * update changelog, bump version for release * Added support for the area function (#123) * Added the area function * made the geometry to be of type GeometryType * fixed the test and added a benchmark test * fixed the area docs * added some more tests * Marked functions as private and fixed documentation * fixed documentation * added exception in case of unsupported geometry type, formatted the code and removed some redundant code Co-authored-by: yarden * Implement polygon-smooth and its tests (#127) * initial implementation, and refactor * finished test and benchmark impl * reference in README * Port boolean functions and tests (#91) * in process - early analysis of the work * linked the meta functions in readme * CONTRIBUTING.md * links to the sources * edited typos * documentation work * closes #77, closes #16 * proofread * improves pub.dev score, closes #79, #78, #75 * Added deleted model, complemented contributing.md * booleans init * initial import * boolean_touches * valid - wip * within - init * rewiring the translated code * contains etc. * touches * valid * dependencies imported * Update CONTRIBUTING.md * clockwise test * concave test * intersect test * pointOnLine test * contains * crosses_test - blocked by findIntersections * boolean_contain * boolean_within * rhumb_bearing * rhumb_bearing\'s test - incomplete * rhumb_bearing's test - done, added to lib/bearing * boolean_contains, boolean_parallel, IP * working on contain - removed usages of runtimeType * rewriting pointInLine * tests reverted to false/true folder style * restructuring, clean-up * clockwise and its test, documentation * concave finalized * PointInPolygon plus test, dart format * removed the commented JS lines * return type added * disjoint and test - not done, depends on sweepline * equal implement, test, has dependencies * moving on * clean coords init * cleanCoord implemented, going to new branch * moving on with equal * update turf_equality dep * moving forward * refactors boolean_equal * #88 crosses, disjoint, equal, intersects, pip @lukas-h * cleanup on #88 * progress on overlap * bool: overlap,parallel,valid,touches & lineOverlap * issue with test is worked on * still at porting the overlap test * done: parallel * working on valid * touches done * valid - got stuck * progress on within * moved on with valid, refactored * valid test * lineIntersection testet - contains sweepline * package publishabe, rm git deps, fix equality dep * update params in equality * mod. on valid to cover the std. - MutiPs' 'finite' * RFCs resolved - readied for merge * return type of getGeom * linter effect! * reolved requests * more requests resolved * more requests resolved * test name, touching lineOverlap * fix conversations in booleanContains * fixes conversations in crosses and disjoint * resolves allllllllll outdated conversations, refactor * use getGeom in booleanTouches * use getGeom more frequently * rm linter rule, which is already inherited from dartclub_lint * cleanup, ready for merge Co-authored-by: Lukas Himsel * Add missing parameter 'unit'. (#145) * Implement rhumb_distance with tests. * Implement rhumb_destination with tests. * Implement centroid with tests. * Implement transform_rotate with tests. * Add truncate tests for MultiLineString, MultiPoint, MultiPolygon * run dart format * introduce localCoordIndex in coordEach, cover more test cases in truncate_test * prepare for next release, support * work student position * Fix excludeWrapCoord in coordEach for MultiPolygon type. (#148) * Fix excludeWrapCoord in coordEach for MultiPolygon type. * Added multipolygon test case for centroid. * format markdown * Document properties set by NearestPointOnLine on returned Point (#155) * Implement length and along (#153) * Implement length with tests * Implement along with tests * Fix export added functions * Document along behaviour when distance is outside line length range * Format along test * Change length and along to accept Feature instead of LineString * Change length to never return null. To my understanding, the reason why segmentReduce in its signature may return null is due to initialValue may be null, but in length() we supply 0.0 as the default. * Change along to throw Exception when empty line is passed instead of returning null It appears to be more in line with how turf.js operates and also existing error handling in turf_dart. * Change along to count from back when distance is negative I raised an issue with turf.js about behavour being undefined when distance is zero and they where in favour of counting from back behavour over clamping to the end. I think it is best to use same behavour as upstream turf.js so changing to their solution. * Update along test for negative distance * Fix along test for negative distance * Add along test using default unit * Add test of length() using default unit * Fix docs for along() when distance is negative * Change along() implementation to handle travelled == distance eagerly * Fix length_test.dart formatting (#159) * Change return type of along to Feature (#161) This goes along with preferring to pass around full Features, and it allow to in the future set properties on the returned point without it being a breaking change. * Prepare release 0.0.9 (#162) * Update Dart SDK version in pubspec.yaml * Update README.md * Remove .DS_Store files * Update changelog * Update package version to 0.0.9 * Update dependencies * Entfernt .DS_Store * Remove job offer --------- Co-authored-by: Lukas Himsel Co-authored-by: Brad Parham Co-authored-by: Tobrun Co-authored-by: arman Co-authored-by: arman Co-authored-by: Arman Torkzaban Co-authored-by: Levente Morva Co-authored-by: Dennis Mwea Co-authored-by: yardenfi Co-authored-by: yarden Co-authored-by: Kangmin An Co-authored-by: ggastv Co-authored-by: L Linse Co-authored-by: Leif Linse <118986082+leiflinse-trivector@users.noreply.github.com> --- .gitignore | 1 + CHANGELOG.md | 8 +- README.md | 12 ++- lib/along.dart | 3 + lib/length.dart | 3 + lib/src/along.dart | 54 ++++++++++++ lib/src/length.dart | 25 ++++++ lib/src/nearest_point_on_line.dart | 7 ++ lib/turf.dart | 2 + pubspec.yaml | 15 ++-- test/.DS_Store | Bin 6148 -> 0 bytes test/components/along_test.dart | 98 ++++++++++++++++++++++ test/components/length_test.dart | 36 ++++++++ test/examples/.DS_Store | Bin 10244 -> 0 bytes test/examples/booleans/.DS_Store | Bin 8196 -> 0 bytes test/examples/booleans/disjoint/.DS_Store | Bin 6148 -> 0 bytes 16 files changed, 249 insertions(+), 15 deletions(-) create mode 100644 lib/along.dart create mode 100644 lib/length.dart create mode 100644 lib/src/along.dart create mode 100644 lib/src/length.dart delete mode 100644 test/.DS_Store create mode 100644 test/components/along_test.dart create mode 100644 test/components/length_test.dart delete mode 100644 test/examples/.DS_Store delete mode 100644 test/examples/booleans/.DS_Store delete mode 100644 test/examples/booleans/disjoint/.DS_Store diff --git a/.gitignore b/.gitignore index 360fc0f5..bd71dd88 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ coverage/ .idea/ +.DS_Store \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 36864a3f..4f825f79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.0.9 + +- Implements `length`, `along` [#153](https://github.com/dartclub/turf_dart/pull/153) +- Documentation: Improves pub.dev scores by fixing bad links in Readme.md + ## 0.0.8 - Implements `transformRotate`, `rhumbDistance`, `rhumbDestination`, `centroid` [#147](https://github.com/dartclub/turf_dart/pull/147) @@ -38,7 +43,8 @@ ## 0.0.5 -- Implements *all* meta functions and`lineSegment` + +- Implements *all* meta functions and `lineSegment` - Adds a lot of documentation - Several bug and type fixes diff --git a/README.md b/README.md index a20a98f7..180e7c94 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # turf.dart -ℹ️ Looking for maintainers as a work student position in Germany: Write an email to [jobs@scalabs.de](mailto:jobs@scalabs.de) ℹ️ - [![pub package](https://img.shields.io/pub/v/turf.svg)](https://pub.dev/packages/turf) THIS PROJECT IS WORK IN PROCESS @@ -80,7 +78,7 @@ Any new benchmarks must be named `*_benchmark.dart` and reside in the ### Measurement -- [ ] along +- [x] [along](https://github.com/dartclub/turf_dart/blob/main/lib/src/along.dart) - [x] [area](https://github.com/dartclub/turf_dart/blob/main/lib/src/area.dart) - [x] [bbox](https://github.com/dartclub/turf_dart/blob/main/lib/src/bbox.dart) - [x] [bboxPolygon](https://github.com/dartclub/turf_dart/blob/main/lib/src/bbox_polygon.dart) @@ -91,7 +89,7 @@ Any new benchmarks must be named `*_benchmark.dart` and reside in the - [x] [destination](https://github.com/dartclub/turf_dart/blob/main/lib/src/destination.dart) - [x] [distance](https://github.com/dartclub/turf_dart/blob/main/lib/src/distance.dart) - [ ] envelope -- [ ] length +- [x] [length](https://github.com/dartclub/turf_dart/blob/main/lib/src/length.dart) - [x] [midpoint](https://github.com/dartclub/turf_dart/blob/main/lib/src/midpoint.dart) - [ ] pointOnFeature - [ ] polygonTangents @@ -123,7 +121,7 @@ Any new benchmarks must be named `*_benchmark.dart` and reside in the - [ ] dissolve - [ ] intersect - [ ] lineOffset -- [x] [polygonSmooth](ttps://github.com/dartclub/turf_dart/blob/main/lib/src/polygon_smooth.dart) +- [x] [polygonSmooth](https://github.com/dartclub/turf_dart/blob/main/lib/src/polygon_smooth.dart) - [ ] simplify - [ ] tesselate - [x] [transformRotate](https://github.com/dartclub/turf_dart/blob/main/lib/src/transform_rotate.dart) @@ -234,7 +232,7 @@ Any new benchmarks must be named `*_benchmark.dart` and reside in the - [x] [booleanCrosses](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_crosses.dart) - [x] [booleanDisjoint](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_disjoint.dart) - [x] [booleanEqual](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_equal.dart) -- [x] [booleanIntersects](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_intersect.dart) +- [x] [booleanIntersects](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_intersects.dart) - [ ] booleanOverlap - [x] [booleanParallel](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_parallel.dart) - [x] [booleanPointInPolygon](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_point_in_polygon.dart) @@ -252,4 +250,4 @@ Any new benchmarks must be named `*_benchmark.dart` and reside in the - [x] [radiansToLength](https://github.com/dartclub/turf_dart/blob/main/lib/src/helpers.dart) - [x] [radiansToDegrees](https://github.com/dartclub/turf_dart/blob/main/lib/src/helpers.dart) - [ ] toMercator -- [ ] toWgs84 +- [ ] toWgs84 \ No newline at end of file diff --git a/lib/along.dart b/lib/along.dart new file mode 100644 index 00000000..d8d18fa5 --- /dev/null +++ b/lib/along.dart @@ -0,0 +1,3 @@ +library turf_along; + +export "src/along.dart"; diff --git a/lib/length.dart b/lib/length.dart new file mode 100644 index 00000000..fa72f3ee --- /dev/null +++ b/lib/length.dart @@ -0,0 +1,3 @@ +library turf_length; + +export "src/length.dart"; diff --git a/lib/src/along.dart b/lib/src/along.dart new file mode 100644 index 00000000..f4b50267 --- /dev/null +++ b/lib/src/along.dart @@ -0,0 +1,54 @@ +import 'dart:math'; + +import 'package:turf/bearing.dart'; +import 'package:turf/destination.dart'; +import 'package:turf/helpers.dart'; +import 'package:turf/length.dart'; +import 'package:turf/src/distance.dart' as measure_distance; +import 'package:turf/src/invariant.dart'; + +/// Takes a [line] and returns a [Point] at a specified [distance] along the line. +/// +/// If [distance] is less than 0, it will count distance along the line from end +/// to start of line. If negative [distance] overshoots the length of the line, +/// the start point of the line is returned. +/// If [distance] is larger than line length, the end point is returned +/// If [line] have no geometry or coordinates, an Exception is thrown +Feature along(Feature line, num distance, + [Unit unit = Unit.kilometers]) { + // Get Coords + final coords = getCoords(line); + if (coords.isEmpty) { + throw Exception('line must contain at least one coordinate'); + } + if (distance < 0) { + distance = max(0, length(line, unit) + distance); + } + num travelled = 0; + for (int i = 0; i < coords.length; i++) { + if (distance >= travelled && i == coords.length - 1) { + break; + } + if (travelled == distance) { + return Feature(geometry: Point(coordinates: coords[i])); + } + if (travelled > distance) { + final overshot = distance - travelled; + final direction = bearing(Point(coordinates: coords[i]), + Point(coordinates: coords[i - 1])) - + 180; + final interpolated = destination( + Point(coordinates: coords[i]), + overshot, + direction, + unit, + ); + return Feature(geometry: interpolated); + } else { + travelled += measure_distance.distance(Point(coordinates: coords[i]), + Point(coordinates: coords[i + 1]), unit); + } + } + return Feature( + geometry: Point(coordinates: coords[coords.length - 1])); +} diff --git a/lib/src/length.dart b/lib/src/length.dart new file mode 100644 index 00000000..b7d5e1f7 --- /dev/null +++ b/lib/src/length.dart @@ -0,0 +1,25 @@ +import 'package:turf/distance.dart'; +import 'package:turf/helpers.dart'; +import 'package:turf/line_segment.dart'; + +/// Takes a [line] and measures its length in the specified [unit]. +num length(Feature line, [Unit unit = Unit.kilometers]) { + return segmentReduce(line, ( + previousValue, + currentSegment, + initialValue, + featureIndex, + multiFeatureIndex, + geometryIndex, + segmentIndex, + ) { + final coords = currentSegment.geometry!.coordinates; + return previousValue! + + distance( + Point(coordinates: coords[0]), + Point(coordinates: coords[1]), + unit, + ); + }, 0.0) ?? + 0.0; +} diff --git a/lib/src/nearest_point_on_line.dart b/lib/src/nearest_point_on_line.dart index 12554074..4656bef1 100644 --- a/lib/src/nearest_point_on_line.dart +++ b/lib/src/nearest_point_on_line.dart @@ -183,6 +183,13 @@ _NearestMulti? _nearestPointOnMultiLine( } /// Takes a [Point] and a [LineString] and calculates the closest Point on the [LineString]. +/// +/// The properties of returned [Point] will contain three values: +/// * index: closest point was found on nth line part +/// * dist: distance between [point] and the closest point on line +/// * location: distance along the line between start and the closest point. +/// +/// Example: /// ```dart /// var line = LineString( /// coordinates: [ diff --git a/lib/turf.dart b/lib/turf.dart index 01f1bc68..25d03aea 100644 --- a/lib/turf.dart +++ b/lib/turf.dart @@ -1,5 +1,6 @@ library turf; +export 'src/along.dart'; export 'src/area.dart'; export 'src/bbox.dart'; export 'src/bearing.dart'; @@ -9,6 +10,7 @@ export 'src/destination.dart'; export 'src/distance.dart'; export 'src/geojson.dart'; export 'src/helpers.dart'; +export 'src/length.dart'; export 'src/midpoint.dart'; export 'src/nearest_point.dart'; export 'src/polyline.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index d2f9c492..26a6587b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,22 +1,23 @@ name: turf description: A turf.js-like geospatial analysis library working with GeoJSON, written in pure Dart. -version: 0.0.8 +version: 0.0.9 environment: - sdk: ">=2.15.0 <4.0.0" + sdk: ">=2.17.0 <4.0.0" homepage: https://github.com/dartclub/turf_dart repository: https://github.com/dartclub/turf_dart dependencies: json_annotation: ^4.8.1 - turf_equality: ^0.0.2 - turf_pip: ^0.0.1+1 + + turf_equality: ^0.0.3 + turf_pip: ^0.0.2 rbush: ^1.1.0 - sweepline_intersections: ^0.0.3+1 + sweepline_intersections: ^0.0.4 dev_dependencies: - lints: ^2.1.1 + lints: ^3.0.0 test: ^1.24.3 json_serializable: ^6.7.0 build_runner: ^2.4.5 - analyzer: ^5.13.0 + analyzer: ^6.4.0 benchmark: ^0.3.0 diff --git a/test/.DS_Store b/test/.DS_Store deleted file mode 100644 index 8dca1b0c6041d6f51c12453d5fe1b56c21e4e4b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~O=}ZD7{{M!qn)$}IVkiZ40sJSZSWAhtg#-vc1t~|#NFl5p16K8oKMkF#&sj_=_? zVXu)>LYk_VrMcXQ4jq9&An?BtaFaVFgI`HY^EWL`iihQe;Tinsr#1WdlGftWSvB_Y z-_vnfRCTZSL+tFf?%dszd-6cOjX#)KTqpIk8YYw1+&VX=OmFH*dQs%FQRn`1qwA#5 z`NSp^S&oo5uL_-++0aaNR@vOx4al}^k2;6*dB6XptBy|wi>{gvPI_H6=noc)wtVpD z@zb->$MQ;>FZRhvV4bpd&+CnRMP=i?KE)GV8vPz)oVQPxpmarJlp3rw)o!g@V)YGi ztE_VRj8&1dn6F(Mf5nT3e~aH5wrd>L*tS6^p#n^gC_`;RHSZ!zr1&3NCW~gUTM_Vc zK_1-dDj_)#2n4o~0Iv@U&Kh}boZ6)Wg*^g5Tj;iiI)5^7j`A9LZJc5RCR{4ir3!z< z5H214%Ev`s8>cRvgg<-;e`n!OD8k+y*H<>2MC3G-fj}UzN?_MDJG}qD`1ARHH7T?L zfk0rZ2#D5cd^*G{`Mq`H<#?}E@ON-Fj%%FS6cm0twiVur58>7@rnmx)yf#kJ0}CGl M7DFfkfqzQi8kGOR@Bjb+ diff --git a/test/components/along_test.dart b/test/components/along_test.dart new file mode 100644 index 00000000..f2c9d304 --- /dev/null +++ b/test/components/along_test.dart @@ -0,0 +1,98 @@ +import 'package:test/test.dart'; +import 'package:turf/along.dart'; +import 'package:turf/distance.dart'; +import 'package:turf/helpers.dart'; +import 'package:turf/length.dart'; + +void main() { + test('along - negative distance should count backwards', () { + final viaToEndDistance = + distance(Point(coordinates: via), Point(coordinates: end), Unit.meters); + expect(viaToEndDistance.round(), equals(198)); + final resolvedViaPoint = along(line, -1 * viaToEndDistance, Unit.meters); + expect(resolvedViaPoint.geometry, isNotNull); + expect(resolvedViaPoint.geometry!.coordinates, equals(via)); + }); + test('along - to start point', () { + final resolvedStartPoint = along(line, 0, Unit.meters); + expect(resolvedStartPoint.geometry, isNotNull); + expect(resolvedStartPoint.geometry!.coordinates, equals(start)); + }); + test('along - to point between start and via', () { + final startToViaDistance = distance( + Point(coordinates: start), Point(coordinates: via), Unit.meters); + expect(startToViaDistance.round(), equals(57)); + final resolvedViaPoint = along(line, startToViaDistance / 2, Unit.meters); + expect(resolvedViaPoint.geometry, isNotNull); + expect(resolvedViaPoint.geometry!.coordinates.lat.toStringAsFixed(6), + equals('55.709028')); + expect(resolvedViaPoint.geometry!.coordinates.lng.toStringAsFixed(6), + equals('13.185096')); + }); + test('along - to via point', () { + final startToViaDistance = distance( + Point(coordinates: start), Point(coordinates: via), Unit.meters); + expect(startToViaDistance.round(), equals(57)); + final resolvedViaPoint = along(line, startToViaDistance, Unit.meters); + expect(resolvedViaPoint.geometry, isNotNull); + expect(resolvedViaPoint.geometry!.coordinates, equals(via)); + }); + test('along - to point between via and end', () { + final startToViaDistance = distance( + Point(coordinates: start), Point(coordinates: via), Unit.meters); + final viaToEndDistance = + distance(Point(coordinates: via), Point(coordinates: end), Unit.meters); + expect(startToViaDistance.round(), equals(57)); + expect(viaToEndDistance.round(), equals(198)); + final resolvedViaPoint = + along(line, startToViaDistance + viaToEndDistance / 2, Unit.meters); + expect(resolvedViaPoint.geometry, isNotNull); + expect(resolvedViaPoint.geometry!.coordinates.lat.toStringAsFixed(6), + equals('55.708330')); + expect(resolvedViaPoint.geometry!.coordinates.lng.toStringAsFixed(6), + equals('13.186555')); + }); + test('along - to end point', () { + final len = length(line, Unit.meters); + expect(len.round(), equals(254)); + final resolvedEndPoint = along(line, len, Unit.meters); + expect(resolvedEndPoint.geometry, isNotNull); + expect(resolvedEndPoint.geometry!.coordinates, equals(end)); + }); + test('along - to end point - default unit (km)', () { + final len = length(line); + expect((len * 1000).round(), equals(254)); + final resolvedEndPoint = along(line, len); + expect(resolvedEndPoint.geometry, isNotNull); + expect(resolvedEndPoint.geometry!.coordinates, equals(end)); + }); + test('along - beyond end point', () { + final len = length(line, Unit.meters); + expect(len.round(), equals(254)); + final resolvedEndPoint = along(line, len + 100, Unit.meters); + expect(resolvedEndPoint.geometry, isNotNull); + expect(resolvedEndPoint.geometry!.coordinates, equals(end)); + }); +} + +final start = Position.named( + lat: 55.7090430186194, + lng: 13.184645393920405, +); +final via = Position.named( + lat: 55.70901279569489, + lng: 13.185546616182755, +); +final end = Position.named( + lat: 55.70764669578079, + lng: 13.187563637197076, +); +final line = Feature( + geometry: LineString( + coordinates: [ + start, + via, + end, + ], + ), +); diff --git a/test/components/length_test.dart b/test/components/length_test.dart new file mode 100644 index 00000000..d93278fc --- /dev/null +++ b/test/components/length_test.dart @@ -0,0 +1,36 @@ +import 'package:test/test.dart'; +import 'package:turf/helpers.dart'; +import 'package:turf/length.dart'; + +void main() { + test('length - in meters', () { + final len = length(line, Unit.meters); + expect(len.round(), equals(254)); + }); + test('length - default unit (km)', () { + final len = length(line); + expect((len * 1000).round(), equals(254)); + }); +} + +final start = Position.named( + lat: 55.7090430186194, + lng: 13.184645393920405, +); +final via = Position.named( + lat: 55.70901279569489, + lng: 13.185546616182755, +); +final end = Position.named( + lat: 55.70764669578079, + lng: 13.187563637197076, +); +final line = Feature( + geometry: LineString( + coordinates: [ + start, + via, + end, + ], + ), +); diff --git a/test/examples/.DS_Store b/test/examples/.DS_Store deleted file mode 100644 index 0c63b13f2fe9cae5a682169f7d851bde0585b08c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10244 zcmeHM&u$Vy82^T1SyCH0*u+bdO^k_$s`QU-h!>=IF!5ld(SsUf%L;^Lhb&NPnkJm} z4LtY?UVQ+cz(n7|2k@l7Z)PE|3!z$LO*_-fd^@w>Z)fK>znSef5RoYKs_R5H5n0G= zGnY|JNqnDkEG5F0RagN$J@n+h<4FhgOw8Lf7zPXjh5^HXVZbo(KQMrAHYaOITT>ba z3E3XFMnDS%eXa2m=pcD|ZrkZB1zyFbu>Q;MhG$4*nz^M&kGTxOe-f zN(y*Ic}eofr3(2}rhTA%lodK4H-dhT#kqQNwA1gj!?S}=PTOmAy4mbEkyuDxT1;6f zYsq?9s>^<(DK#PkIa9 zpCg~~qR#yr${~Bu8p&V_|cBG#lv3>%oO)&ieRoxAlAC-0e0b_U4^$p$i%}jq3)l&liu*SGk0Vo21ft|3hgXSBJ z=BcMzMvd$tGUNjs!vs7Cp?lv?dFuhKfL1^&pcT*xXazPw0o=2x8Q3nJO`uq~p9v?ud1T zbBU4;Owxg=D>GH0FmZL{nZg}dU81&H0j)q<0jk~e&;}nk+DQG*+pf=DoTVSs9qc#G zM8hM19Qtwy(6-=|s{NSvyM(u)yhrHmAuEjgv#SYzI{OgMAJUtIl=tf&d%Kfxpzi#= zJMg`5R4#vFnXT;hrJRv7c8q8C5uezj)@U3yTEi#w=^^L7yEtySkG$^0DeT?l!Kmd0 z-Ju|Ooi4gOee4AtK56iA&$a$UBANbXv8lCG+4`ZB{a;)_%EU)~biIS>CvO z?dI(V&avMQ_$yoiHl|V;?8?teODjxhaB2?&p9ejnVK<;7-m|1Ejws4; q#N{7`cx<98aq0@^5^)6EUw;vB{%7!&d$QjD<4=lu{}&LZhaa-3!n@+bRdJA)_EfC?Wee~pFO#_ z_wXr+v%Fsa5T%9k;?lBQmMikwzt?>~5At5t3c8onJJUJ|M|KdN$DMw=x^}43Jc!dy z*CfPI2Sctd;xy9zmhPodW^#QyAS<%cu5Jtl&Ar{4+G`AJYS7%>si{W2-W(1qa(#1q z|Fr#(Jf`}^%nStn$3|8ij^GuI@w}h?Zkp)y4t=BeQ5+*Pzzi@0e}MtFcgdB%@Ui@j z%m6bmR|aT*P^g5S!@{E3I3Ds{XhQs{y&|>J!XIz_*V>w z@{xbk!YR4hIx{({wF>nHm4xC7i{lhDOew}#D#aV9M$oUwK=d3I7SV&k2LVF^H_X6X G8TbOms$y{f