Force close polygon contours (WebGL)
This commit is contained in:
@@ -352,10 +352,20 @@ ol.render.webgl.LineStringReplay.prototype.drawMultiLineString = function(multiL
|
|||||||
*/
|
*/
|
||||||
ol.render.webgl.LineStringReplay.prototype.drawPolygonCoordinates = function(
|
ol.render.webgl.LineStringReplay.prototype.drawPolygonCoordinates = function(
|
||||||
flatCoordinates, holeFlatCoordinates, stride) {
|
flatCoordinates, holeFlatCoordinates, stride) {
|
||||||
|
if (!ol.geom.flat.topology.lineStringIsClosed(flatCoordinates, 0,
|
||||||
|
flatCoordinates.length, stride)) {
|
||||||
|
flatCoordinates.push(flatCoordinates[0]);
|
||||||
|
flatCoordinates.push(flatCoordinates[1]);
|
||||||
|
}
|
||||||
this.drawCoordinates_(flatCoordinates, 0, flatCoordinates.length, stride);
|
this.drawCoordinates_(flatCoordinates, 0, flatCoordinates.length, stride);
|
||||||
if (holeFlatCoordinates.length) {
|
if (holeFlatCoordinates.length) {
|
||||||
var i, ii;
|
var i, ii;
|
||||||
for (i = 0, ii = holeFlatCoordinates.length; i < ii; ++i) {
|
for (i = 0, ii = holeFlatCoordinates.length; i < ii; ++i) {
|
||||||
|
if (!ol.geom.flat.topology.lineStringIsClosed(holeFlatCoordinates[i], 0,
|
||||||
|
holeFlatCoordinates[i].length, stride)) {
|
||||||
|
holeFlatCoordinates[i].push(holeFlatCoordinates[i][0]);
|
||||||
|
holeFlatCoordinates[i].push(holeFlatCoordinates[i][1]);
|
||||||
|
}
|
||||||
this.drawCoordinates_(holeFlatCoordinates[i], 0,
|
this.drawCoordinates_(holeFlatCoordinates[i], 0,
|
||||||
holeFlatCoordinates[i].length, stride);
|
holeFlatCoordinates[i].length, stride);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,25 +37,25 @@ describe('ol.render.webgl.PolygonReplay', function() {
|
|||||||
[[[1000, 2000], [1200, 2000], [1200, 3000]]]
|
[[[1000, 2000], [1200, 2000], [1200, 3000]]]
|
||||||
);
|
);
|
||||||
replay.drawPolygon(polygon1, null);
|
replay.drawPolygon(polygon1, null);
|
||||||
expect(replay.vertices).to.have.length(6);
|
expect(replay.vertices).to.have.length(8);
|
||||||
expect(replay.indices).to.have.length(3);
|
expect(replay.indices).to.have.length(3);
|
||||||
|
|
||||||
expect(replay.vertices).to.eql([
|
expect(replay.vertices).to.eql([
|
||||||
1200, 3000, 1200, 2000, 1000, 2000]);
|
1000, 2000, 1200, 3000, 1200, 2000, 1000, 2000]);
|
||||||
expect(replay.indices).to.eql([2, 0, 1]);
|
expect(replay.indices).to.eql([2, 0, 1]);
|
||||||
|
|
||||||
var polygon2 = new ol.geom.Polygon(
|
var polygon2 = new ol.geom.Polygon(
|
||||||
[[[4000, 2000], [4200, 2000], [4200, 3000]]]
|
[[[4000, 2000], [4200, 2000], [4200, 3000]]]
|
||||||
);
|
);
|
||||||
replay.drawPolygon(polygon2, null);
|
replay.drawPolygon(polygon2, null);
|
||||||
expect(replay.vertices).to.have.length(12);
|
expect(replay.vertices).to.have.length(16);
|
||||||
expect(replay.indices).to.have.length(6);
|
expect(replay.indices).to.have.length(6);
|
||||||
|
|
||||||
expect(replay.vertices).to.eql([
|
expect(replay.vertices).to.eql([
|
||||||
1200, 3000, 1200, 2000, 1000, 2000,
|
1000, 2000, 1200, 3000, 1200, 2000, 1000, 2000,
|
||||||
4200, 3000, 4200, 2000, 4000, 2000
|
4000, 2000, 4200, 3000, 4200, 2000, 4000, 2000
|
||||||
]);
|
]);
|
||||||
expect(replay.indices).to.eql([2, 0, 1, 5, 3, 4]);
|
expect(replay.indices).to.eql([2, 0, 1, 6, 4, 5]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -70,14 +70,14 @@ describe('ol.render.webgl.PolygonReplay', function() {
|
|||||||
[[[4000, 2000], [4200, 2000], [4200, 3000]]]
|
[[[4000, 2000], [4200, 2000], [4200, 3000]]]
|
||||||
]);
|
]);
|
||||||
replay.drawMultiPolygon(multiPolygon, null);
|
replay.drawMultiPolygon(multiPolygon, null);
|
||||||
expect(replay.vertices).to.have.length(12);
|
expect(replay.vertices).to.have.length(16);
|
||||||
expect(replay.indices).to.have.length(6);
|
expect(replay.indices).to.have.length(6);
|
||||||
|
|
||||||
expect(replay.vertices).to.eql([
|
expect(replay.vertices).to.eql([
|
||||||
1200, 3000, 1200, 2000, 1000, 2000,
|
1000, 2000, 1200, 3000, 1200, 2000, 1000, 2000,
|
||||||
4200, 3000, 4200, 2000, 4000, 2000
|
4000, 2000, 4200, 3000, 4200, 2000, 4000, 2000
|
||||||
]);
|
]);
|
||||||
expect(replay.indices).to.eql([2, 0, 1, 5, 3, 4]);
|
expect(replay.indices).to.eql([2, 0, 1, 6, 4, 5]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user