diff --git a/README.md b/README.md
index 1d17e05..ff86c22 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-
+
A TurfJs-like geospatial analysis library written in pure Dart.
diff --git a/benchmark/explode_benchmark.dart b/benchmark/explode_benchmark.dart
index 52f1808..1e916ae 100644
--- a/benchmark/explode_benchmark.dart
+++ b/benchmark/explode_benchmark.dart
@@ -1,5 +1,4 @@
import 'package:benchmark/benchmark.dart';
-import 'package:turf/src/explode.dart';
import 'package:turf/turf.dart';
var poly = Polygon(coordinates: [
diff --git a/benchmark/line_segment_benchmark.dart b/benchmark/line_segment_benchmark.dart
index b15ed89..0bdd982 100644
--- a/benchmark/line_segment_benchmark.dart
+++ b/benchmark/line_segment_benchmark.dart
@@ -1,6 +1,5 @@
import 'package:benchmark/benchmark.dart';
import 'package:turf/line_segment.dart';
-import 'package:turf/helpers.dart';
void main() {
LineString lineString = LineString(
diff --git a/lib/along.dart b/lib/along.dart
index d8d18fa..ab16ced 100644
--- a/lib/along.dart
+++ b/lib/along.dart
@@ -1,3 +1,4 @@
library turf_along;
+export 'package:geotypes/geotypes.dart';
export "src/along.dart";
diff --git a/lib/area.dart b/lib/area.dart
index ebd1ae1..2bf3755 100644
--- a/lib/area.dart
+++ b/lib/area.dart
@@ -1,3 +1,4 @@
library turf_area;
+export 'package:geotypes/geotypes.dart';
export "src/area.dart";
diff --git a/lib/bbox.dart b/lib/bbox.dart
index 22703d2..0e4de60 100644
--- a/lib/bbox.dart
+++ b/lib/bbox.dart
@@ -1,3 +1,4 @@
library turf_bbox;
+export 'package:geotypes/geotypes.dart';
export "src/bbox.dart";
diff --git a/lib/bbox_polygon.dart b/lib/bbox_polygon.dart
index 3c5c846..de41f44 100644
--- a/lib/bbox_polygon.dart
+++ b/lib/bbox_polygon.dart
@@ -1,3 +1,4 @@
library turf_bbox_polygon.dart;
+export 'package:geotypes/geotypes.dart';
export 'src/bbox_polygon.dart';
diff --git a/lib/bearing.dart b/lib/bearing.dart
index 64c1d49..fffd2e8 100644
--- a/lib/bearing.dart
+++ b/lib/bearing.dart
@@ -1,4 +1,5 @@
library turf_bearing;
+export 'package:geotypes/geotypes.dart';
export 'src/bearing.dart';
export 'src/rhumb_bearing.dart';
diff --git a/lib/boolean.dart b/lib/boolean.dart
index 87e99c3..7642b66 100644
--- a/lib/boolean.dart
+++ b/lib/boolean.dart
@@ -1,5 +1,6 @@
library turf_boolean;
+export 'package:geotypes/geotypes.dart';
export 'src/booleans/boolean_clockwise.dart';
export 'src/booleans/boolean_concave.dart';
export 'src/booleans/boolean_contains.dart';
diff --git a/lib/center.dart b/lib/center.dart
index 898d82d..afc3874 100644
--- a/lib/center.dart
+++ b/lib/center.dart
@@ -1,3 +1,4 @@
library turf_center;
+export 'package:geotypes/geotypes.dart';
export 'src/center.dart';
diff --git a/lib/centroid.dart b/lib/centroid.dart
index 9cf9ee5..f1c3a64 100644
--- a/lib/centroid.dart
+++ b/lib/centroid.dart
@@ -1,3 +1,4 @@
library turf_centroid;
+export 'package:geotypes/geotypes.dart';
export 'src/centroid.dart';
diff --git a/lib/clean_coords.dart b/lib/clean_coords.dart
index 7c61dea..701cd62 100644
--- a/lib/clean_coords.dart
+++ b/lib/clean_coords.dart
@@ -1,3 +1,4 @@
-library clean_coords.dart;
+library turf_clean_coords;
+export 'package:geotypes/geotypes.dart';
export 'src/clean_coords.dart';
diff --git a/lib/clusters.dart b/lib/clusters.dart
index 5e7bdea..35e6c5f 100644
--- a/lib/clusters.dart
+++ b/lib/clusters.dart
@@ -1,3 +1,4 @@
library turf_clusters;
+export 'package:geotypes/geotypes.dart';
export 'src/meta/cluster.dart';
diff --git a/lib/destination.dart b/lib/destination.dart
index 72965b4..8d420ec 100644
--- a/lib/destination.dart
+++ b/lib/destination.dart
@@ -1,4 +1,5 @@
library turf_destination;
+export 'package:geotypes/geotypes.dart';
export 'src/destination.dart';
export 'src/rhumb_destination.dart';
diff --git a/lib/distance.dart b/lib/distance.dart
index 0debc57..e29087e 100644
--- a/lib/distance.dart
+++ b/lib/distance.dart
@@ -1,4 +1,5 @@
library turf_distance;
+export 'package:geotypes/geotypes.dart';
export 'src/distance.dart';
export 'src/rhumb_distance.dart';
diff --git a/lib/explode.dart b/lib/explode.dart
index babaf58..02e4907 100644
--- a/lib/explode.dart
+++ b/lib/explode.dart
@@ -1,3 +1,4 @@
-library explode;
+library turf_explode;
+export 'package:geotypes/geotypes.dart';
export 'src/explode.dart';
diff --git a/lib/extensions.dart b/lib/extensions.dart
index a0d2885..290e424 100644
--- a/lib/extensions.dart
+++ b/lib/extensions.dart
@@ -1,3 +1,4 @@
library turf_extensions;
+export 'package:geotypes/geotypes.dart';
export 'src/meta/extensions.dart';
diff --git a/lib/helpers.dart b/lib/helpers.dart
index 9398f68..a12bd6f 100644
--- a/lib/helpers.dart
+++ b/lib/helpers.dart
@@ -1,4 +1,4 @@
library turf_helpers;
+export 'package:geotypes/geotypes.dart';
export 'src/helpers.dart';
-export 'src/geojson.dart';
diff --git a/lib/invariant.dart b/lib/invariant.dart
new file mode 100644
index 0000000..5718d5d
--- /dev/null
+++ b/lib/invariant.dart
@@ -0,0 +1,4 @@
+library turf_invariant;
+
+export 'package:geotypes/geotypes.dart';
+export 'src/invariant.dart';
diff --git a/lib/length.dart b/lib/length.dart
index fa72f3e..0bb3599 100644
--- a/lib/length.dart
+++ b/lib/length.dart
@@ -1,3 +1,4 @@
library turf_length;
+export 'package:geotypes/geotypes.dart';
export "src/length.dart";
diff --git a/lib/line_intersect.dart b/lib/line_intersect.dart
new file mode 100644
index 0000000..b77315b
--- /dev/null
+++ b/lib/line_intersect.dart
@@ -0,0 +1,4 @@
+library turf_line_intersect;
+
+export 'package:geotypes/geotypes.dart';
+export "src/line_intersect.dart";
diff --git a/lib/line_overlap.dart b/lib/line_overlap.dart
index ba4c093..6aabe6f 100644
--- a/lib/line_overlap.dart
+++ b/lib/line_overlap.dart
@@ -1,3 +1,4 @@
library turf_line_overlap;
+export 'package:geotypes/geotypes.dart';
export "src/line_overlap.dart";
diff --git a/lib/line_segment.dart b/lib/line_segment.dart
index 8afc634..c839627 100644
--- a/lib/line_segment.dart
+++ b/lib/line_segment.dart
@@ -1,3 +1,4 @@
library turf_line_segment;
+export 'package:geotypes/geotypes.dart';
export "src/line_segment.dart";
diff --git a/lib/line_slice.dart b/lib/line_slice.dart
index dafdd38..694f675 100644
--- a/lib/line_slice.dart
+++ b/lib/line_slice.dart
@@ -1,3 +1,4 @@
-library turf_along;
+library turf_line_slice;
+export 'package:geotypes/geotypes.dart';
export "src/line_slice.dart";
diff --git a/lib/line_to_polygon.dart b/lib/line_to_polygon.dart
index 1dfc8be..2209a6d 100644
--- a/lib/line_to_polygon.dart
+++ b/lib/line_to_polygon.dart
@@ -1,3 +1,4 @@
-library turf_line_to_polygon.dart;
+library turf_line_to_polygon;
+export 'package:geotypes/geotypes.dart';
export 'src/line_to_polygon.dart';
diff --git a/lib/meta.dart b/lib/meta.dart
index 4aaa43b..399bbb0 100644
--- a/lib/meta.dart
+++ b/lib/meta.dart
@@ -1,5 +1,6 @@
library turf_meta;
+export 'package:geotypes/geotypes.dart';
export 'src/meta/cluster.dart';
export 'src/meta/coord.dart';
export 'src/meta/feature.dart';
diff --git a/lib/midpoint.dart b/lib/midpoint.dart
index acd6524..528a03a 100644
--- a/lib/midpoint.dart
+++ b/lib/midpoint.dart
@@ -1,3 +1,4 @@
library turf_midpoint;
+export 'package:geotypes/geotypes.dart';
export 'src/midpoint.dart';
diff --git a/lib/nearest_point.dart b/lib/nearest_point.dart
index ed2a2e9..1467c71 100644
--- a/lib/nearest_point.dart
+++ b/lib/nearest_point.dart
@@ -1,3 +1,4 @@
library turf_nearest_point;
+export 'package:geotypes/geotypes.dart';
export 'src/nearest_point.dart';
diff --git a/lib/nearest_point_on_line.dart b/lib/nearest_point_on_line.dart
index 71d7ebc..ad1e6c3 100644
--- a/lib/nearest_point_on_line.dart
+++ b/lib/nearest_point_on_line.dart
@@ -1,3 +1,4 @@
library turf_nearest_point_on_line;
+export 'package:geotypes/geotypes.dart';
export 'src/nearest_point_on_line.dart';
diff --git a/lib/polygon_smooth.dart b/lib/polygon_smooth.dart
index 7d38df1..a9331d6 100644
--- a/lib/polygon_smooth.dart
+++ b/lib/polygon_smooth.dart
@@ -1,3 +1,4 @@
library turf_polygon_smooth;
+export 'package:geotypes/geotypes.dart';
export 'src/polygon_smooth.dart';
diff --git a/lib/polygon_to_line.dart b/lib/polygon_to_line.dart
index 0b38e83..a79f7f3 100644
--- a/lib/polygon_to_line.dart
+++ b/lib/polygon_to_line.dart
@@ -1,3 +1,4 @@
library turf_polygon_to_line;
+export 'package:geotypes/geotypes.dart';
export 'src/polygon_to_line.dart';
diff --git a/lib/polyline.dart b/lib/polyline.dart
index 8ef7e96..760395f 100644
--- a/lib/polyline.dart
+++ b/lib/polyline.dart
@@ -1,3 +1,4 @@
library turf_polyline;
+export 'package:geotypes/geotypes.dart';
export 'src/polyline.dart';
diff --git a/lib/src/along.dart b/lib/src/along.dart
index f4b5026..5912431 100644
--- a/lib/src/along.dart
+++ b/lib/src/along.dart
@@ -4,8 +4,8 @@ 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';
+import 'distance.dart' as measure_distance;
+import 'invariant.dart';
/// Takes a [line] and returns a [Point] at a specified [distance] along the line.
///
@@ -24,16 +24,16 @@ Feature along(Feature line, num distance,
if (distance < 0) {
distance = max(0, length(line, unit) + distance);
}
- num travelled = 0;
+ num traveled = 0;
for (int i = 0; i < coords.length; i++) {
- if (distance >= travelled && i == coords.length - 1) {
+ if (distance >= traveled && i == coords.length - 1) {
break;
}
- if (travelled == distance) {
+ if (traveled == distance) {
return Feature(geometry: Point(coordinates: coords[i]));
}
- if (travelled > distance) {
- final overshot = distance - travelled;
+ if (traveled > distance) {
+ final overshot = distance - traveled;
final direction = bearing(Point(coordinates: coords[i]),
Point(coordinates: coords[i - 1])) -
180;
@@ -45,7 +45,7 @@ Feature along(Feature line, num distance,
);
return Feature(geometry: interpolated);
} else {
- travelled += measure_distance.distance(Point(coordinates: coords[i]),
+ traveled += measure_distance.distance(Point(coordinates: coords[i]),
Point(coordinates: coords[i + 1]), unit);
}
}
diff --git a/lib/src/bbox.dart b/lib/src/bbox.dart
index a7d37ab..7ac1bb4 100644
--- a/lib/src/bbox.dart
+++ b/lib/src/bbox.dart
@@ -1,4 +1,3 @@
-import 'package:turf/helpers.dart';
import 'package:turf/meta.dart';
/// Calculates the bounding box for any [geoJson] object, including [FeatureCollection].
diff --git a/lib/src/bearing.dart b/lib/src/bearing.dart
index f979375..4fe7504 100644
--- a/lib/src/bearing.dart
+++ b/lib/src/bearing.dart
@@ -1,7 +1,6 @@
import 'dart:math';
-
-import 'geojson.dart';
import 'helpers.dart';
+import 'package:geotypes/geotypes.dart';
// http://en.wikipedia.org/wiki/Haversine_formula
// http://www.movable-type.co.uk/scripts/latlong.html
diff --git a/lib/src/booleans/boolean_contains.dart b/lib/src/booleans/boolean_contains.dart
index 171baaa..3e1b6b7 100644
--- a/lib/src/booleans/boolean_contains.dart
+++ b/lib/src/booleans/boolean_contains.dart
@@ -1,4 +1,3 @@
-import 'package:turf/src/invariant.dart';
import 'package:turf/turf.dart';
import 'boolean_helper.dart';
diff --git a/lib/src/booleans/boolean_crosses.dart b/lib/src/booleans/boolean_crosses.dart
index 54ccdc5..2ee2064 100644
--- a/lib/src/booleans/boolean_crosses.dart
+++ b/lib/src/booleans/boolean_crosses.dart
@@ -4,11 +4,12 @@ import '../../helpers.dart';
import '../line_intersect.dart';
import '../polygon_to_line.dart';
import 'boolean_point_in_polygon.dart';
+import 'boolean_point_on_line.dart';
/// [booleanCrosses] returns [true] if the intersection results in a geometry whose
/// dimension is one less than the maximum dimension of the two source geometries
/// and the intersection set is interior to both source geometries.
-/// [booleanCsses] returns [true] for only [MultiPoint]/[Polygon], [MultiPoint]/[LineString],
+/// [booleanCrosses] returns [true] for only [MultiPoint]/[Polygon], [MultiPoint]/[LineString],
/// [LineString]/[LineString], [LineString]/[Polygon], and [LineString]/[MultiPolygon] comparisons.
/// Other comparisons are not supported as they are outside the OpenGIS Simple
/// [Feature]s spec and may give unexpected results.
@@ -31,7 +32,7 @@ bool booleanCrosses(GeoJSONObject feature1, GeoJSONObject feature2) {
var geom1 = getGeom(feature1);
var geom2 = getGeom(feature2);
- var exception = Exception("$geom2 is not supperted");
+ var exception = Exception("$geom2 is not supported");
if (geom1 is MultiPoint) {
if (geom2 is LineString) {
return _doMultiPointAndLineStringCross(geom1, geom2);
@@ -78,7 +79,7 @@ bool _doMultiPointAndLineStringCross(
if (i2 == 0 || i2 == lineString.coordinates.length - 2) {
incEndVertices = false;
}
- if (isPointOnLineSegment(
+ if (isPointOnLineSegmentCrossesVariant(
lineString.coordinates[i2],
lineString.coordinates[i2 + 1],
multiPoint.coordinates[i],
@@ -102,7 +103,7 @@ bool _doLineStringsCross(LineString lineString1, LineString lineString2) {
if (i2 == 0 || i2 == lineString2.coordinates.length - 2) {
incEndVertices = false;
}
- if (isPointOnLineSegment(
+ if (isPointOnLineSegmentCrossesVariant(
lineString1.coordinates[i],
lineString1.coordinates[i + 1],
lineString2.coordinates[i2],
@@ -137,44 +138,3 @@ bool _doesMultiPointCrossPoly(MultiPoint multiPoint, Polygon polygon) {
return foundExtPoint && foundIntPoint;
}
-
-/// Only takes into account outer rings
-/// See http://stackoverflow.com/a/4833823/1979085
-/// lineSegmentStart [Position] of start of line
-/// lineSegmentEnd [Position] of end of line
-/// pt [Position] of point to check
-/// [incEnd] controls whether the [Point] is allowed to fall on the line ends
-bool isPointOnLineSegment(
- Position lineSegmentStart,
- Position lineSegmentEnd,
- Position pt,
- bool incEnd,
-) {
- var dxc = pt[0]! - lineSegmentStart[0]!;
- var dyc = pt[1]! - lineSegmentStart[1]!;
- var dxl = lineSegmentEnd[0]! - lineSegmentStart[0]!;
- var dyl = lineSegmentEnd[1]! - lineSegmentStart[1]!;
- var cross = dxc * dyl - dyc * dxl;
- if (cross != 0) {
- return false;
- }
- if (incEnd) {
- if ((dxl).abs() >= (dyl).abs()) {
- return dxl > 0
- ? lineSegmentStart[0]! <= pt[0]! && pt[0]! <= lineSegmentEnd[0]!
- : lineSegmentEnd[0]! <= pt[0]! && pt[0]! <= lineSegmentStart[0]!;
- }
- return dyl > 0
- ? lineSegmentStart[1]! <= pt[1]! && pt[1]! <= lineSegmentEnd[1]!
- : lineSegmentEnd[1]! <= pt[1]! && pt[1]! <= lineSegmentStart[1]!;
- } else {
- if ((dxl).abs() >= (dyl).abs()) {
- return dxl > 0
- ? lineSegmentStart[0]! < pt[0]! && pt[0]! < lineSegmentEnd[0]!
- : lineSegmentEnd[0]! < pt[0]! && pt[0]! < lineSegmentStart[0]!;
- }
- return dyl > 0
- ? lineSegmentStart[1]! < pt[1]! && pt[1]! < lineSegmentEnd[1]!
- : lineSegmentEnd[1]! < pt[1]! && pt[1]! < lineSegmentStart[1]!;
- }
-}
diff --git a/lib/src/booleans/boolean_disjoint.dart b/lib/src/booleans/boolean_disjoint.dart
index ff104ca..0920f44 100644
--- a/lib/src/booleans/boolean_disjoint.dart
+++ b/lib/src/booleans/boolean_disjoint.dart
@@ -1,10 +1,8 @@
-import 'package:turf/src/booleans/boolean_crosses.dart';
-
-import '../../helpers.dart';
+import 'boolean_point_on_line.dart';
+import 'boolean_point_in_polygon.dart';
import '../../meta.dart';
import '../line_intersect.dart';
import '../polygon_to_line.dart';
-import 'boolean_point_in_polygon.dart';
/// Returns [true] if the intersection of the two geometries is an empty set.
/// example:
@@ -73,7 +71,7 @@ bool _disjoint(GeometryType geom1, GeometryType geom2) {
// http://stackoverflow.com/a/11908158/1979085
bool _isPointOnLine(LineString lineString, Point pt) {
for (var i = 0; i < lineString.coordinates.length - 1; i++) {
- if (isPointOnLineSegment(lineString.coordinates[i],
+ if (isPointOnLineSegmentCrossesVariant(lineString.coordinates[i],
lineString.coordinates[i + 1], pt.coordinates, true)) {
return true;
}
diff --git a/lib/src/booleans/boolean_intersects.dart b/lib/src/booleans/boolean_intersects.dart
index 2c97870..695452a 100644
--- a/lib/src/booleans/boolean_intersects.dart
+++ b/lib/src/booleans/boolean_intersects.dart
@@ -1,4 +1,3 @@
-import '../../helpers.dart';
import '../../meta.dart';
import 'boolean_disjoint.dart';
diff --git a/lib/src/booleans/boolean_overlap.dart b/lib/src/booleans/boolean_overlap.dart
index c4f4f36..5a12df5 100644
--- a/lib/src/booleans/boolean_overlap.dart
+++ b/lib/src/booleans/boolean_overlap.dart
@@ -1,4 +1,3 @@
-import 'package:turf/helpers.dart';
import 'package:turf/line_overlap.dart';
import 'package:turf/line_segment.dart';
import 'package:turf/src/invariant.dart';
diff --git a/lib/src/booleans/boolean_point_on_line.dart b/lib/src/booleans/boolean_point_on_line.dart
index ffc0dd5..e1e8187 100644
--- a/lib/src/booleans/boolean_point_on_line.dart
+++ b/lib/src/booleans/boolean_point_on_line.dart
@@ -41,22 +41,30 @@ bool booleanPointOnLine(Point pt, LineString line,
return false;
}
+// ToDo: These variants of isPointOnLineSegment have the
+// potential to be brought together.
+
// See http://stackoverflow.com/a/4833823/1979085
// See https://stackoverflow.com/a/328122/1048847
-/// [pt] is the coord pair of the [Point] to check.
+/// [point] is the coord pair of the [Point] to check.
/// [excludeBoundary] controls whether the point is allowed to fall on the line ends.
/// [epsilon] is the Fractional number to compare with the cross product result.
/// Useful for dealing with floating points such as lng/lat points.
-bool _isPointOnLineSegment(Position lineSegmentStart, Position lineSegmentEnd,
- Position pt, BoundaryType excludeBoundary, num? epsilon) {
- var x = pt[0]!;
- var y = pt[1]!;
- var x1 = lineSegmentStart[0];
- var y1 = lineSegmentStart[1];
- var x2 = lineSegmentEnd[0];
- var y2 = lineSegmentEnd[1];
- var dxc = pt[0]! - x1!;
- var dyc = pt[1]! - y1!;
+bool _isPointOnLineSegment(
+ Position start,
+ Position end,
+ Position point,
+ BoundaryType excludeBoundary,
+ num? epsilon,
+) {
+ var x = point[0]!;
+ var y = point[1]!;
+ var x1 = start[0];
+ var y1 = start[1];
+ var x2 = end[0];
+ var y2 = end[1];
+ var dxc = point[0]! - x1!;
+ var dyc = point[1]! - y1!;
var dxl = x2! - x1;
var dyl = y2! - y1;
var cross = dxc * dyl - dyc * dxl;
@@ -90,3 +98,74 @@ bool _isPointOnLineSegment(Position lineSegmentStart, Position lineSegmentEnd,
}
return false;
}
+
+/// Returns if [point] is on the segment between [start] and [end].
+/// Borrowed from `booleanPointOnLine` to speed up the evaluation (instead of
+/// using the module as dependency).
+/// [start] is the coord pair of start of line, [end] is the coord pair of end
+/// of line, and [point] is the coord pair of point to check.
+bool isPointOnLineSegmentCleanCoordsVariant(
+ Position start,
+ Position end,
+ Position point,
+) {
+ var x = point.lat;
+ var y = point.lng;
+ var startX = start.lat, startY = start.lng;
+ var endX = end.lat, endY = end.lng;
+
+ var dxc = x - startX;
+ var dyc = y - startY;
+ var dxl = endX - startX;
+ var dyl = endY - startY;
+ var cross = dxc * dyl - dyc * dxl;
+
+ if (cross != 0) {
+ return false;
+ } else if ((dxl).abs() >= (dyl).abs()) {
+ return dxl > 0 ? startX <= x && x <= endX : endX <= x && x <= startX;
+ } else {
+ return dyl > 0 ? startY <= y && y <= endY : endY <= y && y <= startY;
+ }
+}
+
+/// Only takes into account outer rings
+/// See http://stackoverflow.com/a/4833823/1979085
+/// lineSegmentStart [Position] of start of line
+/// lineSegmentEnd [Position] of end of line
+/// pt [Position] of point to check
+/// [incEnd] controls whether the [Point] is allowed to fall on the line ends
+bool isPointOnLineSegmentCrossesVariant(
+ Position start,
+ Position end,
+ Position pt,
+ bool incEnd,
+) {
+ var dxc = pt[0]! - start[0]!;
+ var dyc = pt[1]! - start[1]!;
+ var dxl = end[0]! - start[0]!;
+ var dyl = end[1]! - start[1]!;
+ var cross = dxc * dyl - dyc * dxl;
+ if (cross != 0) {
+ return false;
+ }
+ if (incEnd) {
+ if ((dxl).abs() >= (dyl).abs()) {
+ return dxl > 0
+ ? start[0]! <= pt[0]! && pt[0]! <= end[0]!
+ : end[0]! <= pt[0]! && pt[0]! <= start[0]!;
+ }
+ return dyl > 0
+ ? start[1]! <= pt[1]! && pt[1]! <= end[1]!
+ : end[1]! <= pt[1]! && pt[1]! <= start[1]!;
+ } else {
+ if ((dxl).abs() >= (dyl).abs()) {
+ return dxl > 0
+ ? start[0]! < pt[0]! && pt[0]! < end[0]!
+ : end[0]! < pt[0]! && pt[0]! < start[0]!;
+ }
+ return dyl > 0
+ ? start[1]! < pt[1]! && pt[1]! < end[1]!
+ : end[1]! < pt[1]! && pt[1]! < start[1]!;
+ }
+}
diff --git a/lib/src/booleans/boolean_valid.dart b/lib/src/booleans/boolean_valid.dart
index 5a06e74..cd37dac 100644
--- a/lib/src/booleans/boolean_valid.dart
+++ b/lib/src/booleans/boolean_valid.dart
@@ -4,7 +4,6 @@ import 'package:turf/src/booleans/boolean_point_on_line.dart';
import 'package:turf/src/invariant.dart';
import 'package:turf/src/meta/extensions.dart';
-import '../../helpers.dart';
import '../line_intersect.dart';
import 'boolean_crosses.dart';
diff --git a/lib/src/centroid.dart b/lib/src/centroid.dart
index 33874ad..73f7666 100644
--- a/lib/src/centroid.dart
+++ b/lib/src/centroid.dart
@@ -1,7 +1,7 @@
-import 'package:turf/helpers.dart';
import 'package:turf/meta.dart';
-/// Takes a [Feature] or a [FeatureCollection] and computes the centroid as the mean of all vertices within the object.
+/// Takes a [Feature] or a [FeatureCollection] and computes the centroid as
+/// the mean of all vertices within the object.
///
/// example:
/// ```dart
diff --git a/lib/src/clean_coords.dart b/lib/src/clean_coords.dart
index 41989a6..78596bd 100644
--- a/lib/src/clean_coords.dart
+++ b/lib/src/clean_coords.dart
@@ -1,4 +1,5 @@
import '../helpers.dart';
+import 'booleans/boolean_point_on_line.dart';
import 'invariant.dart';
/// Removes redundant coordinates from any [GeometryType].
@@ -95,8 +96,10 @@ List _cleanLine(List coords, GeoJSONObject geojson) {
newPoints.add(coords[i]);
newPointsLength = newPoints.length;
if (newPointsLength > 2) {
- if (isPointOnLineSegment(newPoints[newPointsLength - 3],
- newPoints[newPointsLength - 1], newPoints[newPointsLength - 2])) {
+ if (isPointOnLineSegmentCleanCoordsVariant(
+ newPoints[newPointsLength - 3],
+ newPoints[newPointsLength - 1],
+ newPoints[newPointsLength - 2])) {
newPoints.removeAt(newPoints.length - 2);
}
}
@@ -112,34 +115,9 @@ List _cleanLine(List coords, GeoJSONObject geojson) {
throw Exception("invalid polygon");
}
- if (isPointOnLineSegment(newPoints[newPointsLength - 3],
+ if (isPointOnLineSegmentCleanCoordsVariant(newPoints[newPointsLength - 3],
newPoints[newPointsLength - 1], newPoints[newPointsLength - 2])) {
newPoints.removeAt(newPoints.length - 2);
}
return newPoints;
}
-
-/// Returns if [point] is on the segment between [start] and [end].
-/// Borrowed from `booleanPointOnLine` to speed up the evaluation (instead of
-/// using the module as dependency).
-/// [start] is the coord pair of start of line, [end] is the coord pair of end
-/// of line, and [point] is the coord pair of point to check.
-bool isPointOnLineSegment(Position start, Position end, Position point) {
- var x = point.lat, y = point.lng;
- var startX = start.lat, startY = start.lng;
- var endX = end.lat, endY = end.lng;
-
- var dxc = x - startX;
- var dyc = y - startY;
- var dxl = endX - startX;
- var dyl = endY - startY;
- var cross = dxc * dyl - dyc * dxl;
-
- if (cross != 0) {
- return false;
- } else if ((dxl).abs() >= (dyl).abs()) {
- return dxl > 0 ? startX <= x && x <= endX : endX <= x && x <= startX;
- } else {
- return dyl > 0 ? startY <= y && y <= endY : endY <= y && y <= startY;
- }
-}
diff --git a/lib/src/destination.dart b/lib/src/destination.dart
index 48461b9..3dfb8bd 100644
--- a/lib/src/destination.dart
+++ b/lib/src/destination.dart
@@ -1,6 +1,5 @@
import 'dart:math';
-
-import 'geojson.dart';
+import 'package:geotypes/geotypes.dart';
import 'helpers.dart';
Position destinationRaw(Position origin, num distance, num bearing,
diff --git a/lib/src/distance.dart b/lib/src/distance.dart
index f8bd526..39e042c 100644
--- a/lib/src/distance.dart
+++ b/lib/src/distance.dart
@@ -1,6 +1,6 @@
import 'dart:math';
-import 'geojson.dart';
+import 'package:geotypes/geotypes.dart';
import 'helpers.dart';
//http://en.wikipedia.org/wiki/Haversine_formula
diff --git a/lib/src/explode.dart b/lib/src/explode.dart
index b2e0811..b381486 100644
--- a/lib/src/explode.dart
+++ b/lib/src/explode.dart
@@ -1,8 +1,7 @@
-import 'package:turf/helpers.dart';
import 'package:turf/meta.dart';
/// Takes a feature or set of features and returns all positions as [Point]s.
-/// Takes [GeoJSONObhect] input.
+/// Takes [GeoJSONObject] input.
/// Returns [FeatureCollection] representing the exploded input features
/// Throws [Exception] if it encounters an unknown geometry type
/// ```dart
diff --git a/lib/src/geojson.dart b/lib/src/geojson.dart
deleted file mode 100644
index 24af095..0000000
--- a/lib/src/geojson.dart
+++ /dev/null
@@ -1 +0,0 @@
-export 'package:geotypes/geotypes.dart';
diff --git a/lib/src/intersection.dart b/lib/src/intersection.dart
index 72ecf35..f8af3e7 100644
--- a/lib/src/intersection.dart
+++ b/lib/src/intersection.dart
@@ -1,4 +1,5 @@
-import 'geojson.dart';
+// internal functions, not meant to be exposed
+import 'package:geotypes/geotypes.dart';
Point? intersects(LineString line1, LineString line2) {
if (line1.coordinates.length != 2) {
diff --git a/lib/src/line_overlap.dart b/lib/src/line_overlap.dart
index 51d6ab6..5c7ecca 100644
--- a/lib/src/line_overlap.dart
+++ b/lib/src/line_overlap.dart
@@ -1,9 +1,12 @@
import 'package:rbush/rbush.dart';
+import 'package:turf/boolean.dart';
import 'package:turf/line_segment.dart';
import 'package:turf/meta.dart';
import 'package:turf/src/booleans/boolean_helper.dart';
-import 'package:turf/turf.dart';
+import '../helpers.dart';
+import 'destination.dart';
import 'invariant.dart';
+import 'nearest_point_on_line.dart';
/// Takes any [LineString], [MultiLineString], [Polygon] or [MultiPolygon] and
/// returns the overlapping lines between both features.
diff --git a/lib/src/line_segment.dart b/lib/src/line_segment.dart
index 02df7ad..444a4e8 100644
--- a/lib/src/line_segment.dart
+++ b/lib/src/line_segment.dart
@@ -1,7 +1,6 @@
-import 'package:turf/src/meta/coord.dart';
-import 'package:turf/src/meta/flatten.dart';
-
-import 'geojson.dart';
+import 'meta/coord.dart';
+import 'meta/flatten.dart';
+import 'package:geotypes/geotypes.dart';
/// Creates a [FeatureCollection] of 2-vertex [LineString] segments from a
/// [LineString] or [MultiLineString] or [Polygon] and [MultiPolygon]
diff --git a/lib/src/line_slice.dart b/lib/src/line_slice.dart
index cbd53b2..d5fdf94 100644
--- a/lib/src/line_slice.dart
+++ b/lib/src/line_slice.dart
@@ -1,6 +1,7 @@
-import 'package:turf/helpers.dart';
-import 'package:turf/nearest_point_on_line.dart';
-import 'package:turf/src/invariant.dart';
+import 'package:geotypes/geotypes.dart';
+
+import 'nearest_point_on_line.dart';
+import 'invariant.dart';
/// Takes a [line], at a start point [startPt], and a stop point [stopPt]
/// and returns a subsection of the line in-between those points.
diff --git a/lib/src/line_to_polygon.dart b/lib/src/line_to_polygon.dart
index eed0aa7..d76072e 100644
--- a/lib/src/line_to_polygon.dart
+++ b/lib/src/line_to_polygon.dart
@@ -1,5 +1,4 @@
import 'package:turf/bbox.dart';
-import 'package:turf/helpers.dart';
import 'package:turf/meta.dart';
import 'package:turf/src/invariant.dart';
diff --git a/lib/src/midpoint.dart b/lib/src/midpoint.dart
index 7176457..e571348 100644
--- a/lib/src/midpoint.dart
+++ b/lib/src/midpoint.dart
@@ -1,7 +1,7 @@
import 'bearing.dart';
import 'destination.dart';
import 'distance.dart';
-import 'geojson.dart';
+import 'package:geotypes/geotypes.dart';
Position midpointRaw(Position point1, Position point2) {
var dist = distanceRaw(point1, point2);
@@ -12,7 +12,8 @@ Position midpointRaw(Position point1, Position point2) {
}
/// Takes two [Point]s and returns a point midway between them.
-/// The midpoint is calculated geodesically, meaning the curvature of the earth is taken into account.
+/// The midpoint is calculated geodesically, meaning the curvature of the
+/// earth is taken into account.
/// For example:
///
/// ```
diff --git a/lib/src/nearest_point.dart b/lib/src/nearest_point.dart
index afd1b94..60253d1 100644
--- a/lib/src/nearest_point.dart
+++ b/lib/src/nearest_point.dart
@@ -1,5 +1,5 @@
import 'distance.dart';
-import 'geojson.dart';
+import 'package:geotypes/geotypes.dart';
/// Takes a reference [Point] and a FeatureCollection of Features
/// with Point geometries and returns the
diff --git a/lib/src/nearest_point_on_line.dart b/lib/src/nearest_point_on_line.dart
index 1e037be..fe5c90f 100644
--- a/lib/src/nearest_point_on_line.dart
+++ b/lib/src/nearest_point_on_line.dart
@@ -1,9 +1,9 @@
import 'dart:math';
+import 'package:geotypes/geotypes.dart';
import 'bearing.dart';
import 'destination.dart';
import 'distance.dart';
-import 'geojson.dart';
import 'helpers.dart';
import 'intersection.dart';
diff --git a/lib/src/rhumb_destination.dart b/lib/src/rhumb_destination.dart
index b901632..c94c1a2 100644
--- a/lib/src/rhumb_destination.dart
+++ b/lib/src/rhumb_destination.dart
@@ -4,8 +4,8 @@ import 'package:turf/helpers.dart';
import 'package:turf/src/invariant.dart';
///
-/// Returns the destination [Point] having travelled the given distance along a Rhumb line from the
-/// origin Point with the (varant) given bearing.
+/// Returns the destination [Point] having traveled the given distance along a Rhumb line from the
+/// origin Point with the (variant) given bearing.
///
/// example:
/// ```dart
@@ -62,7 +62,7 @@ Position calculateRhumbDestination(Position origin, num distance, num bearing,
final dPhi = delta * math.cos(theta);
var phi2 = phi1 + dPhi;
- // check for some daft bugger going past the pole, normalise latitude if so
+ // check for some daft bugger going past the pole, normalize latitude if so
if (phi2.abs() > math.pi / 2) {
phi2 = phi2 > 0 ? math.pi - phi2 : -math.pi - phi2;
}
@@ -75,7 +75,7 @@ Position calculateRhumbDestination(Position origin, num distance, num bearing,
final dLambda = (delta * math.sin(theta)) / q;
final lambda2 = lambda1 + dLambda;
- // normalise to −180..+180°
+ // normalize to −180..+180°
final lng = (((lambda2 * 180) / math.pi + 540) % 360) - 180;
final lat = (phi2 * 180) / math.pi;
diff --git a/lib/src/rhumb_distance.dart b/lib/src/rhumb_distance.dart
index 2524c4d..08a7c6f 100644
--- a/lib/src/rhumb_distance.dart
+++ b/lib/src/rhumb_distance.dart
@@ -33,7 +33,7 @@ num rhumbDistance(Point from, Point to, [Unit unit = Unit.kilometers]) {
}
///
-/// Returns the distance travelling from ‘this’ point to destination point along a rhumb line.
+/// Returns the distance traveling from ‘this’ point to destination point along a rhumb line.
/// Adapted from Geodesy ‘distanceTo‘: https://github.com/chrisveness/geodesy/blob/master/latlon-spherical.js
///
/// example:
diff --git a/lib/src/transform_rotate.dart b/lib/src/transform_rotate.dart
index 0234606..aa3ca91 100644
--- a/lib/src/transform_rotate.dart
+++ b/lib/src/transform_rotate.dart
@@ -1,6 +1,5 @@
import 'package:turf/bearing.dart';
import 'package:turf/distance.dart';
-import 'package:turf/helpers.dart';
import 'package:turf/src/centroid.dart';
import 'package:turf/src/invariant.dart';
import 'package:turf/src/meta/coord.dart';
diff --git a/lib/transform.dart b/lib/transform.dart
index fdd9f4d..bc38978 100644
--- a/lib/transform.dart
+++ b/lib/transform.dart
@@ -1,3 +1,4 @@
library turf_transform;
+export 'package:geotypes/geotypes.dart';
export 'src/transform_rotate.dart';
diff --git a/lib/truncate.dart b/lib/truncate.dart
index d50cd33..905e69b 100644
--- a/lib/truncate.dart
+++ b/lib/truncate.dart
@@ -1,3 +1,4 @@
-library truncate.dart;
+library turf_truncate;
+export 'package:geotypes/geotypes.dart';
export 'src/truncate.dart';
diff --git a/lib/turf.dart b/lib/turf.dart
index 952f5b8..b36424c 100644
--- a/lib/turf.dart
+++ b/lib/turf.dart
@@ -1,19 +1,34 @@
library turf;
export 'package:geotypes/geotypes.dart';
-export 'src/along.dart';
-export 'src/area.dart';
-export 'src/bbox.dart';
-export 'src/bearing.dart';
-export 'src/center.dart';
-export 'src/centroid.dart';
-export 'src/destination.dart';
-export 'src/distance.dart';
-export 'src/helpers.dart';
-export 'src/length.dart';
-export 'src/midpoint.dart';
-export 'src/nearest_point.dart';
-export 'src/polyline.dart';
-export 'src/nearest_point_on_line.dart';
+export 'along.dart';
+export 'area.dart';
+export 'bbox_polygon.dart';
+export 'bbox.dart';
+export 'bearing.dart';
export 'boolean.dart';
-export 'src/line_overlap.dart';
+export 'center.dart';
+export 'centroid.dart';
+export 'clean_coords.dart';
+export 'clusters.dart';
+export 'destination.dart';
+export 'distance.dart';
+export 'explode.dart';
+export 'extensions.dart';
+export 'helpers.dart';
+export 'invariant.dart';
+export 'length.dart';
+export 'line_intersect.dart';
+export 'line_overlap.dart';
+export 'line_segment.dart';
+export 'line_slice.dart';
+export 'line_to_polygon.dart';
+export 'meta.dart';
+export 'midpoint.dart';
+export 'nearest_point_on_line.dart';
+export 'nearest_point.dart';
+export 'polygon_smooth.dart';
+export 'polygon_to_line.dart';
+export 'polyline.dart';
+export 'transform.dart';
+export 'truncate.dart';
diff --git a/test/booleans/overlap_test.dart b/test/booleans/overlap_test.dart
index 0a309e1..a2bbb49 100644
--- a/test/booleans/overlap_test.dart
+++ b/test/booleans/overlap_test.dart
@@ -1,7 +1,7 @@
+import 'package:geotypes/geotypes.dart';
import 'package:test/test.dart';
import 'package:turf/src/booleans/boolean_helper.dart';
import 'package:turf/src/booleans/boolean_overlap.dart';
-import 'package:turf/src/geojson.dart';
import '../context/helper.dart';
import '../context/load_test_cases.dart';
diff --git a/test/booleans/parallel_test.dart b/test/booleans/parallel_test.dart
index 02c569c..4010fa8 100644
--- a/test/booleans/parallel_test.dart
+++ b/test/booleans/parallel_test.dart
@@ -2,7 +2,6 @@ import 'dart:convert';
import 'dart:io';
import 'package:test/test.dart';
-import 'package:turf/src/booleans/boolean_parallel.dart';
import 'package:turf/turf.dart';
void main() {
@@ -10,7 +9,7 @@ void main() {
'boolean-overlap',
() {
test(
- "turf-boolean-overlap-trues",
+ "turf-boolean-overlap-true",
() {
// True Fixtures
Directory dir = Directory('./test/examples/booleans/parallel/true');
@@ -29,7 +28,7 @@ void main() {
);
test(
- "turf-boolean-overlap-falses",
+ "turf-boolean-overlap-false",
() {
// True Fixtures
Directory dir = Directory('./test/examples/booleans/parallel/false');
diff --git a/test/booleans/touches_test.dart b/test/booleans/touches_test.dart
index f398343..7db9db1 100644
--- a/test/booleans/touches_test.dart
+++ b/test/booleans/touches_test.dart
@@ -2,8 +2,7 @@ import 'dart:convert';
import 'dart:io';
import 'package:test/test.dart';
-import 'package:turf/src/booleans/boolean_touches.dart';
-import 'package:turf/turf.dart';
+import 'package:turf/boolean.dart';
void main() {
group(
@@ -28,7 +27,7 @@ void main() {
);
test(
- "turf-boolean-overlap-falses",
+ "turf-boolean-overlap-false",
() {
// True Fixtures
Directory dir = Directory('./test/examples/booleans/touches/false');
diff --git a/test/booleans/valid_test.dart b/test/booleans/valid_test.dart
index 6720eaf..9f82c80 100644
--- a/test/booleans/valid_test.dart
+++ b/test/booleans/valid_test.dart
@@ -2,14 +2,13 @@ import 'dart:convert';
import 'dart:io';
import 'package:test/test.dart';
-import 'package:turf/src/booleans/boolean_valid.dart';
-import 'package:turf/turf.dart';
+import 'package:turf/boolean.dart';
void main() {
group(
'boolean-valid',
() {
- /// Assertion error is caught in the fromJSON factory contructor of [GeometryType]s
+ /// Assertion error is caught in the fromJSON factory constructor of [GeometryType]s
Directory dir = Directory('./test/examples/booleans/valid/assertion');
for (var file in dir.listSync(recursive: true)) {
test(
@@ -30,8 +29,8 @@ void main() {
},
);
}
- Directory dirFale = Directory('./test/examples/booleans/valid/false');
- for (var file in dirFale.listSync(recursive: true)) {
+ Directory dirFile = Directory('./test/examples/booleans/valid/false');
+ for (var file in dirFile.listSync(recursive: true)) {
test(
file.path,
() {
diff --git a/test/components/bbox_test.dart b/test/components/bbox_test.dart
index e9efefc..8354d7e 100644
--- a/test/components/bbox_test.dart
+++ b/test/components/bbox_test.dart
@@ -1,6 +1,5 @@
import 'package:test/test.dart';
import 'package:turf/bbox.dart';
-import 'package:turf/helpers.dart';
void main() {
final pt = Feature(
diff --git a/test/components/bearing_test.dart b/test/components/bearing_test.dart
index 4294945..3abe74e 100644
--- a/test/components/bearing_test.dart
+++ b/test/components/bearing_test.dart
@@ -1,6 +1,5 @@
import 'package:test/test.dart';
import 'package:turf/bearing.dart';
-import 'package:turf/helpers.dart';
void main() {
test(
diff --git a/test/components/center_test.dart b/test/components/center_test.dart
index c642d22..1f8cd79 100644
--- a/test/components/center_test.dart
+++ b/test/components/center_test.dart
@@ -2,9 +2,10 @@ import 'dart:convert';
import 'dart:io';
import 'package:test/test.dart';
+import 'package:turf/bbox.dart';
+import 'package:turf/center.dart';
import 'package:turf/meta.dart';
import 'package:turf/src/bbox_polygon.dart';
-import 'package:turf/turf.dart';
void main() {
group(
diff --git a/test/components/centroid_test.dart b/test/components/centroid_test.dart
index 30ceb0b..6449019 100644
--- a/test/components/centroid_test.dart
+++ b/test/components/centroid_test.dart
@@ -2,7 +2,6 @@ import 'dart:convert';
import 'dart:io';
import 'package:test/test.dart';
-import 'package:turf/src/meta/feature.dart';
import 'package:turf/turf.dart';
import 'package:turf_equality/turf_equality.dart';
diff --git a/test/components/explode_test.dart b/test/components/explode_test.dart
index d5c5598..443d84e 100644
--- a/test/components/explode_test.dart
+++ b/test/components/explode_test.dart
@@ -1,9 +1,9 @@
import 'dart:convert';
import 'dart:io';
+import 'package:geotypes/geotypes.dart';
import 'package:test/test.dart';
import 'package:turf/src/explode.dart';
-import 'package:turf/turf.dart';
void main() {
group(
diff --git a/test/components/geojson_test.dart b/test/components/geojson_test.dart
index 9133302..d2f9188 100644
--- a/test/components/geojson_test.dart
+++ b/test/components/geojson_test.dart
@@ -6,7 +6,6 @@ import 'dart:math';
import 'package:test/test.dart';
import 'package:turf/distance.dart';
-import 'package:turf/helpers.dart';
void main() {
group('Coordinate Types:', () {
diff --git a/test/components/midpoint_test.dart b/test/components/midpoint_test.dart
index 51dc60d..44e26db 100644
--- a/test/components/midpoint_test.dart
+++ b/test/components/midpoint_test.dart
@@ -2,7 +2,6 @@
import 'package:test/test.dart';
import 'package:turf/distance.dart';
-import 'package:turf/helpers.dart';
import 'package:turf/midpoint.dart';
void checkLatLngInRange(Point result) {
diff --git a/test/components/polyline.dart b/test/components/polyline.dart
index 1083e68..3cf2906 100644
--- a/test/components/polyline.dart
+++ b/test/components/polyline.dart
@@ -1,5 +1,4 @@
import 'package:test/test.dart';
-import 'package:turf/helpers.dart';
import 'package:turf/polyline.dart';
void main() {
diff --git a/test/components/transform_rotate_test.dart b/test/components/transform_rotate_test.dart
index 0320294..12d7e05 100644
--- a/test/components/transform_rotate_test.dart
+++ b/test/components/transform_rotate_test.dart
@@ -2,7 +2,6 @@ import 'dart:convert';
import 'dart:io';
import 'package:test/test.dart';
-import 'package:turf/helpers.dart';
import 'package:turf/src/centroid.dart';
import 'package:turf/src/invariant.dart';
import 'package:turf/src/transform_rotate.dart';
diff --git a/test/components/truncate_test.dart b/test/components/truncate_test.dart
index aff618d..b39bf58 100644
--- a/test/components/truncate_test.dart
+++ b/test/components/truncate_test.dart
@@ -2,7 +2,6 @@ import 'dart:convert';
import 'dart:io';
import 'package:test/test.dart';
-import 'package:turf/helpers.dart';
import 'package:turf/truncate.dart';
import 'package:turf_equality/turf_equality.dart';
diff --git a/test/context/matcher.dart b/test/context/matcher.dart
index 011b03f..aa35005 100644
--- a/test/context/matcher.dart
+++ b/test/context/matcher.dart
@@ -1,6 +1,5 @@
import 'package:test/test.dart';
import 'package:turf/helpers.dart';
-import 'package:turf/src/geojson.dart';
import 'package:turf_equality/turf_equality.dart';
Matcher equals(T? expected) => _Equals(expected);