Skip to content

Commit

Permalink
Clipping polygong rectangle caching
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl committed Oct 19, 2024
1 parent 0e9a425 commit f17221b
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion packages/engine/Source/Scene/ClippingPolygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,54 @@ ClippingPolygon.equals = function (left, right) {
);
};

function equalArrayCartesian3(a, b) {
if (defined(a) !== defined(b)) {
return false;
}
if (a.length !== b.length) {
return false;
}
const n = a.length;
for (let i = 0; i < n; i++) {
const ca = a[i];
const cb = b[i];
if (!Cartesian3.equals(ca, cb)) {
return false;
}
}
return true;
}

/**
* Computes a cartographic rectangle which encloses the polygon defined by the list of positions, including cases over the international date line and the poles.
*
* @param {Rectangle} [result] An object in which to store the result.
* @returns {Rectangle} The result rectangle
*/
ClippingPolygon.prototype.computeRectangle = function (result) {
return PolygonGeometry.computeRectangleFromPositions(
// XXX EXPERIMENT!!!
if (ClippingPolygon.hackyCaching) {
if (equalArrayCartesian3(this.positions, this._cachedPositions)) {
return this._cachedRectangle;
}
this._cachedPositions = this.positions.map((c) => Cartesian3.clone(c));
const rectangle = PolygonGeometry.computeRectangleFromPositions(
this.positions,
this.ellipsoid,
undefined,
result,
);
this._cachedRectangle = rectangle;
return rectangle;
}
// XXX EXPERIMENT!!!
const rectangle = PolygonGeometry.computeRectangleFromPositions(
this.positions,
this.ellipsoid,
undefined,
result,
);
return rectangle;
};

const scratchRectangle = new Rectangle();
Expand Down

0 comments on commit f17221b

Please sign in to comment.