Skip to content

Commit

Permalink
Change along() implementation to handle travelled == distance eagerly
Browse files Browse the repository at this point in the history
  • Loading branch information
leiflinse-trivector committed Jan 25, 2024
1 parent 3aa2e19 commit 1092b64
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/src/along.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ Point along(Feature<LineString> line, num distance,
for (int i = 0; i < coords.length; i++) {
if (distance >= travelled && i == coords.length - 1) {
break;
} else if (travelled >= distance) {
}
if (travelled == distance) {
return Point(coordinates: coords[i]);
}
if (travelled > distance) {
final overshot = distance - travelled;
if (overshot == 0) {
return Point(coordinates: coords[i]);
} else {
final direction = bearing(Point(coordinates: coords[i]),
Point(coordinates: coords[i - 1])) -
180;
final interpolated = destination(
Point(coordinates: coords[i]),
overshot,
direction,
unit,
);
return interpolated;
}
final direction = bearing(Point(coordinates: coords[i]),
Point(coordinates: coords[i - 1])) -
180;
final interpolated = destination(
Point(coordinates: coords[i]),
overshot,
direction,
unit,
);
return interpolated;
} else {
travelled += measure_distance.distance(Point(coordinates: coords[i]),
Point(coordinates: coords[i + 1]), unit);
Expand Down

0 comments on commit 1092b64

Please sign in to comment.