Skip to content

Commit

Permalink
Fix boolean-equal docs and added new tests (#2401) (#2412)
Browse files Browse the repository at this point in the history
Co-authored-by: James Milner <jamesmilner22@hotmail.com>
  • Loading branch information
J-Guenther and JamesLMilner authored May 8, 2023
1 parent fa67387 commit ab2456f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
10 changes: 8 additions & 2 deletions packages/turf-boolean-equal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## booleanEqual

Determine whether two geometries of the same type have identical X,Y coordinate values.
Determines whether two geometries or features of the same type have identical X,Y coordinate values and properties.
See [http://edndoc.esri.com/arcsde/9.0/general_topics/understand_spatial_relations.htm][1]

### Parameters
Expand All @@ -21,11 +21,17 @@ See [http://edndoc.esri.com/arcsde/9.0/general_topics/understand_spatial_relatio
var pt1 = turf.point([0, 0]);
var pt2 = turf.point([0, 0]);
var pt3 = turf.point([1, 1]);
var pt4 = turf.point([0, 0], {prop: 'A'});
var pt5 = turf.point([0, 0], {prop: 'B'});

turf.booleanEqual(pt1, pt2);
//= true
turf.booleanEqual(pt2, pt3);
//= false
turf.booleanEqual(pt4, pt5);
//= false
turf.booleanEqual(pt4.geometry, pt5.geometry);
//= true
```

Returns **[boolean][6]** true if the objects are equal, false otherwise
Expand Down Expand Up @@ -70,4 +76,4 @@ $ npm install @turf/turf

### Diagrams

![esri-equals](diagrams/esri-equals.gif)
![esri-equals](diagrams/esri-equals.gif)
48 changes: 34 additions & 14 deletions packages/turf-boolean-equal/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,30 @@ const line2 = lineString([
[8, 50],
[9, 50],
]);
const poly1 = polygon([
const poly1 = polygon(
[
[8.5, 50],
[9.5, 50],
[9.5, 49],
[8.5, 49],
[8.5, 50],
[
[8.5, 50],
[9.5, 50],
[9.5, 49],
[8.5, 49],
[8.5, 50],
],
],
]);
const poly2 = polygon([
{ prop: "A" }
);
const poly2 = polygon(
[
[8.5, 50],
[9.5, 50],
[9.5, 49],
[8.5, 49],
[8.5, 50],
[
[8.5, 50],
[9.5, 50],
[9.5, 49],
[8.5, 49],
[8.5, 50],
],
],
]);
{ prop: "B" }
);
const poly3 = polygon([
[
[10, 50],
Expand All @@ -82,12 +88,26 @@ const poly3 = polygon([
[10, 50],
],
]);
const poly4 = polygon(
[
[
[8.5, 50],
[9.5, 50],
[9.5, 49],
[8.5, 49],
[8.5, 50],
],
],
{ prop: "A" }
);

test("turf-boolean-equal -- geometries", (t) => {
t.true(equal(line1.geometry, line2.geometry), "[true] LineString geometry");
t.true(equal(poly1.geometry, poly2.geometry), "[true] Polygon geometry");
t.true(equal(poly1, poly4), "[true] Polygon feature");
t.false(equal(poly1.geometry, poly3.geometry), "[false] Polygon geometry");
t.false(equal(pt, line1), "[false] different types");
t.false(equal(poly1, poly2), "[false] different properties");
t.end();
});

Expand Down

0 comments on commit ab2456f

Please sign in to comment.