Skip to content

Commit

Permalink
Fix some changes got lost in a previous rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
leiflinse-trivector committed Jan 30, 2024
1 parent 7f04587 commit fbe8e2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/src/line_slice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:turf/src/invariant.dart';
/// as the resolved line would only contain one point which isn't supported by LineString.
///
/// This can be useful for extracting only the part of a route between waypoints.
Feature<LineString> lineSlice(
Feature<LineString>? lineSlice(
Point startPt, Point stopPt, Feature<LineString> line) {
final coords = line.geometry;
if (coords == null) {
Expand All @@ -19,7 +19,7 @@ Feature<LineString> lineSlice(

final startVertex = nearestPointOnLine(coords, startPt);
final stopVertex = nearestPointOnLine(coords, stopPt);
if (startVertex['index'] == stopVertex['index']) {
if (startVertex.properties!['index'] == stopVertex.properties!['index']) {
// LineString do not allow 1 point lines
return null;
}
Expand All @@ -31,7 +31,7 @@ Feature<LineString> lineSlice(
}
final List<Position> clipCoords = [getCoord(ends[0])];
for (var i = ends[0].properties!['index'] + 1;
i < ends[1].properties!['index'] + 1;
i < ends[1].properties!['index'];
i++) {
clipCoords.add(coords.coordinates[i]);
}
Expand Down
8 changes: 6 additions & 2 deletions test/components/line_slice_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ void main() {
test('lineSlice - exact points', () {
final slice = lineSlice(
Point(coordinates: start), Point(coordinates: via), lineFeature);
expect(slice.properties, isNotNull);
expect(slice, isNotNull);
expect(slice!.properties, isNotNull);
expect(slice.properties!.keys, contains(propName));
expect(slice.properties![propName], equals(propValue));

final expectedLineFeature = Feature<LineString>(
geometry: LineString(coordinates: [start, via]),
);
expect(slice.geometry, isNotNull);
expect(slice.geometry!.coordinates, hasLength(2));
expect(length(slice).round(), equals(length(expectedLineFeature).round()));
});
test('lineSlice - interpolation', () {
Expand All @@ -26,14 +28,16 @@ void main() {
expect(startPt, isNotNull);

final slice = lineSlice(startPt, Point(coordinates: via), lineFeature);
expect(slice.properties, isNotNull);
expect(slice, isNotNull);
expect(slice!.properties, isNotNull);
expect(slice.properties!.keys, contains(propName));
expect(slice.properties![propName], equals(propValue));

final expectedLine = Feature<LineString>(
geometry: LineString(coordinates: [start, via]),
);
expect(slice.geometry, isNotNull);
expect(slice.geometry!.coordinates, hasLength(2));
expect(
length(slice, Unit.meters).round(),
equals(length(expectedLine, Unit.meters).round() - skipDist),
Expand Down

0 comments on commit fbe8e2d

Please sign in to comment.