Do not skip moveTo calls after fill

This commit is contained in:
Andreas Hocevar
2017-01-11 17:12:46 +01:00
parent c09c7ef3e2
commit 2296ca3942
2 changed files with 39 additions and 5 deletions

View File

@@ -427,6 +427,8 @@ ol.render.canvas.Replay.prototype.replay_ = function(
this.fill_(context, viewRotation); this.fill_(context, viewRotation);
} }
++i; ++i;
prevX = NaN;
prevY = NaN;
break; break;
case ol.render.canvas.Instruction.MOVE_TO_LINE_TO: case ol.render.canvas.Instruction.MOVE_TO_LINE_TO:
d = /** @type {number} */ (instruction[1]); d = /** @type {number} */ (instruction[1]);

View File

@@ -16,18 +16,24 @@ describe('ol.render.canvas.ReplayGroup', function() {
describe('#replay', function() { describe('#replay', function() {
var context, replay, fillCount, strokeCount, beginPathCount; var context, replay, fillCount, transform;
var feature1, feature2, feature3, style1, style2, transform; var strokeCount, beginPathCount, moveToCount, lineToCount;
var feature0, feature1, feature2, feature3, style0, style1, style2;
beforeEach(function() { beforeEach(function() {
transform = ol.transform.create(); transform = ol.transform.create();
replay = new ol.render.canvas.ReplayGroup(1, [-180, -90, 180, 90], 1, false); replay = new ol.render.canvas.ReplayGroup(1, [-180, -90, 180, 90], 1, false);
feature0 = new ol.Feature(new ol.geom.Polygon(
[[[-90, 0], [-45, 45], [0, 0], [1, 1], [0, -45], [-90, 0]]]));
feature1 = new ol.Feature(new ol.geom.Polygon( feature1 = new ol.Feature(new ol.geom.Polygon(
[[[-90, -45], [-90, 0], [0, 0], [0, -45], [-90, -45]]])); [[[-90, -45], [-90, 0], [0, 0], [0, -45], [-90, -45]]]));
feature2 = new ol.Feature(new ol.geom.Polygon( feature2 = new ol.Feature(new ol.geom.Polygon(
[[[90, 45], [90, 0], [0, 0], [0, 45], [90, 45]]])); [[[90, 45], [90, 0], [0, 0], [0, 45], [90, 45]]]));
feature3 = new ol.Feature(new ol.geom.Polygon( feature3 = new ol.Feature(new ol.geom.Polygon(
[[[-90, -45], [-90, 45], [90, 45], [90, -45], [-90, -45]]])); [[[-90, -45], [-90, 45], [90, 45], [90, -45], [-90, -45]]]));
style0 = new ol.style.Style({
fill: new ol.style.Fill({color: 'black'})
});
style1 = new ol.style.Style({ style1 = new ol.style.Style({
fill: new ol.style.Fill({color: 'black'}), fill: new ol.style.Fill({color: 'black'}),
stroke: new ol.style.Stroke({color: 'white', width: 1}) stroke: new ol.style.Stroke({color: 'white', width: 1})
@@ -40,6 +46,8 @@ describe('ol.render.canvas.ReplayGroup', function() {
fillCount = 0; fillCount = 0;
strokeCount = 0; strokeCount = 0;
beginPathCount = 0; beginPathCount = 0;
moveToCount = 0;
lineToCount = 0;
context = { context = {
fill: function() { fill: function() {
fillCount++; fillCount++;
@@ -51,18 +59,42 @@ describe('ol.render.canvas.ReplayGroup', function() {
beginPathCount++; beginPathCount++;
}, },
clip: function() { clip: function() {
// remove beginPath, moveTo and lineTo counts for clipping
beginPathCount--; beginPathCount--;
moveToCount--;
lineToCount -= 3;
},
moveTo: function() {
moveToCount++;
},
lineTo: function() {
lineToCount++;
}, },
save: function() {},
moveTo: function() {},
lineTo: function() {},
closePath: function() {}, closePath: function() {},
setLineDash: function() {}, setLineDash: function() {},
save: function() {},
restore: function() {} restore: function() {}
}; };
}); });
it('omits lineTo for repeated coordinates', function() {
ol.renderer.vector.renderFeature(replay, feature0, style0, 1);
replay.replay(context, 1, transform, 0, {});
expect(lineToCount).to.be(4);
lineToCount = 0;
ol.transform.scale(transform, 0.25, 0.25);
replay.replay(context, 1, transform, 0, {});
expect(lineToCount).to.be(3);
});
it('does not omit moveTo for repeated coordinates', function() {
ol.renderer.vector.renderFeature(replay, feature0, style0, 1);
ol.renderer.vector.renderFeature(replay, feature1, style0, 1);
replay.replay(context, 1, transform, 0, {});
expect(moveToCount).to.be(2);
});
it('batches fill and stroke instructions for same style', function() { it('batches fill and stroke instructions for same style', function() {
ol.renderer.vector.renderFeature(replay, feature1, style1, 1); ol.renderer.vector.renderFeature(replay, feature1, style1, 1);
ol.renderer.vector.renderFeature(replay, feature2, style1, 1); ol.renderer.vector.renderFeature(replay, feature2, style1, 1);