Skip to content

Commit d914bad

Browse files
authored
Merge branch 'master' into interpolate-by-bbox
2 parents e0d57be + 9dc7a50 commit d914bad

12 files changed

+391
-12
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ You can also include it directly from a CDN:
5050

5151
### TypeScript
5252

53-
TypeScript definitions are packaged with each module. No DefinitelyTyped packages required.
53+
Turf modules ship with type definitions packaged in each module. No DefinitelyTyped packages required.
54+
55+
The types defined in the GeoJSON specification are maintained separately (Geometry, Polygon, etc). To refer to these in your own code, install `@types/geojson` and import from there:
56+
57+
```typescript
58+
import { type Polygon } from "geojson";
59+
```
5460

5561
### Other languages
5662

packages/turf-line-intersect/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Takes any LineString or Polygon GeoJSON and returns the intersecting point(s).
1313
* `options` **[Object][2]** Optional parameters (optional, default `{}`)
1414

1515
* `options.removeDuplicates` **[boolean][3]** remove duplicate intersections (optional, default `true`)
16-
* `options.ignoreSelfIntersections` **[boolean][3]** ignores self-intersections on input features (optional, default `false`)
16+
* `options.ignoreSelfIntersections` **[boolean][3]** ignores self-intersections on input features (optional, default `true`)
1717

1818
### Examples
1919

