Comparing version 1.0.1 to 1.0.2
@@ -98,2 +98,6 @@ import { DCoord, DPoint, LatLng } from './DPoint'; | ||
get growingPiecesGenerator(): () => Generator<DPolygon, DPolygon>; | ||
simpleUnion(p: DPolygon): DPolygon | null; | ||
simpleIntersection(p: DPolygon): DPolygon | null | DPolygon[]; | ||
simpleDifference(p: DPolygon): DPolygon | null | DPolygon[]; | ||
smartUnion(p: DPolygon): DPolygon | null; | ||
private simpleIncludeX; | ||
@@ -104,3 +108,5 @@ private simpleIncludeY; | ||
private contain2; | ||
private getJSTSGeometry; | ||
private simpleLogicFunction; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DPolygon = exports.MIN_POINTS_IN_VALID_POLYGON = void 0; | ||
/* eslint-disable max-lines */ | ||
const DPoint_1 = require("./DPoint"); | ||
@@ -8,2 +9,3 @@ const DLine_1 = require("./DLine"); | ||
const DNumbers_1 = require("./DNumbers"); | ||
const jsts_1 = require("jsts"); | ||
exports.MIN_POINTS_IN_VALID_POLYGON = 3; | ||
@@ -672,2 +674,49 @@ const APPROXIMATION_VALUE = 0.1; | ||
} | ||
simpleUnion(p) { | ||
try { | ||
const res = this.simpleLogicFunction(p, true, true); | ||
if (res === null) { | ||
return null; | ||
} | ||
if (res instanceof DPolygon) { | ||
return res; | ||
} | ||
return null; | ||
} | ||
catch (ex) { | ||
return null; | ||
} | ||
} | ||
simpleIntersection(p) { | ||
return this.simpleLogicFunction(p, false, false); | ||
} | ||
simpleDifference(p) { | ||
return this.simpleLogicFunction(p, true, false); | ||
} | ||
smartUnion(p) { | ||
var _a; | ||
const res = this.clone().simpleUnion(p); | ||
if (res) { | ||
let allHoles = [...this.holes, ...p.holes, ...((_a = res.holes) !== null && _a !== void 0 ? _a : [])].map((h) => h.clone()); | ||
for (const a of allHoles) { | ||
for (const b of allHoles) { | ||
if (a.equal(b)) { | ||
continue; | ||
} | ||
const r = a.simpleUnion(b); | ||
if (r) { | ||
allHoles = allHoles.filter((v) => !v.equal(a) && !v.equal(b)); | ||
if (Array.isArray(r)) { | ||
allHoles = [...allHoles, ...r]; | ||
} | ||
else { | ||
allHoles.push(r); | ||
} | ||
} | ||
} | ||
} | ||
res.holes = allHoles; | ||
} | ||
return res; | ||
} | ||
simpleIncludeX(p) { | ||
@@ -748,3 +797,87 @@ const { x } = p; | ||
} | ||
getJSTSGeometry(p, unionThis, unionThat) { | ||
const unionOrIntersection = unionThat === unionThis; | ||
const reader = new jsts_1.io.WKTReader(); | ||
const a = reader.read(this.noHoles.toWKT()); | ||
const b = reader.read(p.noHoles.toWKT()); | ||
if (!unionOrIntersection) { | ||
return a.difference(b); | ||
} | ||
else if (unionThis) { | ||
return a.union(b); | ||
} | ||
else if (!unionThis) { | ||
return a.intersection(b); | ||
} | ||
return undefined; | ||
} | ||
simpleLogicFunction(p, unionThis, unionThat) { | ||
const c = this.getJSTSGeometry(p, unionThis, unionThat); | ||
if (c) { | ||
const coordinates = c.getCoordinates(); | ||
if (coordinates.length) { | ||
let result = coordinates.reduce((ak, { x, y }, index) => { | ||
const lastIndex = ak.length - 1; | ||
const t = new DPoint_1.DPoint(x, y); | ||
const { first } = ak[lastIndex]; | ||
if (t.equal(first)) { | ||
if (coordinates[index + 1]) { | ||
const nextPoint = new DPoint_1.DPoint(coordinates[index + 1].x, coordinates[index + 1].y); | ||
if (ak[lastIndex].length > 1) { | ||
ak.push(new DPolygon([nextPoint])); | ||
} | ||
} | ||
} | ||
else { | ||
ak[lastIndex].push(t); | ||
} | ||
return ak; | ||
}, [new DPolygon([new DPoint_1.DPoint(coordinates[0].x, coordinates[0].y)])]); | ||
if (unionThat && unionThis && result.length > 1) { | ||
for (const q of result) { | ||
for (const r of result) { | ||
if (q.has(r.first) && !q.equal(r)) { | ||
const index = q.findIndex(r.first); | ||
q.points.splice(index, 0, ...r.points); | ||
result = result.filter((h) => !h.equal(r)); | ||
continue; | ||
} | ||
if (result.length < 2) { | ||
break; | ||
} | ||
} | ||
if (result.length < 2) { | ||
break; | ||
} | ||
} | ||
} | ||
result = result.filter((h) => h.length > 2).map((h) => h.close()); | ||
for (const q of result) { | ||
for (const r of result) { | ||
if (result.length < 2) { | ||
break; | ||
} | ||
if (!q.equal(r)) { | ||
if (q.contain(r.first, true)) { | ||
q.holes.push(r); | ||
result = result.filter((h) => !h.equal(r)); | ||
} | ||
} | ||
} | ||
if (result.length < 2) { | ||
break; | ||
} | ||
} | ||
if (result.length === 0) { | ||
return null; | ||
} | ||
if (result.length === 1) { | ||
return result[0].close(); | ||
} | ||
return result.map((g) => g.close()); | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
exports.DPolygon = DPolygon; |
{ | ||
"name": "dgeoutils", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -19,2 +19,6 @@ "scripts": { | ||
], | ||
"dependencies": { | ||
"jsts": "^2.6.1", | ||
"@types/jsts": "^0.17.5" | ||
}, | ||
"devDependencies": { | ||
@@ -39,3 +43,5 @@ "@types/jest": "^26.0.22", | ||
"jest": { | ||
"setupFiles": ["jest-canvas-mock"] | ||
"setupFiles": [ | ||
"jest-canvas-mock" | ||
] | ||
}, | ||
@@ -42,0 +48,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78837
2251
2
+ Added@types/jsts@^0.17.5
+ Addedjsts@^2.6.1
+ Added@types/jsts@0.17.24(transitive)
+ Added@types/openlayers@4.6.23(transitive)
+ Addedfastpriorityqueue@0.7.5(transitive)
+ Addedjsts@2.12.1(transitive)