Skip to content

Commit

Permalink
cleanup on #88
Browse files Browse the repository at this point in the history
  • Loading branch information
armantorkzaban committed Aug 30, 2022
1 parent 65eddf8 commit 8c912f6
Show file tree
Hide file tree
Showing 51 changed files with 1,596 additions and 260 deletions.
4 changes: 2 additions & 2 deletions lib/src/booleans/boolean_crosses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'boolean_point_in_polygon.dart';
/// Boolean-Crosses 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.
/// Boolean-Crosses returns [true] for only [MultiPoint]/[Polygon], [MultiPoint]/[Linestring],
/// [Linestring]/[Linestring], [Linestring]/[Polygon], and [Linestring]/[multiPolygon] comparisons.
/// Boolean-Crosses 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.
/// example:
Expand Down
6 changes: 3 additions & 3 deletions lib/src/booleans/boolean_disjoint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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.
/// Returns [true] if the intersection of the two geometries is an empty set.
/// example:
/// ```dart
/// var point = Point(coordinates: Position.of([2, 2]));
Expand Down Expand Up @@ -38,7 +38,7 @@ bool booleanDisjoint(GeoJSONObject feature1, GeoJSONObject feature2) {
return bool;
}

/// Disjoint operation for simple Geometries (Point/LineString/Polygon)
/// Disjoint operation for simple Geometries ([Point]/[LineString]/[Polygon])
bool _disjoint(GeometryType geom1, GeometryType geom2) {
if (geom1 is Point) {
if (geom2 is Point) {
Expand Down Expand Up @@ -100,7 +100,7 @@ bool isLineInPoly(Polygon polygon, LineString lineString) {
return false;
}

/// Is Polygon (geom1) in Polygon (geom2)
/// Is [Polygon] (geom1) in [Polygon] (geom2)
/// Only takes into account outer rings
/// See http://stackoverflow.com/a/4833823/1979085
_isPolyInPoly(Polygon feature1, Polygon feature2) {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/booleans/boolean_equal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import '../clean_coords.dart';
/// Determine whether two geometries of the same type have identical X,Y coordinate values.
/// See http://edndoc.esri.com/arcsde/9.0/general_topics/understand_spatial_relations.htm
/// [precision]=6 sets decimal precision to use when comparing coordinates.
/// With [direction] set to true, even if the [LineStrings] are reverse versions
/// of each other but the have similar [Position]s, they will be considered the same.
/// If [shiftedPolygon] is true, two [Polygon]s with shifted [Position]s are
/// considered the same.
/// Returns true if the objects are equal, false otherwise
/// With [direction] set to [true], even if the [LineString]s are reverse versions
/// of each other but they have similar [Position]s, they will be considered the
/// same. If [shiftedPolygon] is [true], two [Polygon]s with shifted [Position]s
/// are considered the same.
/// Returns [true] if the objects are equal, false otherwise
/// example:
/// var pt1 = Point(coordinates: Position.of([0, 0]));
/// var pt2 = Point(coordinates: Position.of([0, 0]));
Expand Down
76 changes: 23 additions & 53 deletions lib/src/booleans/boolean_intersect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,31 @@ import '../../helpers.dart';
import '../../meta.dart';
import 'boolean_disjoint.dart';

/// returns (TRUE) when two geometries intersect.
/// @name booleanIntersects
/// @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
/// @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
/// @returns {boolean} true/false
/// @example
/// var point = turf.point([2, 2]);
/// var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
/// turf.booleanIntersects(line, point);
/// returns [true] when two geometries intersect.
/// Takes a feature1 & feature2 parameters of type [GeoJSONObject] which can be
/// a [Feature] or [GeometryType].
/// example
/// ```dart
/// var point = Point(coordinates:Position.of([2, 2]));
/// var line = LineString(coordinates:[Position.of([1, 1]), Position.of([1, 2]), Position.of([1, 3]), Position.of([1, 4]]));
/// booleanIntersects(line, point);
/// ```
//=true
booleanIntersects(GeoJSONObject feature1, GeoJSONObject feature2) {
var bool = false;
flattenEach(feature1, (flatten1, featureIndex, multiFeatureIndex) {
flattenEach(feature2, (flatten2, featureIndex, multiFeatureIndex) {
if (bool == true) {
return true;
}
bool = !booleanDisjoint(flatten1, flatten2);
});
});
flattenEach(
feature1,
(flatten1, featureIndex, multiFeatureIndex) {
flattenEach(
feature2,
(flatten2, featureIndex, multiFeatureIndex) {
if (bool) {
return true;
}
bool = !booleanDisjoint(flatten1, flatten2);
},
);
},
);
return bool;
}

/**
* import { Feature, Geometry } from "geojson";
import booleanDisjoint from "@turf/boolean-disjoint";
import { flattenEach } from "@turf/meta";
/**
* Boolean-intersects returns (TRUE) two geometries intersect.
*
* @name booleanIntersects
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
* @returns {boolean} true/false
* @example
* var point = turf.point([2, 2]);
* var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
*
* turf.booleanIntersects(line, point);
* //=true
*/
export default function booleanIntersects(
feature1: Feature<any> | Geometry,
feature2: Feature<any> | Geometry
) {
let bool = false;
flattenEach(feature1, (flatten1) => {
flattenEach(feature2, (flatten2) => {
if (bool === true) {
return true;
}
bool = !booleanDisjoint(flatten1.geometry, flatten2.geometry);
});
});
return bool;
}
*/
8 changes: 4 additions & 4 deletions lib/src/booleans/boolean_point_in_polygon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import 'package:turf_pip/turf_pip.dart';
import '../../helpers.dart';

/// Takes a [Point], and a [Polygon] or [MultiPolygon]and determines if the
/// [Point] resides inside the [Polygon]. The polygon can be convex or concave.
/// [Point] resides within the [Polygon]. The [polygon] can be convex or concave.
/// The function accounts for holes. By taking a [Feature<Polygon>] or a
/// [Feature<MultiPolygon>]. [ignoreBoundary=false] should be set [true] if polygon's
/// boundary should be ignored when determining if the [Point] is inside the
/// [Polygon] otherwise false.
/// [Feature<MultiPolygon>]. [ignoreBoundary=false] should be set to [true] if
/// [Polygon]'s boundary should be ignored when determining if the [Point] is
/// inside the [Polygon], otherwise, false.
/// example:
/// ```dart
/// var pt = Point(coordinates: Position([-77, 44]));
Expand Down
4 changes: 1 addition & 3 deletions test/booleans/crosses_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ main() {
group(
'boolean_crosses',
() {
// True Fixtures
var inDir = Directory('./test/examples/booleans/crosses/true');
for (var file in inDir.listSync(recursive: true)) {
if (file is File && file.path.endsWith('.geojson')) {
test(
file.path,
() {
// True Fixtures
var inSource = file.readAsStringSync();
var inGeom = GeoJSONObject.fromJson(jsonDecode(inSource));
var feature1 = (inGeom as FeatureCollection).features[0];
var feature2 = inGeom.features[1];

expect(
booleanCrosses(feature1.geometry!, feature2.geometry!), true);
},
Expand All @@ -34,7 +33,6 @@ main() {
test(
file.path,
() {
// True Fixtures
var inSource = file.readAsStringSync();
var inGeom = GeoJSONObject.fromJson(jsonDecode(inSource));
var feature1 = (inGeom as FeatureCollection).features[0];
Expand Down
76 changes: 36 additions & 40 deletions test/booleans/disjoint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,44 @@ import 'package:turf/helpers.dart';
import 'package:turf/src/booleans/boolean_disjoint.dart';

main() {
group(
'boolean_disjoint',
() {
var inDir = Directory('./test/examples/booleans/disjoint/test/true');
for (var file in inDir.listSync(recursive: true)) {
if (file is File && file.path.endsWith('.geojson')) {
test(
file.path,
() {
// True Fixtures
var inSource = file.readAsStringSync();
var inGeom = GeoJSONObject.fromJson(jsonDecode(inSource));
group('boolean_disjoint', () {
// True Fixtures
var inDir = Directory('./test/examples/booleans/disjoint/test/true');
for (var file in inDir.listSync(recursive: true)) {
if (file is File && file.path.endsWith('.geojson')) {
test(
file.path,
() {
var inSource = file.readAsStringSync();
var inGeom = GeoJSONObject.fromJson(jsonDecode(inSource));

var feature1 = (inGeom as FeatureCollection).features[0];
var feature2 = inGeom.features[1];
var result = booleanDisjoint(feature1, feature2);
expect(result, true);
},
);
// False Fixtures
var inDir1 =
Directory('./test/examples/booleans/disjoint/test/false');
for (var file in inDir1.listSync(recursive: true)) {
if (file is File && file.path.endsWith('.geojson')) {
test(
file.path,
() {
// True Fixtures
var inSource = file.readAsStringSync();
var inGeom = GeoJSONObject.fromJson(jsonDecode(inSource));
var feature1 = (inGeom as FeatureCollection).features[0];
var feature2 = inGeom.features[1];
var result = booleanDisjoint(feature1, feature2);
expect(result, true);
},
);
}
}
// False Fixtures
var inDir1 = Directory('./test/examples/booleans/disjoint/test/false');
for (var file in inDir1.listSync(recursive: true)) {
if (file is File && file.path.endsWith('.geojson')) {
test(
file.path,
() {
// True Fixtures
var inSource = file.readAsStringSync();
var inGeom = GeoJSONObject.fromJson(jsonDecode(inSource));

var feature1 = (inGeom as FeatureCollection).features[0];
var feature2 = inGeom.features[1];
var result = booleanDisjoint(feature1, feature2);
var feature1 = (inGeom as FeatureCollection).features[0];
var feature2 = inGeom.features[1];
var result = booleanDisjoint(feature1, feature2);

expect(result, false);
},
);
}
}
}
expect(result, false);
},
);
}
},
);
}
});
}
2 changes: 1 addition & 1 deletion test/booleans/equal_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ main() {
group(
'boolean_equal',
() {
// True Fixtures
var inDir = Directory('./test/examples/booleans/equal/test/true');
for (var file in inDir.listSync(recursive: true)) {
if (file is File && file.path.endsWith('.geojson')) {
test(
file.path,
() {
// True Fixtures
var inSource = file.readAsStringSync();
var inGeom = GeoJSONObject.fromJson(jsonDecode(inSource));

Expand Down
37 changes: 37 additions & 0 deletions test/booleans/intersect_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'dart:convert';
import 'dart:io';

import 'package:test/test.dart';
import 'package:turf/helpers.dart';
import 'package:turf/src/booleans/boolean_intersect.dart';
import 'package:turf/src/intersection.dart';

main() {
var featureCollection = FeatureCollection(features: [
Expand Down Expand Up @@ -90,4 +94,37 @@ main() {
expect(booleanIntersects(feature3, feature4), equals(false));
},
);
test(
"turf-boolean-intersects",
() {
// True Fixtures
var inDir = Directory('./test/examples/booleans/intersects/true');
for (var file in inDir.listSync(recursive: true)) {
if (file is File && file.path.endsWith('.geojson')) {
var inSource = file.readAsStringSync();
var inGeom = GeoJSONObject.fromJson(jsonDecode(inSource));

var feature1 = (inGeom as FeatureCollection).features[0];
var feature2 = inGeom.features[1];
var result = booleanIntersects(feature1, feature2);

expect(result, isTrue);
}
}
// False Fixtures
var inDir1 = Directory('./test/examples/booleans/intersects/false');
for (var file in inDir1.listSync(recursive: true)) {
if (file is File && file.path.endsWith('.geojson')) {
var inSource = file.readAsStringSync();
var inGeom = GeoJSONObject.fromJson(jsonDecode(inSource));

var feature1 = (inGeom as FeatureCollection).features[0];
var feature2 = inGeom.features[1];
var result = booleanIntersects(feature1, feature2);

expect(result, isFalse);
}
}
},
);
}
Loading

0 comments on commit 8c912f6

Please sign in to comment.