Merge pull request #10463 from pjsg/fix_triangulation
Fix issue with reprojection and double drawing pixels.
This commit is contained in:
@@ -7,9 +7,9 @@ import Tile from '../Tile.js';
|
||||
import TileState from '../TileState.js';
|
||||
import {listen, unlistenByKey} from '../events.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import {getArea, getCenter, getIntersection} from '../extent.js';
|
||||
import {getArea, getIntersection} from '../extent.js';
|
||||
import {clamp} from '../math.js';
|
||||
import {calculateSourceResolution, render as renderReprojected} from '../reproj.js';
|
||||
import {calculateSourceExtentResolution, render as renderReprojected} from '../reproj.js';
|
||||
import Triangulation from './Triangulation.js';
|
||||
|
||||
|
||||
@@ -148,9 +148,8 @@ class ReprojTile extends Tile {
|
||||
const targetResolution = targetTileGrid.getResolution(
|
||||
this.wrappedTileCoord_[0]);
|
||||
|
||||
const targetCenter = getCenter(limitedTargetExtent);
|
||||
const sourceResolution = calculateSourceResolution(
|
||||
sourceProj, targetProj, targetCenter, targetResolution);
|
||||
const sourceResolution = calculateSourceExtentResolution(
|
||||
sourceProj, targetProj, limitedTargetExtent, targetResolution);
|
||||
|
||||
if (!isFinite(sourceResolution) || sourceResolution <= 0) {
|
||||
// invalid sourceResolution -> EMPTY
|
||||
|
||||
@@ -263,12 +263,19 @@ class Triangulation {
|
||||
}
|
||||
|
||||
if (!needsSubdivision && this.maxSourceExtent_) {
|
||||
if (!intersects(sourceQuadExtent, this.maxSourceExtent_)) {
|
||||
// whole quad outside source projection extent -> ignore
|
||||
return;
|
||||
if (isFinite(sourceQuadExtent[0]) &&
|
||||
isFinite(sourceQuadExtent[1]) &&
|
||||
isFinite(sourceQuadExtent[2]) &&
|
||||
isFinite(sourceQuadExtent[3])) {
|
||||
if (!intersects(sourceQuadExtent, this.maxSourceExtent_)) {
|
||||
// whole quad outside source projection extent -> ignore
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let isNotFinite = 0;
|
||||
|
||||
if (!needsSubdivision) {
|
||||
if (!isFinite(aSrc[0]) || !isFinite(aSrc[1]) ||
|
||||
!isFinite(bSrc[0]) || !isFinite(bSrc[1]) ||
|
||||
@@ -277,7 +284,16 @@ class Triangulation {
|
||||
if (maxSubdivision > 0) {
|
||||
needsSubdivision = true;
|
||||
} else {
|
||||
return;
|
||||
// It might be the case that only 1 of the points is infinite. In this case
|
||||
// we can draw a single triangle with the other three points
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,8 +352,25 @@ class Triangulation {
|
||||
this.wrapsXInSource_ = true;
|
||||
}
|
||||
|
||||
this.addTriangle_(a, c, d, aSrc, cSrc, dSrc);
|
||||
this.addTriangle_(a, b, c, aSrc, bSrc, cSrc);
|
||||
// Exactly zero or one of *Src is not finite
|
||||
// The triangles must have the diagonal line as the first side
|
||||
// This is to allow easy code in reproj.s to make it straight for broken
|
||||
// browsers that can't handle diagonal clipping
|
||||
if ((isNotFinite & 0xb) == 0) {
|
||||
this.addTriangle_(a, c, d, aSrc, cSrc, dSrc);
|
||||
}
|
||||
if ((isNotFinite & 0xe) == 0) {
|
||||
this.addTriangle_(a, c, b, aSrc, cSrc, bSrc);
|
||||
}
|
||||
if (isNotFinite) {
|
||||
// Try the other two triangles
|
||||
if ((isNotFinite & 0xd) == 0) {
|
||||
this.addTriangle_(b, d, a, bSrc, dSrc, aSrc);
|
||||
}
|
||||
if ((isNotFinite & 0x7) == 0) {
|
||||
this.addTriangle_(b, d, c, bSrc, dSrc, cSrc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user