Fix tests
This commit is contained in:
@@ -7,10 +7,11 @@ import MultiPoint from '../../../../../src/ol/geom/MultiPoint.js';
|
|||||||
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
|
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
|
||||||
import Point from '../../../../../src/ol/geom/Point.js';
|
import Point from '../../../../../src/ol/geom/Point.js';
|
||||||
import Polygon from '../../../../../src/ol/geom/Polygon.js';
|
import Polygon from '../../../../../src/ol/geom/Polygon.js';
|
||||||
import CanvasLineStringReplay from '../../../../../src/ol/render/canvas/LineStringBuilder.js';
|
import CanvasLineStringBuilder from '../../../../../src/ol/render/canvas/LineStringBuilder.js';
|
||||||
import CanvasPolygonReplay from '../../../../../src/ol/render/canvas/PolygonBuilder.js';
|
import CanvasPolygonBuilder from '../../../../../src/ol/render/canvas/PolygonBuilder.js';
|
||||||
import CanvasReplay from '../../../../../src/ol/render/canvas/InstructionsBuilder.js';
|
import CanvasReplay from '../../../../../src/ol/render/canvas/InstructionsBuilder.js';
|
||||||
import CanvasReplayGroup from '../../../../../src/ol/render/canvas/InstructionsGroupBuilder.js';
|
import CanvasInstructionsGroupBuilder from '../../../../../src/ol/render/canvas/InstructionsGroupBuilder.js';
|
||||||
|
import CanvasInstructionsGroupExecutor from '../../../../../src/ol/render/canvas/InstructionsGroupExecutor.js';
|
||||||
import {renderFeature} from '../../../../../src/ol/renderer/vector.js';
|
import {renderFeature} from '../../../../../src/ol/renderer/vector.js';
|
||||||
import Fill from '../../../../../src/ol/style/Fill.js';
|
import Fill from '../../../../../src/ol/style/Fill.js';
|
||||||
import Stroke from '../../../../../src/ol/style/Stroke.js';
|
import Stroke from '../../../../../src/ol/style/Stroke.js';
|
||||||
@@ -21,14 +22,15 @@ describe('ol.render.canvas.ReplayGroup', function() {
|
|||||||
|
|
||||||
describe('#replay', function() {
|
describe('#replay', function() {
|
||||||
|
|
||||||
let context, replay, fillCount, transform;
|
let context, builder, executor, fillCount, transform;
|
||||||
let strokeCount, beginPathCount, moveToCount, lineToCount;
|
let strokeCount, beginPathCount, moveToCount, lineToCount;
|
||||||
let feature0, feature1, feature2, feature3;
|
let feature0, feature1, feature2, feature3;
|
||||||
let fill0, fill1, style1, style2;
|
let fill0, fill1, style1, style2;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
transform = createTransform();
|
transform = createTransform();
|
||||||
replay = new CanvasReplayGroup(1, [-180, -90, 180, 90], 1, 1, false);
|
builder = new CanvasInstructionsGroupBuilder(1, [-180, -90, 180, 90], 1, 1, false);
|
||||||
|
executor = new CanvasInstructionsGroupExecutor(1, [-180, -90, 180, 90], 1, 1, false);
|
||||||
feature0 = new Feature(new Polygon(
|
feature0 = new Feature(new Polygon(
|
||||||
[[[-90, 0], [-45, 45], [0, 0], [1, 1], [0, -45], [-90, 0]]]));
|
[[[-90, 0], [-45, 45], [0, 0], [1, 1], [0, -45], [-90, 0]]]));
|
||||||
feature1 = new Feature(new Polygon(
|
feature1 = new Feature(new Polygon(
|
||||||
@@ -88,95 +90,106 @@ describe('ol.render.canvas.ReplayGroup', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('omits lineTo for repeated coordinates', function() {
|
it('omits lineTo for repeated coordinates', function() {
|
||||||
renderFeature(replay, feature0, fill0, 1);
|
renderFeature(builder, feature0, fill0, 1);
|
||||||
replay.replay(context, transform, 0, {});
|
executor.replaceInstructions(builder.finish());
|
||||||
|
executor.replay(context, transform, 0, {});
|
||||||
expect(lineToCount).to.be(4);
|
expect(lineToCount).to.be(4);
|
||||||
lineToCount = 0;
|
lineToCount = 0;
|
||||||
scaleTransform(transform, 0.25, 0.25);
|
scaleTransform(transform, 0.25, 0.25);
|
||||||
replay.replay(context, transform, 0, {});
|
executor.replaceInstructions(builder.finish());
|
||||||
|
executor.replay(context, transform, 0, {});
|
||||||
expect(lineToCount).to.be(3);
|
expect(lineToCount).to.be(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not omit moveTo for repeated coordinates', function() {
|
it('does not omit moveTo for repeated coordinates', function() {
|
||||||
renderFeature(replay, feature0, fill0, 1);
|
renderFeature(builder, feature0, fill0, 1);
|
||||||
renderFeature(replay, feature1, fill1, 1);
|
renderFeature(builder, feature1, fill1, 1);
|
||||||
replay.replay(context, transform, 0, {});
|
executor.replaceInstructions(builder.finish());
|
||||||
|
executor.replay(context, transform, 0, {});
|
||||||
expect(moveToCount).to.be(2);
|
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() {
|
||||||
renderFeature(replay, feature1, style1, 1);
|
renderFeature(builder, feature1, style1, 1);
|
||||||
renderFeature(replay, feature2, style1, 1);
|
renderFeature(builder, feature2, style1, 1);
|
||||||
renderFeature(replay, feature3, style1, 1);
|
renderFeature(builder, feature3, style1, 1);
|
||||||
replay.replay(context, transform, 0, {});
|
executor.replaceInstructions(builder.finish());
|
||||||
|
executor.replay(context, transform, 0, {});
|
||||||
expect(fillCount).to.be(1);
|
expect(fillCount).to.be(1);
|
||||||
expect(strokeCount).to.be(1);
|
expect(strokeCount).to.be(1);
|
||||||
expect(beginPathCount).to.be(1);
|
expect(beginPathCount).to.be(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('batches fill and stroke instructions for different styles', function() {
|
it('batches fill and stroke instructions for different styles', function() {
|
||||||
renderFeature(replay, feature1, style1, 1);
|
renderFeature(builder, feature1, style1, 1);
|
||||||
renderFeature(replay, feature2, style1, 1);
|
renderFeature(builder, feature2, style1, 1);
|
||||||
renderFeature(replay, feature3, style2, 1);
|
renderFeature(builder, feature3, style2, 1);
|
||||||
replay.replay(context, transform, 0, {});
|
executor.replaceInstructions(builder.finish());
|
||||||
|
executor.replay(context, transform, 0, {});
|
||||||
expect(fillCount).to.be(2);
|
expect(fillCount).to.be(2);
|
||||||
expect(strokeCount).to.be(2);
|
expect(strokeCount).to.be(2);
|
||||||
expect(beginPathCount).to.be(2);
|
expect(beginPathCount).to.be(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('batches fill and stroke instructions for changing styles', function() {
|
it('batches fill and stroke instructions for changing styles', function() {
|
||||||
renderFeature(replay, feature1, style1, 1);
|
renderFeature(builder, feature1, style1, 1);
|
||||||
renderFeature(replay, feature2, style2, 1);
|
renderFeature(builder, feature2, style2, 1);
|
||||||
renderFeature(replay, feature3, style1, 1);
|
renderFeature(builder, feature3, style1, 1);
|
||||||
replay.replay(context, transform, 0, {});
|
executor.replaceInstructions(builder.finish());
|
||||||
|
executor.replay(context, transform, 0, {});
|
||||||
expect(fillCount).to.be(3);
|
expect(fillCount).to.be(3);
|
||||||
expect(strokeCount).to.be(3);
|
expect(strokeCount).to.be(3);
|
||||||
expect(beginPathCount).to.be(3);
|
expect(beginPathCount).to.be(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('batches fill and stroke instructions for skipped feature at the beginning', function() {
|
it('batches fill and stroke instructions for skipped feature at the beginning', function() {
|
||||||
renderFeature(replay, feature1, style1, 1);
|
renderFeature(builder, feature1, style1, 1);
|
||||||
renderFeature(replay, feature2, style2, 1);
|
renderFeature(builder, feature2, style2, 1);
|
||||||
renderFeature(replay, feature3, style2, 1);
|
renderFeature(builder, feature3, style2, 1);
|
||||||
const skippedUids = {};
|
const skippedUids = {};
|
||||||
skippedUids[getUid(feature1)] = true;
|
skippedUids[getUid(feature1)] = true;
|
||||||
replay.replay(context, transform, 0, skippedUids);
|
executor.replaceInstructions(builder.finish());
|
||||||
|
executor.replay(context, transform, 0, skippedUids);
|
||||||
expect(fillCount).to.be(1);
|
expect(fillCount).to.be(1);
|
||||||
expect(strokeCount).to.be(1);
|
expect(strokeCount).to.be(1);
|
||||||
expect(beginPathCount).to.be(1);
|
expect(beginPathCount).to.be(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('batches fill and stroke instructions for skipped feature at the end', function() {
|
it('batches fill and stroke instructions for skipped feature at the end', function() {
|
||||||
renderFeature(replay, feature1, style1, 1);
|
renderFeature(builder, feature1, style1, 1);
|
||||||
renderFeature(replay, feature2, style1, 1);
|
renderFeature(builder, feature2, style1, 1);
|
||||||
renderFeature(replay, feature3, style2, 1);
|
renderFeature(builder, feature3, style2, 1);
|
||||||
const skippedUids = {};
|
const skippedUids = {};
|
||||||
skippedUids[getUid(feature3)] = true;
|
skippedUids[getUid(feature3)] = true;
|
||||||
replay.replay(context, transform, 0, skippedUids);
|
executor.replaceInstructions(builder.finish());
|
||||||
|
executor.replay(context, transform, 0, skippedUids);
|
||||||
expect(fillCount).to.be(1);
|
expect(fillCount).to.be(1);
|
||||||
expect(strokeCount).to.be(1);
|
expect(strokeCount).to.be(1);
|
||||||
expect(beginPathCount).to.be(1);
|
expect(beginPathCount).to.be(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('batches fill and stroke instructions for skipped features', function() {
|
it('batches fill and stroke instructions for skipped features', function() {
|
||||||
renderFeature(replay, feature1, style1, 1);
|
renderFeature(builder, feature1, style1, 1);
|
||||||
renderFeature(replay, feature2, style1, 1);
|
renderFeature(builder, feature2, style1, 1);
|
||||||
renderFeature(replay, feature3, style2, 1);
|
renderFeature(builder, feature3, style2, 1);
|
||||||
const skippedUids = {};
|
const skippedUids = {};
|
||||||
skippedUids[getUid(feature1)] = true;
|
skippedUids[getUid(feature1)] = true;
|
||||||
skippedUids[getUid(feature2)] = true;
|
skippedUids[getUid(feature2)] = true;
|
||||||
replay.replay(context, transform, 0, skippedUids);
|
executor.replaceInstructions(builder.finish());
|
||||||
|
executor.replay(context, transform, 0, skippedUids);
|
||||||
expect(fillCount).to.be(1);
|
expect(fillCount).to.be(1);
|
||||||
expect(strokeCount).to.be(1);
|
expect(strokeCount).to.be(1);
|
||||||
expect(beginPathCount).to.be(1);
|
expect(beginPathCount).to.be(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not batch when overlaps is set to true', function() {
|
it('does not batch when overlaps is set to true', function() {
|
||||||
replay = new CanvasReplayGroup(1, [-180, -90, 180, 90], 1, 1, true);
|
builder = new CanvasInstructionsGroupBuilder(1, [-180, -90, 180, 90], 1, 1, true);
|
||||||
renderFeature(replay, feature1, style1, 1);
|
executor = new CanvasInstructionsGroupExecutor(1, [-180, -90, 180, 90], 1, 1, true);
|
||||||
renderFeature(replay, feature2, style1, 1);
|
renderFeature(builder, feature1, style1, 1);
|
||||||
renderFeature(replay, feature3, style1, 1);
|
renderFeature(builder, feature2, style1, 1);
|
||||||
replay.replay(context, transform, 0, {});
|
renderFeature(builder, feature3, style1, 1);
|
||||||
|
executor.replaceInstructions(builder.finish());
|
||||||
|
executor.replay(context, transform, 0, {});
|
||||||
expect(fillCount).to.be(3);
|
expect(fillCount).to.be(3);
|
||||||
expect(strokeCount).to.be(3);
|
expect(strokeCount).to.be(3);
|
||||||
expect(beginPathCount).to.be(3);
|
expect(beginPathCount).to.be(3);
|
||||||
@@ -184,7 +197,8 @@ describe('ol.render.canvas.ReplayGroup', function() {
|
|||||||
|
|
||||||
it('applies the pixelRatio to the linedash array and offset', function() {
|
it('applies the pixelRatio to the linedash array and offset', function() {
|
||||||
// replay with a pixelRatio of 2
|
// replay with a pixelRatio of 2
|
||||||
replay = new CanvasReplayGroup(1, [-180, -90, 180, 90], 1, 2, true);
|
builder = new CanvasInstructionsGroupBuilder(1, [-180, -90, 180, 90], 1, 2, true);
|
||||||
|
executor = new CanvasInstructionsGroupExecutor(1, [-180, -90, 180, 90], 1, 2, true);
|
||||||
|
|
||||||
let lineDash, lineDashCount = 0,
|
let lineDash, lineDashCount = 0,
|
||||||
lineDashOffset, lineDashOffsetCount = 0;
|
lineDashOffset, lineDashOffsetCount = 0;
|
||||||
@@ -201,9 +215,10 @@ describe('ol.render.canvas.ReplayGroup', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
renderFeature(replay, feature1, style2, 1);
|
renderFeature(builder, feature1, style2, 1);
|
||||||
renderFeature(replay, feature2, style2, 1);
|
renderFeature(builder, feature2, style2, 1);
|
||||||
replay.replay(context, transform, 0, {});
|
executor.replaceInstructions(builder.finish());
|
||||||
|
executor.replay(context, transform, 0, {});
|
||||||
|
|
||||||
expect(lineDashCount).to.be(1);
|
expect(lineDashCount).to.be(1);
|
||||||
expect(style2.getStroke().getLineDash()).to.eql([3, 6]);
|
expect(style2.getStroke().getLineDash()).to.eql([3, 6]);
|
||||||
@@ -241,16 +256,18 @@ describe('ol.render.canvas.ReplayGroup', function() {
|
|||||||
[polygon.getGeometry().getCoordinates(), polygon.getGeometry().getCoordinates()]));
|
[polygon.getGeometry().getCoordinates(), polygon.getGeometry().getCoordinates()]));
|
||||||
const geometrycollection = new Feature(new GeometryCollection(
|
const geometrycollection = new Feature(new GeometryCollection(
|
||||||
[point.getGeometry(), linestring.getGeometry(), polygon.getGeometry()]));
|
[point.getGeometry(), linestring.getGeometry(), polygon.getGeometry()]));
|
||||||
replay = new CanvasReplayGroup(1, [-180, -90, 180, 90], 1, 1, true);
|
builder = new CanvasInstructionsGroupBuilder(1, [-180, -90, 180, 90], 1, 1, true);
|
||||||
renderFeature(replay, point, style, 1);
|
executor = new CanvasInstructionsGroupExecutor(1, [-180, -90, 180, 90], 1, 1, true);
|
||||||
renderFeature(replay, multipoint, style, 1);
|
renderFeature(builder, point, style, 1);
|
||||||
renderFeature(replay, linestring, style, 1);
|
renderFeature(builder, multipoint, style, 1);
|
||||||
renderFeature(replay, multilinestring, style, 1);
|
renderFeature(builder, linestring, style, 1);
|
||||||
renderFeature(replay, polygon, style, 1);
|
renderFeature(builder, multilinestring, style, 1);
|
||||||
renderFeature(replay, multipolygon, style, 1);
|
renderFeature(builder, polygon, style, 1);
|
||||||
renderFeature(replay, geometrycollection, style, 1);
|
renderFeature(builder, multipolygon, style, 1);
|
||||||
|
renderFeature(builder, geometrycollection, style, 1);
|
||||||
scaleTransform(transform, 0.1, 0.1);
|
scaleTransform(transform, 0.1, 0.1);
|
||||||
replay.replay(context, transform, 0, {});
|
executor.replaceInstructions(builder.finish());
|
||||||
|
executor.replay(context, transform, 0, {});
|
||||||
expect(calls.length).to.be(9);
|
expect(calls.length).to.be(9);
|
||||||
expect(calls[0].geometry).to.be(point.getGeometry());
|
expect(calls[0].geometry).to.be(point.getGeometry());
|
||||||
expect(calls[0].feature).to.be(point);
|
expect(calls[0].feature).to.be(point);
|
||||||
@@ -446,7 +463,7 @@ describe('ol.render.canvas.LineStringReplay', function() {
|
|||||||
const tolerance = 1;
|
const tolerance = 1;
|
||||||
const extent = [-180, -90, 180, 90];
|
const extent = [-180, -90, 180, 90];
|
||||||
const resolution = 10;
|
const resolution = 10;
|
||||||
const replay = new CanvasLineStringReplay(tolerance, extent,
|
const replay = new CanvasLineStringBuilder(tolerance, extent,
|
||||||
resolution);
|
resolution);
|
||||||
const stroke = new Stroke({
|
const stroke = new Stroke({
|
||||||
width: 2
|
width: 2
|
||||||
@@ -468,7 +485,7 @@ describe('ol.render.canvas.PolygonReplay', function() {
|
|||||||
const tolerance = 1;
|
const tolerance = 1;
|
||||||
const extent = [-180, -90, 180, 90];
|
const extent = [-180, -90, 180, 90];
|
||||||
const resolution = 10;
|
const resolution = 10;
|
||||||
replay = new CanvasPolygonReplay(tolerance, extent,
|
replay = new CanvasPolygonBuilder(tolerance, extent,
|
||||||
resolution);
|
resolution);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user