Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace polygon-clipping with polyclip-ts #2729

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/turf-difference/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Polygon, MultiPolygon, Feature, FeatureCollection } from "geojson";
import polygonClipping, { Geom } from "polygon-clipping";
import * as polyclip from "polyclip-ts";
import { polygon, multiPolygon } from "@turf/helpers";
import { geomEach } from "@turf/meta";

Expand Down Expand Up @@ -39,10 +39,10 @@ import { geomEach } from "@turf/meta";
function difference(
features: FeatureCollection<Polygon | MultiPolygon>
): Feature<Polygon | MultiPolygon> | null {
const geoms: Array<Geom> = [];
const geoms: Array<polyclip.Geom> = [];

geomEach(features, (geom) => {
geoms.push(geom.coordinates as Geom);
geoms.push(geom.coordinates as polyclip.Geom);
});

if (geoms.length < 2) {
Expand All @@ -51,7 +51,7 @@ function difference(

const properties = features.features[0].properties || {};

const differenced = polygonClipping.difference(geoms[0], ...geoms.slice(1));
const differenced = polyclip.difference(geoms[0], ...geoms.slice(1));
if (differenced.length === 0) return null;
if (differenced.length === 1) return polygon(differenced[0], properties);
return multiPolygon(differenced, properties);
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-difference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@turf/helpers": "workspace:^",
"@turf/meta": "workspace:^",
"@types/geojson": "^7946.0.10",
"polygon-clipping": "^0.15.3",
"polyclip-ts": "^0.16.6",
"tslib": "^2.8.1"
}
}
36 changes: 36 additions & 0 deletions packages/turf-difference/test/out/issue-#721-inverse.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,42 @@
]
]
}
},
{
"type": "Feature",
"properties": {
"fill-opacity": 1,
"fill": "#0F0"
},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[-0.6462588068806041, 44.80608667910215],
[-0.6462588068796641, 44.80608667910137],
[-0.6461987, 44.8060367],
[-0.6462588068806041, 44.80608667910215]
]
],
[
[
[-0.6461042, 44.8059451],
[-0.6461041344154723, 44.805944903377586],
[-0.6461041344154722, 44.805944903377586],
[-0.6461042, 44.8059451]
]
],
[
[
[-0.6460471709105139, 44.80564743856641],
[-0.6460421, 44.8056729],
[-0.6460471709104708, 44.80564743856663],
[-0.6460471709105139, 44.80564743856641]
]
]
]
}
}
]
}
18 changes: 12 additions & 6 deletions packages/turf-difference/test/out/issue-#721.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,16 @@
[-0.6460168, 44.8047948],
[-0.6460827, 44.8050017],
[-0.6461218, 44.8051741],
[-0.6461158838109077, 44.80524109574131],
[-0.646107941865921, 44.80533857879061],
[-0.646093673696575, 44.80541109474097],
[-0.6461073, 44.8053383],
[-0.6460848, 44.8054585],
[-0.6460471709105139, 44.80564743856641],
[-0.6460471709104708, 44.80564743856663],
[-0.6460422277450562, 44.805672561504906],
[-0.6460542976856232, 44.80579530680288],
[-0.646069093721612, 44.80583985137739],
[-0.6461041344154722, 44.805944903377586],
[-0.6460542, 44.8057952],
[-0.6461041344154723, 44.805944903377586],
[-0.6461991369724274, 44.80603699057963],
[-0.6462588068806041, 44.80608667910215],
[-0.6462588068796641, 44.80608667910137],
[-0.6463809, 44.8061882],
[-0.646437, 44.806159],
[-0.64649, 44.80611],
Expand All @@ -138,6 +137,13 @@
[-0.6465049, 44.8055554],
[-0.6471907, 44.8053946],
[-0.6474134, 44.805326]
],
[
[-0.6461073, 44.8053383],
[-0.6461158838109077, 44.80524109574131],
[-0.646107941865921, 44.80533857879061],
[-0.646093673696575, 44.80541109474097],
[-0.6461073, 44.8053383]
]
]
}
Expand Down
10 changes: 5 additions & 5 deletions packages/turf-dissolve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { featureCollection, isObject, multiPolygon } from "@turf/helpers";
import { collectionOf } from "@turf/invariant";
import { featureEach } from "@turf/meta";
import { flatten } from "@turf/flatten";
import polygonClipping, { Geom } from "polygon-clipping";
import * as polyclip from "polyclip-ts";

/**
* Dissolves a FeatureCollection of {@link Polygon} features, filtered by an optional property name:value.
Expand Down Expand Up @@ -45,12 +45,12 @@ function dissolve(
if (!propertyName) {
return flatten(
multiPolygon(
polygonClipping.union.apply(
polyclip.union.apply(
null,
// List of polygons expressed as Position[][][] a.k.a. Geom[]
fc.features.map(function (f) {
return f.geometry.coordinates;
}) as [Geom, ...Geom[]]
}) as [polyclip.Geom, ...polyclip.Geom[]]
)
)
);
Expand All @@ -76,12 +76,12 @@ function dissolve(
// Export each group of polygons as a separate feature.
for (let i = 0; i < vals.length; i++) {
const mp = multiPolygon(
polygonClipping.union.apply(
polyclip.union.apply(
null,
// List of polygons expressed as Position[][][] a.k.a. Geom[]
(uniquePropertyVals[vals[i]] as Feature<Polygon>[]).map(function (f) {
return f.geometry.coordinates;
}) as [Geom, ...Geom[]]
}) as [polyclip.Geom, ...polyclip.Geom[]]
)
);
if (mp && mp.properties) {
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-dissolve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@turf/invariant": "workspace:^",
"@turf/meta": "workspace:^",
"@types/geojson": "^7946.0.10",
"polygon-clipping": "^0.15.3",
"polyclip-ts": "^0.16.6",
"tslib": "^2.8.1"
}
}
Loading