SourceTermAnalysisSystem_vue/node_modules/.vite/deps/chunk-4YO3ZZ7L.js
2026-05-15 10:22:44 +08:00

624 lines
22 KiB
JavaScript

import {
createCanvasContext2D,
releaseCanvas
} from "./chunk-YWIWRQT2.js";
import {
apply
} from "./chunk-JFONEOYG.js";
import {
createTransformFromCoordinateTransform,
getPointResolution,
getTransform,
transform
} from "./chunk-XZU4LSFD.js";
import {
modulo,
solveLinearSystem
} from "./chunk-54BTDBAD.js";
import {
boundingExtent,
containsCoordinate,
createEmpty,
extend,
extendCoordinate,
forEachCorner,
getArea,
getBottomLeft,
getBottomRight,
getCenter,
getHeight,
getTopLeft,
getTopRight,
getWidth,
intersects
} from "./chunk-CKDBVGKM.js";
// node_modules/ol/reproj.js
var brokenDiagonalRendering_;
var canvasPool = [];
function drawTestTriangle(ctx, u1, v1, u2, v2) {
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(u1, v1);
ctx.lineTo(u2, v2);
ctx.closePath();
ctx.save();
ctx.clip();
ctx.fillRect(0, 0, Math.max(u1, u2) + 1, Math.max(v1, v2));
ctx.restore();
}
function verifyBrokenDiagonalRendering(data, offset) {
return Math.abs(data[offset * 4] - 210) > 2 || Math.abs(data[offset * 4 + 3] - 0.75 * 255) > 2;
}
function isBrokenDiagonalRendering() {
if (brokenDiagonalRendering_ === void 0) {
const ctx = createCanvasContext2D(6, 6, canvasPool);
ctx.globalCompositeOperation = "lighter";
ctx.fillStyle = "rgba(210, 0, 0, 0.75)";
drawTestTriangle(ctx, 4, 5, 4, 0);
drawTestTriangle(ctx, 4, 5, 0, 5);
const data = ctx.getImageData(0, 0, 3, 3).data;
brokenDiagonalRendering_ = verifyBrokenDiagonalRendering(data, 0) || verifyBrokenDiagonalRendering(data, 4) || verifyBrokenDiagonalRendering(data, 8);
releaseCanvas(ctx);
canvasPool.push(ctx.canvas);
}
return brokenDiagonalRendering_;
}
function calculateSourceResolution(sourceProj, targetProj, targetCenter, targetResolution) {
const sourceCenter = transform(targetCenter, targetProj, sourceProj);
let sourceResolution = getPointResolution(
targetProj,
targetResolution,
targetCenter
);
const targetMetersPerUnit = targetProj.getMetersPerUnit();
if (targetMetersPerUnit !== void 0) {
sourceResolution *= targetMetersPerUnit;
}
const sourceMetersPerUnit = sourceProj.getMetersPerUnit();
if (sourceMetersPerUnit !== void 0) {
sourceResolution /= sourceMetersPerUnit;
}
const sourceExtent = sourceProj.getExtent();
if (!sourceExtent || containsCoordinate(sourceExtent, sourceCenter)) {
const compensationFactor = getPointResolution(sourceProj, sourceResolution, sourceCenter) / sourceResolution;
if (isFinite(compensationFactor) && compensationFactor > 0) {
sourceResolution /= compensationFactor;
}
}
return sourceResolution;
}
function calculateSourceExtentResolution(sourceProj, targetProj, targetExtent, targetResolution) {
const targetCenter = getCenter(targetExtent);
let sourceResolution = calculateSourceResolution(
sourceProj,
targetProj,
targetCenter,
targetResolution
);
if (!isFinite(sourceResolution) || sourceResolution <= 0) {
forEachCorner(targetExtent, function(corner) {
sourceResolution = calculateSourceResolution(
sourceProj,
targetProj,
corner,
targetResolution
);
return isFinite(sourceResolution) && sourceResolution > 0;
});
}
return sourceResolution;
}
function render(width, height, pixelRatio, sourceResolution, sourceExtent, targetResolution, targetExtent, triangulation, sources, gutter, renderEdges, interpolate, drawSingle, clipExtent) {
const context = createCanvasContext2D(
Math.round(pixelRatio * width),
Math.round(pixelRatio * height),
canvasPool
);
if (!interpolate) {
context.imageSmoothingEnabled = false;
}
if (sources.length === 0) {
return context.canvas;
}
context.scale(pixelRatio, pixelRatio);
function pixelRound(value) {
return Math.round(value * pixelRatio) / pixelRatio;
}
context.globalCompositeOperation = "lighter";
const sourceDataExtent = createEmpty();
sources.forEach(function(src, i, arr) {
extend(sourceDataExtent, src.extent);
});
let stitchContext;
const stitchScale = pixelRatio / sourceResolution;
const inverseScale = (interpolate ? 1 : 1 + Math.pow(2, -24)) / stitchScale;
if (!drawSingle || sources.length !== 1 || gutter !== 0) {
stitchContext = createCanvasContext2D(
Math.round(getWidth(sourceDataExtent) * stitchScale),
Math.round(getHeight(sourceDataExtent) * stitchScale),
canvasPool
);
if (!interpolate) {
stitchContext.imageSmoothingEnabled = false;
}
if (sourceExtent && clipExtent) {
const xPos = (sourceExtent[0] - sourceDataExtent[0]) * stitchScale;
const yPos = -(sourceExtent[3] - sourceDataExtent[3]) * stitchScale;
const width2 = getWidth(sourceExtent) * stitchScale;
const height2 = getHeight(sourceExtent) * stitchScale;
stitchContext.rect(xPos, yPos, width2, height2);
stitchContext.clip();
}
sources.forEach(function(src, i, arr) {
if (src.image.width > 0 && src.image.height > 0) {
if (src.clipExtent) {
stitchContext.save();
const xPos2 = (src.clipExtent[0] - sourceDataExtent[0]) * stitchScale;
const yPos2 = -(src.clipExtent[3] - sourceDataExtent[3]) * stitchScale;
const width2 = getWidth(src.clipExtent) * stitchScale;
const height2 = getHeight(src.clipExtent) * stitchScale;
stitchContext.rect(
interpolate ? xPos2 : Math.round(xPos2),
interpolate ? yPos2 : Math.round(yPos2),
interpolate ? width2 : Math.round(xPos2 + width2) - Math.round(xPos2),
interpolate ? height2 : Math.round(yPos2 + height2) - Math.round(yPos2)
);
stitchContext.clip();
}
const xPos = (src.extent[0] - sourceDataExtent[0]) * stitchScale;
const yPos = -(src.extent[3] - sourceDataExtent[3]) * stitchScale;
const srcWidth = getWidth(src.extent) * stitchScale;
const srcHeight = getHeight(src.extent) * stitchScale;
stitchContext.drawImage(
src.image,
gutter,
gutter,
src.image.width - 2 * gutter,
src.image.height - 2 * gutter,
interpolate ? xPos : Math.round(xPos),
interpolate ? yPos : Math.round(yPos),
interpolate ? srcWidth : Math.round(xPos + srcWidth) - Math.round(xPos),
interpolate ? srcHeight : Math.round(yPos + srcHeight) - Math.round(yPos)
);
if (src.clipExtent) {
stitchContext.restore();
}
}
});
}
const targetTopLeft = getTopLeft(targetExtent);
triangulation.getTriangles().forEach(function(triangle, i, arr) {
const source = triangle.source;
const target = triangle.target;
let x0 = source[0][0], y0 = source[0][1];
let x1 = source[1][0], y1 = source[1][1];
let x2 = source[2][0], y2 = source[2][1];
const u0 = pixelRound((target[0][0] - targetTopLeft[0]) / targetResolution);
const v0 = pixelRound(
-(target[0][1] - targetTopLeft[1]) / targetResolution
);
const u1 = pixelRound((target[1][0] - targetTopLeft[0]) / targetResolution);
const v1 = pixelRound(
-(target[1][1] - targetTopLeft[1]) / targetResolution
);
const u2 = pixelRound((target[2][0] - targetTopLeft[0]) / targetResolution);
const v2 = pixelRound(
-(target[2][1] - targetTopLeft[1]) / targetResolution
);
const sourceNumericalShiftX = x0;
const sourceNumericalShiftY = y0;
x0 = 0;
y0 = 0;
x1 -= sourceNumericalShiftX;
y1 -= sourceNumericalShiftY;
x2 -= sourceNumericalShiftX;
y2 -= sourceNumericalShiftY;
const augmentedMatrix = [
[x1, y1, 0, 0, u1 - u0],
[x2, y2, 0, 0, u2 - u0],
[0, 0, x1, y1, v1 - v0],
[0, 0, x2, y2, v2 - v0]
];
const affineCoefs = solveLinearSystem(augmentedMatrix);
if (!affineCoefs) {
return;
}
context.save();
context.beginPath();
if (isBrokenDiagonalRendering() || !interpolate) {
context.moveTo(u1, v1);
const steps = 4;
const ud = u0 - u1;
const vd = v0 - v1;
for (let step = 0; step < steps; step++) {
context.lineTo(
u1 + pixelRound((step + 1) * ud / steps),
v1 + pixelRound(step * vd / (steps - 1))
);
if (step != steps - 1) {
context.lineTo(
u1 + pixelRound((step + 1) * ud / steps),
v1 + pixelRound((step + 1) * vd / (steps - 1))
);
}
}
context.lineTo(u2, v2);
} else {
context.moveTo(u1, v1);
context.lineTo(u0, v0);
context.lineTo(u2, v2);
}
context.clip();
context.transform(
affineCoefs[0],
affineCoefs[2],
affineCoefs[1],
affineCoefs[3],
u0,
v0
);
context.translate(
sourceDataExtent[0] - sourceNumericalShiftX,
sourceDataExtent[3] - sourceNumericalShiftY
);
let image;
if (stitchContext) {
image = stitchContext.canvas;
context.scale(inverseScale, -inverseScale);
} else {
const source2 = sources[0];
const extent = source2.extent;
image = source2.image;
context.scale(
getWidth(extent) / image.width,
-getHeight(extent) / image.height
);
}
context.drawImage(image, 0, 0);
context.restore();
});
if (stitchContext) {
releaseCanvas(stitchContext);
canvasPool.push(stitchContext.canvas);
}
if (renderEdges) {
context.save();
context.globalCompositeOperation = "source-over";
context.strokeStyle = "black";
context.lineWidth = 1;
triangulation.getTriangles().forEach(function(triangle, i, arr) {
const target = triangle.target;
const u0 = (target[0][0] - targetTopLeft[0]) / targetResolution;
const v0 = -(target[0][1] - targetTopLeft[1]) / targetResolution;
const u1 = (target[1][0] - targetTopLeft[0]) / targetResolution;
const v1 = -(target[1][1] - targetTopLeft[1]) / targetResolution;
const u2 = (target[2][0] - targetTopLeft[0]) / targetResolution;
const v2 = -(target[2][1] - targetTopLeft[1]) / targetResolution;
context.beginPath();
context.moveTo(u1, v1);
context.lineTo(u0, v0);
context.lineTo(u2, v2);
context.closePath();
context.stroke();
});
context.restore();
}
return context.canvas;
}
// node_modules/ol/reproj/Triangulation.js
var MAX_SUBDIVISION = 10;
var MAX_TRIANGLE_WIDTH = 0.25;
var Triangulation = class {
/**
* @param {import("../proj/Projection.js").default} sourceProj Source projection.
* @param {import("../proj/Projection.js").default} targetProj Target projection.
* @param {import("../extent.js").Extent} targetExtent Target extent to triangulate.
* @param {import("../extent.js").Extent} maxSourceExtent Maximal source extent that can be used.
* @param {number} errorThreshold Acceptable error (in source units).
* @param {?number} destinationResolution The (optional) resolution of the destination.
* @param {import("../transform.js").Transform} [sourceMatrix] Source transform matrix.
*/
constructor(sourceProj, targetProj, targetExtent, maxSourceExtent, errorThreshold, destinationResolution, sourceMatrix) {
this.sourceProj_ = sourceProj;
this.targetProj_ = targetProj;
let transformInvCache = {};
const transformInv = sourceMatrix ? createTransformFromCoordinateTransform(
(input) => apply(
sourceMatrix,
transform(input, this.targetProj_, this.sourceProj_)
)
) : getTransform(this.targetProj_, this.sourceProj_);
this.transformInv_ = function(c) {
const key = c[0] + "/" + c[1];
if (!transformInvCache[key]) {
transformInvCache[key] = transformInv(c);
}
return transformInvCache[key];
};
this.maxSourceExtent_ = maxSourceExtent;
this.errorThresholdSquared_ = errorThreshold * errorThreshold;
this.triangles_ = [];
this.wrapsXInSource_ = false;
this.canWrapXInSource_ = this.sourceProj_.canWrapX() && !!maxSourceExtent && !!this.sourceProj_.getExtent() && getWidth(maxSourceExtent) >= getWidth(this.sourceProj_.getExtent());
this.sourceWorldWidth_ = this.sourceProj_.getExtent() ? getWidth(this.sourceProj_.getExtent()) : null;
this.targetWorldWidth_ = this.targetProj_.getExtent() ? getWidth(this.targetProj_.getExtent()) : null;
const destinationTopLeft = getTopLeft(targetExtent);
const destinationTopRight = getTopRight(targetExtent);
const destinationBottomRight = getBottomRight(targetExtent);
const destinationBottomLeft = getBottomLeft(targetExtent);
const sourceTopLeft = this.transformInv_(destinationTopLeft);
const sourceTopRight = this.transformInv_(destinationTopRight);
const sourceBottomRight = this.transformInv_(destinationBottomRight);
const sourceBottomLeft = this.transformInv_(destinationBottomLeft);
const maxSubdivision = MAX_SUBDIVISION + (destinationResolution ? Math.max(
0,
Math.ceil(
Math.log2(
getArea(targetExtent) / (destinationResolution * destinationResolution * 256 * 256)
)
)
) : 0);
this.addQuad_(
destinationTopLeft,
destinationTopRight,
destinationBottomRight,
destinationBottomLeft,
sourceTopLeft,
sourceTopRight,
sourceBottomRight,
sourceBottomLeft,
maxSubdivision
);
if (this.wrapsXInSource_) {
let leftBound = Infinity;
this.triangles_.forEach(function(triangle, i, arr) {
leftBound = Math.min(
leftBound,
triangle.source[0][0],
triangle.source[1][0],
triangle.source[2][0]
);
});
this.triangles_.forEach((triangle) => {
if (Math.max(
triangle.source[0][0],
triangle.source[1][0],
triangle.source[2][0]
) - leftBound > this.sourceWorldWidth_ / 2) {
const newTriangle = [
[triangle.source[0][0], triangle.source[0][1]],
[triangle.source[1][0], triangle.source[1][1]],
[triangle.source[2][0], triangle.source[2][1]]
];
if (newTriangle[0][0] - leftBound > this.sourceWorldWidth_ / 2) {
newTriangle[0][0] -= this.sourceWorldWidth_;
}
if (newTriangle[1][0] - leftBound > this.sourceWorldWidth_ / 2) {
newTriangle[1][0] -= this.sourceWorldWidth_;
}
if (newTriangle[2][0] - leftBound > this.sourceWorldWidth_ / 2) {
newTriangle[2][0] -= this.sourceWorldWidth_;
}
const minX = Math.min(
newTriangle[0][0],
newTriangle[1][0],
newTriangle[2][0]
);
const maxX = Math.max(
newTriangle[0][0],
newTriangle[1][0],
newTriangle[2][0]
);
if (maxX - minX < this.sourceWorldWidth_ / 2) {
triangle.source = newTriangle;
}
}
});
}
transformInvCache = {};
}
/**
* Adds triangle to the triangulation.
* @param {import("../coordinate.js").Coordinate} a The target a coordinate.
* @param {import("../coordinate.js").Coordinate} b The target b coordinate.
* @param {import("../coordinate.js").Coordinate} c The target c coordinate.
* @param {import("../coordinate.js").Coordinate} aSrc The source a coordinate.
* @param {import("../coordinate.js").Coordinate} bSrc The source b coordinate.
* @param {import("../coordinate.js").Coordinate} cSrc The source c coordinate.
* @private
*/
addTriangle_(a, b, c, aSrc, bSrc, cSrc) {
this.triangles_.push({
source: [aSrc, bSrc, cSrc],
target: [a, b, c]
});
}
/**
* Adds quad (points in clock-wise order) to the triangulation
* (and reprojects the vertices) if valid.
* Performs quad subdivision if needed to increase precision.
*
* @param {import("../coordinate.js").Coordinate} a The target a coordinate.
* @param {import("../coordinate.js").Coordinate} b The target b coordinate.
* @param {import("../coordinate.js").Coordinate} c The target c coordinate.
* @param {import("../coordinate.js").Coordinate} d The target d coordinate.
* @param {import("../coordinate.js").Coordinate} aSrc The source a coordinate.
* @param {import("../coordinate.js").Coordinate} bSrc The source b coordinate.
* @param {import("../coordinate.js").Coordinate} cSrc The source c coordinate.
* @param {import("../coordinate.js").Coordinate} dSrc The source d coordinate.
* @param {number} maxSubdivision Maximal allowed subdivision of the quad.
* @private
*/
addQuad_(a, b, c, d, aSrc, bSrc, cSrc, dSrc, maxSubdivision) {
const sourceQuadExtent = boundingExtent([aSrc, bSrc, cSrc, dSrc]);
const sourceCoverageX = this.sourceWorldWidth_ ? getWidth(sourceQuadExtent) / this.sourceWorldWidth_ : null;
const sourceWorldWidth = (
/** @type {number} */
this.sourceWorldWidth_
);
const wrapsX = this.sourceProj_.canWrapX() && sourceCoverageX > 0.5 && sourceCoverageX < 1;
let needsSubdivision = false;
if (maxSubdivision > 0) {
if (this.targetProj_.isGlobal() && this.targetWorldWidth_) {
const targetQuadExtent = boundingExtent([a, b, c, d]);
const targetCoverageX = getWidth(targetQuadExtent) / this.targetWorldWidth_;
needsSubdivision = targetCoverageX > MAX_TRIANGLE_WIDTH || needsSubdivision;
}
if (!wrapsX && this.sourceProj_.isGlobal() && sourceCoverageX) {
needsSubdivision = sourceCoverageX > MAX_TRIANGLE_WIDTH || needsSubdivision;
}
}
if (!needsSubdivision && this.maxSourceExtent_) {
if (isFinite(sourceQuadExtent[0]) && isFinite(sourceQuadExtent[1]) && isFinite(sourceQuadExtent[2]) && isFinite(sourceQuadExtent[3])) {
if (!intersects(sourceQuadExtent, this.maxSourceExtent_)) {
return;
}
}
}
let isNotFinite = 0;
if (!needsSubdivision) {
if (!isFinite(aSrc[0]) || !isFinite(aSrc[1]) || !isFinite(bSrc[0]) || !isFinite(bSrc[1]) || !isFinite(cSrc[0]) || !isFinite(cSrc[1]) || !isFinite(dSrc[0]) || !isFinite(dSrc[1])) {
if (maxSubdivision > 0) {
needsSubdivision = true;
} else {
isNotFinite = (!isFinite(aSrc[0]) || !isFinite(aSrc[1]) ? 8 : 0) + (!isFinite(bSrc[0]) || !isFinite(bSrc[1]) ? 4 : 0) + (!isFinite(cSrc[0]) || !isFinite(cSrc[1]) ? 2 : 0) + (!isFinite(dSrc[0]) || !isFinite(dSrc[1]) ? 1 : 0);
if (isNotFinite != 1 && isNotFinite != 2 && isNotFinite != 4 && isNotFinite != 8) {
return;
}
}
}
}
if (maxSubdivision > 0) {
if (!needsSubdivision) {
const center = [(a[0] + c[0]) / 2, (a[1] + c[1]) / 2];
const centerSrc = this.transformInv_(center);
let dx;
if (wrapsX) {
const centerSrcEstimX = (modulo(aSrc[0], sourceWorldWidth) + modulo(cSrc[0], sourceWorldWidth)) / 2;
dx = centerSrcEstimX - modulo(centerSrc[0], sourceWorldWidth);
} else {
dx = (aSrc[0] + cSrc[0]) / 2 - centerSrc[0];
}
const dy = (aSrc[1] + cSrc[1]) / 2 - centerSrc[1];
const centerSrcErrorSquared = dx * dx + dy * dy;
needsSubdivision = centerSrcErrorSquared > this.errorThresholdSquared_;
}
if (needsSubdivision) {
if (Math.abs(a[0] - c[0]) <= Math.abs(a[1] - c[1])) {
const bc = [(b[0] + c[0]) / 2, (b[1] + c[1]) / 2];
const bcSrc = this.transformInv_(bc);
const da = [(d[0] + a[0]) / 2, (d[1] + a[1]) / 2];
const daSrc = this.transformInv_(da);
this.addQuad_(
a,
b,
bc,
da,
aSrc,
bSrc,
bcSrc,
daSrc,
maxSubdivision - 1
);
this.addQuad_(
da,
bc,
c,
d,
daSrc,
bcSrc,
cSrc,
dSrc,
maxSubdivision - 1
);
} else {
const ab = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
const abSrc = this.transformInv_(ab);
const cd = [(c[0] + d[0]) / 2, (c[1] + d[1]) / 2];
const cdSrc = this.transformInv_(cd);
this.addQuad_(
a,
ab,
cd,
d,
aSrc,
abSrc,
cdSrc,
dSrc,
maxSubdivision - 1
);
this.addQuad_(
ab,
b,
c,
cd,
abSrc,
bSrc,
cSrc,
cdSrc,
maxSubdivision - 1
);
}
return;
}
}
if (wrapsX) {
if (!this.canWrapXInSource_) {
return;
}
this.wrapsXInSource_ = true;
}
if ((isNotFinite & 11) == 0) {
this.addTriangle_(a, c, d, aSrc, cSrc, dSrc);
}
if ((isNotFinite & 14) == 0) {
this.addTriangle_(a, c, b, aSrc, cSrc, bSrc);
}
if (isNotFinite) {
if ((isNotFinite & 13) == 0) {
this.addTriangle_(b, d, a, bSrc, dSrc, aSrc);
}
if ((isNotFinite & 7) == 0) {
this.addTriangle_(b, d, c, bSrc, dSrc, cSrc);
}
}
}
/**
* Calculates extent of the `source` coordinates from all the triangles.
*
* @return {import("../extent.js").Extent} Calculated extent.
*/
calculateSourceExtent() {
const extent = createEmpty();
this.triangles_.forEach(function(triangle, i, arr) {
const src = triangle.source;
extendCoordinate(extent, src[0]);
extendCoordinate(extent, src[1]);
extendCoordinate(extent, src[2]);
});
return extent;
}
/**
* @return {Array<Triangle>} Array of the calculated triangles.
*/
getTriangles() {
return this.triangles_;
}
};
var Triangulation_default = Triangulation;
// node_modules/ol/reproj/common.js
var ERROR_THRESHOLD = 0.5;
export {
canvasPool,
calculateSourceResolution,
calculateSourceExtentResolution,
render,
Triangulation_default,
ERROR_THRESHOLD
};
//# sourceMappingURL=chunk-4YO3ZZ7L.js.map