import { Circle_default, LineString_default, MultiLineString_default, MultiPolygon_default } from "./chunk-7JXPN73Q.js"; import { Polygon_default } from "./chunk-AZGMK675.js"; import { buffer } from "./chunk-SRXHWJOY.js"; // node_modules/ol-ext/geom/GeomUtils.js var ol_coordinate_dist2d = function(p1, p2) { var dx = p1[0] - p2[0]; var dy = p1[1] - p2[1]; return Math.sqrt(dx * dx + dy * dy); }; var ol_coordinate_equal = function(p1, p2) { return p1[0] == p2[0] && p1[1] == p2[1]; }; var ol_coordinate_offsetCoords = function(coords, offset) { var path = []; var N = coords.length - 1; var max = N; var mi, mi1, li, li1, ri, ri1, si, si1, Xi1, Yi1; var p0, p1, p2; var isClosed = ol_coordinate_equal(coords[0], coords[N]); if (!isClosed) { p0 = coords[0]; p1 = coords[1]; p2 = [ p0[0] + (p1[1] - p0[1]) / ol_coordinate_dist2d(p0, p1) * offset, p0[1] - (p1[0] - p0[0]) / ol_coordinate_dist2d(p0, p1) * offset ]; path.push(p2); coords.push(coords[N]); N++; max--; } for (var i = 0; i < max; i++) { p0 = coords[i]; p1 = coords[(i + 1) % N]; p2 = coords[(i + 2) % N]; mi = (p1[1] - p0[1]) / (p1[0] - p0[0]); mi1 = (p2[1] - p1[1]) / (p2[0] - p1[0]); if (Math.abs(mi - mi1) > 1e-10) { li = Math.sqrt((p1[0] - p0[0]) * (p1[0] - p0[0]) + (p1[1] - p0[1]) * (p1[1] - p0[1])); li1 = Math.sqrt((p2[0] - p1[0]) * (p2[0] - p1[0]) + (p2[1] - p1[1]) * (p2[1] - p1[1])); ri = p0[0] + offset * (p1[1] - p0[1]) / li; ri1 = p1[0] + offset * (p2[1] - p1[1]) / li1; si = p0[1] - offset * (p1[0] - p0[0]) / li; si1 = p1[1] - offset * (p2[0] - p1[0]) / li1; Xi1 = (mi1 * ri1 - mi * ri + si - si1) / (mi1 - mi); Yi1 = (mi * mi1 * (ri1 - ri) + mi1 * si - mi * si1) / (mi1 - mi); if (p1[0] - p0[0] == 0) { Xi1 = p1[0] + offset * (p1[1] - p0[1]) / Math.abs(p1[1] - p0[1]); Yi1 = mi1 * Xi1 - mi1 * ri1 + si1; } if (p2[0] - p1[0] == 0) { Xi1 = p2[0] + offset * (p2[1] - p1[1]) / Math.abs(p2[1] - p1[1]); Yi1 = mi * Xi1 - mi * ri + si; } path.push([Xi1, Yi1]); } } if (isClosed) { path.push(path[0]); } else { coords.pop(); p0 = coords[coords.length - 1]; p1 = coords[coords.length - 2]; p2 = [ p0[0] - (p1[1] - p0[1]) / ol_coordinate_dist2d(p0, p1) * offset, p0[1] + (p1[0] - p0[0]) / ol_coordinate_dist2d(p0, p1) * offset ]; path.push(p2); } return path; }; var ol_coordinate_findSegment = function(pt, coords) { for (var i = 0; i < coords.length - 1; i++) { var p0 = coords[i]; var p1 = coords[i + 1]; if (ol_coordinate_equal(pt, p0) || ol_coordinate_equal(pt, p1)) { return { index: 1, segment: [p0, p1] }; } else { var d0 = ol_coordinate_dist2d(p0, p1); var v0 = [(p1[0] - p0[0]) / d0, (p1[1] - p0[1]) / d0]; var d1 = ol_coordinate_dist2d(p0, pt); var v1 = [(pt[0] - p0[0]) / d1, (pt[1] - p0[1]) / d1]; if (Math.abs(v0[0] * v1[1] - v0[1] * v1[0]) < 1e-10) { return { index: 1, segment: [p0, p1] }; } } } return { index: -1 }; }; var ol_extent_intersection; (function() { function splitX(pts, x) { var pt; for (let i = pts.length - 1; i > 0; i--) { if (pts[i][0] > x && pts[i - 1][0] < x || pts[i][0] < x && pts[i - 1][0] > x) { pt = [x, (x - pts[i][0]) / (pts[i - 1][0] - pts[i][0]) * (pts[i - 1][1] - pts[i][1]) + pts[i][1]]; pts.splice(i, 0, pt); } } } function splitY(pts, y) { var pt; for (let i = pts.length - 1; i > 0; i--) { if (pts[i][1] > y && pts[i - 1][1] < y || pts[i][1] < y && pts[i - 1][1] > y) { pt = [(y - pts[i][1]) / (pts[i - 1][1] - pts[i][1]) * (pts[i - 1][0] - pts[i][0]) + pts[i][0], y]; pts.splice(i, 0, pt); } } } ol_extent_intersection = function(extent, polygon) { var poly = polygon.getType() === "Polygon"; if (!poly && polygon.getType() !== "MultiPolygon") return null; var geom = polygon.getCoordinates(); if (poly) geom = [geom]; geom.forEach(function(g) { g.forEach(function(c) { splitX(c, extent[0]); splitX(c, extent[2]); splitY(c, extent[1]); splitY(c, extent[3]); }); }); geom.forEach(function(g) { g.forEach(function(c) { c.forEach(function(p) { if (p[0] < extent[0]) p[0] = extent[0]; else if (p[0] > extent[2]) p[0] = extent[2]; if (p[1] < extent[1]) p[1] = extent[1]; else if (p[1] > extent[3]) p[1] = extent[3]; }); }); }); if (poly) { return new Polygon_default(geom[0]); } else { return new MultiPolygon_default(geom); } }; })(); var ol_coordinate_sampleAt = function(p1, p2, d, start) { var pts = []; if (start !== false) pts.push(p1); var dl = ol_coordinate_dist2d(p1, p2); if (dl) { var nb = Math.round(dl / d); if (nb > 1) { var dx = (p2[0] - p1[0]) / nb; var dy = (p2[1] - p1[1]) / nb; for (var i = 1; i < nb; i++) { pts.push([p1[0] + dx * i, p1[1] + dy * i]); } } } pts.push(p2); return pts; }; LineString_default.prototype.sampleAt = function(d) { var line = this.getCoordinates(); var result = []; for (var i = 1; i < line.length; i++) { result = result.concat(ol_coordinate_sampleAt(line[i - 1], line[i], d, i === 1)); } return new LineString_default(result); }; MultiLineString_default.prototype.sampleAt = function(d) { var lines = this.getCoordinates(); var result = []; lines.forEach(function(p) { var l = []; for (var i = 1; i < p.length; i++) { l = l.concat(ol_coordinate_sampleAt(p[i - 1], p[i], d, i === 1)); } result.push(l); }); return new MultiLineString_default(result); }; Polygon_default.prototype.sampleAt = function(res) { var poly = this.getCoordinates(); var result = []; poly.forEach(function(p) { var l = []; for (var i = 1; i < p.length; i++) { l = l.concat(ol_coordinate_sampleAt(p[i - 1], p[i], res, i === 1)); } result.push(l); }); return new Polygon_default(result); }; MultiPolygon_default.prototype.sampleAt = function(res) { var mpoly = this.getCoordinates(); var result = []; mpoly.forEach(function(poly) { var a = []; result.push(a); poly.forEach(function(p) { var l = []; for (var i = 1; i < p.length; i++) { l = l.concat(ol_coordinate_sampleAt(p[i - 1], p[i], res, i === 1)); } a.push(l); }); }); return new MultiPolygon_default(result); }; Circle_default.prototype.intersection = function(geom, resolution) { if (geom.sampleAt) { var ext = buffer(this.getCenter().concat(this.getCenter()), this.getRadius()); geom = ol_extent_intersection(ext, geom); geom = geom.simplify(resolution); var c = this.getCenter(); var r = this.getRadius(); var g = geom.sampleAt(resolution).getCoordinates(); switch (geom.getType()) { case "Polygon": g = [g]; // fallthrough case "MultiPolygon": { var hasout = false; var result = []; g.forEach(function(poly) { var a = []; result.push(a); poly.forEach(function(ring) { var l = []; a.push(l); ring.forEach(function(p) { var d = ol_coordinate_dist2d(c, p); if (d > r) { hasout = true; l.push([ c[0] + r / d * (p[0] - c[0]), c[1] + r / d * (p[1] - c[1]) ]); } else { l.push(p); } }); }); }); if (!hasout) return geom; if (geom.getType() === "Polygon") { return new Polygon_default(result[0]); } else { return new MultiPolygon_default(result); } } } } else { console.warn("[ol/geom/Circle~intersection] Unsupported geometry type: " + geom.getType()); } return geom; }; export { ol_coordinate_dist2d, ol_coordinate_equal, ol_coordinate_offsetCoords, ol_coordinate_findSegment }; //# sourceMappingURL=chunk-3UNEODO2.js.map