Skip to content

Commit

Permalink
refactor(Extent): move calculation of Extent intersection to static E…
Browse files Browse the repository at this point in the history
…xtent.intersectsExtent(ExtentA,ExtentB)
  • Loading branch information
ftoromanoff committed Apr 12, 2023
1 parent 4cef6ba commit 4ca93a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Converter/Feature2Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function _drawPolygon(ctx, vertices, indices, style, size, extent, invCtxScale,
// build contour
ctx.beginPath();
for (const indice of indices) {
if (indice.extent && indice.extent.intersectsExtent(extent)) {
if (indice.extent && Extent.intersectsExtent(indice.extent, extent)) {
const offset = indice.offset * size;
const count = offset + indice.count * size;
ctx.moveTo(vertices[offset], vertices[offset + 1]);
Expand Down Expand Up @@ -108,7 +108,7 @@ function drawFeature(ctx, feature, extent, style, invCtxScale) {
const globals = { zoom: extent.zoom };

for (const geometry of feature.geometries) {
if (geometry.extent.intersectsExtent(extent)) {
if (Extent.intersectsExtent(geometry.extent, extent)) {
const context = { globals, properties: () => geometry.properties };
const contextStyle = (geometry.properties.style || style).drawingStylefromContext(context);

Expand Down
14 changes: 9 additions & 5 deletions src/Core/Geographic/Extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,16 @@ class Extent {
* @returns {Boolean}
*/
intersectsExtent(extent) {
return Extent.intersectsExtent(this, extent);
}

static intersectsExtent(extentA, extentB) {
// TODO don't work when is on limit
const other = extent.crs == this.crs ? extent : extent.as(this.crs, _extent);
return !(this.west >= other.east ||
this.east <= other.west ||
this.south >= other.north ||
this.north <= other.south);
const other = extentB.crs == extentA.crs ? extentB : extentB.as(extentA.crs, _extent);
return !(extentA.west >= other.east ||
extentA.east <= other.west ||
extentA.south >= other.north ||
extentA.north <= other.south);
}

/**
Expand Down

0 comments on commit 4ca93a9

Please sign in to comment.