packages/turf-line-intersect/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { sweeplineIntersections as findIntersections } from "./lib/sweepline-int
1919
* @param {GeoJSON} line2 any LineString or Polygon
2020
* @param {Object} [options={}] Optional parameters
2121
* @param {boolean} [options.removeDuplicates=true] remove duplicate intersections
22-
* @param {boolean} [options.ignoreSelfIntersections=false] ignores self-intersections on input features
22+
* @param {boolean} [options.ignoreSelfIntersections=true] ignores self-intersections on input features
2323
* @returns {FeatureCollection<Point>} point(s) that intersect both
2424
* @example
2525
* var line1 = turf.lineString([[126, -11], [129, -21]]);
@@ -40,7 +40,7 @@ function lineIntersect<
4040
ignoreSelfIntersections?: boolean;
4141
} = {}
4242
): FeatureCollection<Point> {
43-
const { removeDuplicates = true, ignoreSelfIntersections = false } = options;
43+
const { removeDuplicates = true, ignoreSelfIntersections = true } = options;
4444
let features: Feature<G1 | G2>[] = [];
4545
if (line1.type === "FeatureCollection")
4646
features = features.concat(line1.features);

packages/turf-line-intersect/test.ts

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ import path from "path";
44
import { loadJsonFileSync } from "load-json-file";
55
import { writeJsonFileSync } from "write-json-file";
66
import { truncate } from "@turf/truncate";
7-
import {
8-
featureCollection,
9-
// geometryCollection,
10-
lineString,
11-
polygon,
12-
} from "@turf/helpers";
7+
import { featureCollection, lineString, polygon } from "@turf/helpers";
138
import { lineIntersect } from "./index.js";
9+
import { Feature, LineString, Point } from "geojson";
1410

1511
const directories = {
1612
in: path.join("test", "in") + path.sep,
@@ -21,14 +17,18 @@ const fixtures = fs.readdirSync(directories.in).map((filename) => {
2117
return {
2218
filename,
2319
name: path.parse(filename).name,
24-
geojson: loadJsonFileSync(directories.in + filename),
20+
geojson: loadJsonFileSync(
21+
directories.in + filename
22+
) as GeoJSON.FeatureCollection<LineString>,
2523
};
2624
});
2725

2826
test("turf-line-intersect", (t) => {
2927
for (const { filename, name, geojson } of fixtures) {
3028
const [line1, line2] = geojson.features;
31-
const results = truncate(lineIntersect(line1, line2));
29+
const results: GeoJSON.FeatureCollection<LineString | Point> = truncate(
30+
lineIntersect(line1, line2)
31+
);
3232
results.features.push(line1);
3333
results.features.push(line2);
3434

@@ -132,3 +132,52 @@ test("turf-line-intersect - polygon support #586", (t) => {
132132
t.equal(results.features.length, 1, "should return single point");
133133
t.end();
134134
});
135+
136+
/**
137+
* ensures that the self intersection param behaves as expected -
138+
* since it cannot be verified in the fixture format.
139+
*/
140+
test("turf-line-intersect - self intersection behavior", (t) => {
141+
const line1: Feature<LineString> = {
142+
type: "Feature",
143+
properties: {},
144+
geometry: {
145+
type: "LineString",
146+
coordinates: [
147+
[0, 0],
148+
[0, 2],
149+
[2, 1],
150+
[-1, 1],
151+
],
152+
},
153+
};
154+
const line2: Feature<LineString> = {
155+
type: "Feature",
156+
properties: {},
157+
geometry: {
158+
type: "LineString",
159+
coordinates: [
160+
[3, 3],
161+
[4, 4],
162+
[5, 5],
163+
],
164+
},
165+
};
166+
167+
const ignored = lineIntersect(line1, line2);
168+
t.equal(
169+
ignored.features.length,
170+
0,
171+
"self intersections should be ignored by default"
172+
);
173+
174+
const included = lineIntersect(line1, line2, {
175+
ignoreSelfIntersections: false,
176+
});
177+
t.equal(
178+
included.features.length,
179+
1,
180+
"self intersections should be included when ignoreSelfIntersections set to false"
181+
);
182+
t.end();
183+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {},
7+
"geometry": {
8+
"type": "LineString",
9+
"coordinates": [
10+
[0, 0],
11+
[0, 2],
12+
[2, 1],
13+
[-1, 1]
14+
]
15+
}
16+
},
17+
{
18+
"type": "Feature",
19+
"properties": {},
20+
"geometry": {
21+
"type": "LineString",
22+
"coordinates": [
23+
[3, 3],
24+
[4, 4],
25+
[5, 5]
26+
]
27+
}
28+
}
29+
]
30+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {},
7+
"geometry": {
8+
"type": "MultiLineString",
9+
"coordinates": [
10+
[
11+
[0, 0],
12+
[1, 2],
13+
[0, 4]
14+
],
15+
[
16+
[1, 0],
17+
[0, 2],
18+
[1, 4]
19+
]
20+
]
21+
}
22+
},
23+
{
24+
"type": "Feature",
25+
"properties": {},
26+
"geometry": {
27+
"type": "LineString",
28+
"coordinates": [
29+
[3, 3],
30+
[4, 4],
31+
[5, 5]
32+
]
33+
}
34+
}
35+
]
36+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {
7+
"fill": "#ed333b",
8+
"fill-opacity": 0.5
9+
},
10+
"geometry": {
11+
"coordinates": [
12+
[
13+
[
14+
[2.8208987964653716, 5.206515064293427],
15+
[2.8208987964653716, -4.530167455797994],
16+
[6.383916833323553, -4.530167455797994],
17+
[6.383916833323553, 5.206515064293427],
18+
[2.8208987964653716, 5.206515064293427]
19+
]
20+
],
21+
[
22+
[
23+
[-0.33343506038161763, 3.67541603033537],
24+
[-0.33343506038161763, 2.1793088174136273],
25+
[8.775841349855597, 2.1793088174136273],
26+
[8.775841349855597, 3.67541603033537],
27+
[-0.33343506038161763, 3.67541603033537]
28+
]
29+
]
30+
],
31+
"type": "MultiPolygon"
32+
},
33+
"id": 0
34+
},
35+
{
36+
"type": "Feature",
37+
"properties": {},
38+
"geometry": {
39+
"coordinates": [
40+
[
41+
[-7.951422534380413, 5.231149187754099],
42+
[-7.951422534380413, -4.552832252613101],
43+
[-5.701165954657256, -4.552832252613101],
44+
[-5.701165954657256, 5.231149187754099],
45+
[-7.951422534380413, 5.231149187754099]
46+
]
47+
],
48+
"type": "Polygon"
49+
}
50+
}
51+
]
52+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {},
7+
"geometry": {
8+
"coordinates": [
9+
[
10+
[-0.8680870854922205, 3.0368343508535673],
11+
[-1.321147431010786, 5.333329344976903],
12+
[1.0099462525165848, 5.611566335081363],
13+
[0.47439299724965167, -1.9282285399474688],
14+
[3.2162894164922875, -1.8166964568157766],
15+
[2.707220996335252, 7.192842763774053],
16+
[-3.8645185945755713, 6.519248925309753],
17+
[-3.8571038955967083, 0.3483632770754781],
18+
[-0.5093053180867742, 0.39824548653076874],
19+
[4.4119165583018685, 0.21046777461485533],
20+
[3.9804563423212755, 3.7937082620644844],
21+
[-0.8680870854922205, 3.0368343508535673]
22+
]
23+
],
24+
"type": "Polygon"
25+
}
26+
},
27+
{
28+
"type": "Feature",
29+
"properties": {},
30+
"geometry": {
31+
"coordinates": [
32+
[
33+
[-7.4564971746842446, 6.278543929857676],
34+
[-13.631981273628753, 6.323585458965155],
35+
[-12.43687692686214, -2.589094309688946],
36+
[-6.376915352576532, -3.0767722870515115],
37+
[-7.4564971746842446, 6.278543929857676]
38+
]
39+
],
40+
"type": "Polygon"
41+
}
42+
}
43+
]
44+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {},
7+
"geometry": {
8+
"type": "LineString",
9+
"coordinates": [
10+
[0, 0],
11+
[0, 2],
12+
[2, 1],
13+
[-1, 1]
14+
]
15+
}
16+
},
17+
{
18+
"type": "Feature",
19+
"properties": {},
20+
"geometry": {
21+
"type": "LineString",
22+
"coordinates": [
23+
[3, 3],
24+
[4, 4],
25+
[5, 5]
26+
]
27+
}
28+
}
29+
]
30+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {},
7+
"geometry": {
8+
"type": "MultiLineString",
9+
"coordinates": [
10+
[
11+
[0, 0],
12+
[1, 2],
13+
[0, 4]
14+
],
15+
[
16+
[1, 0],
17+
[0, 2],
18+
[1, 4]
19+
]
20+
]
21+
}
22+
},
23+
{
24+
"type": "Feature",
25+
"properties": {},
26+
"geometry": {
27+
"type": "LineString",
28+
"coordinates": [
29+
[3, 3],
30+
[4, 4],
31+
[5, 5]
32+
]
33+
}
34+
}
35+
]
36+
}

0 commit comments

Comments
 (0)