Use blocked scoped variables

In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
Tim Schaub
2018-01-11 23:32:36 -07:00
parent 0bf2b04dee
commit ad62739a6e
684 changed files with 18120 additions and 18184 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ import _ol_render_Box_ from '../../../../src/ol/render/Box.js';
describe('ol.render.Box', function() {
var box, map, target;
let box, map, target;
beforeEach(function() {
box = new _ol_render_Box_('test-box');
@@ -33,7 +33,7 @@ describe('ol.render.Box', function() {
describe('constructor', function() {
it('creates an instance', function() {
var obj = new _ol_render_Box_('test-box');
const obj = new _ol_render_Box_('test-box');
expect(obj).to.be.a(_ol_render_Box_);
expect(obj).to.be.a(Disposable);
obj.dispose();
+38 -38
View File
@@ -30,7 +30,7 @@ describe('ol.render.canvas.Immediate', function() {
describe('constructor', function() {
it('creates an instance', function() {
var instance = new CanvasImmediateRenderer();
const instance = new CanvasImmediateRenderer();
expect(instance).to.be.a(CanvasImmediateRenderer);
expect(instance).to.be.a(VectorContext);
});
@@ -38,15 +38,15 @@ describe('ol.render.canvas.Immediate', function() {
describe('#setStyle()', function() {
it('calls the more specific methods with style parts', function() {
var context = new CanvasImmediateRenderer();
const context = new CanvasImmediateRenderer();
sinon.spy(context, 'setFillStrokeStyle');
sinon.spy(context, 'setImageStyle');
sinon.spy(context, 'setTextStyle');
var fill = new Fill({});
var stroke = new Stroke({});
var text = new Text({});
var image = new CircleStyle({});
var style = new Style({
const fill = new Fill({});
const stroke = new Stroke({});
const text = new Text({});
const image = new CircleStyle({});
const style = new Style({
fill: fill,
stroke: stroke,
image: image,
@@ -65,80 +65,80 @@ describe('ol.render.canvas.Immediate', function() {
describe('#drawGeometry()', function() {
var extent = [-10, -10, 10, 10];
const extent = [-10, -10, 10, 10];
it('calls drawPoint() with a Point', function() {
var context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
const context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
sinon.spy(context, 'drawPoint');
var geometry = new Point([1, 2]);
const geometry = new Point([1, 2]);
context.drawGeometry(geometry);
expect(context.drawPoint.calledOnce).to.be(true);
expect(context.drawPoint.firstCall.calledWithExactly(geometry)).to.be(true);
});
it('calls drawLineString() with a LineString', function() {
var context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
const context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
sinon.spy(context, 'drawLineString');
var geometry = new LineString([[1, 2], [3, 4]]);
const geometry = new LineString([[1, 2], [3, 4]]);
context.drawGeometry(geometry);
expect(context.drawLineString.calledOnce).to.be(true);
expect(context.drawLineString.firstCall.calledWithExactly(geometry)).to.be(true);
});
it('calls drawPolygon() with a Polygon', function() {
var context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
const context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
sinon.spy(context, 'drawPolygon');
var geometry = new Polygon([[[1, 2], [3, 4], [5, 6], [1, 2]]]);
const geometry = new Polygon([[[1, 2], [3, 4], [5, 6], [1, 2]]]);
context.drawGeometry(geometry);
expect(context.drawPolygon.calledOnce).to.be(true);
expect(context.drawPolygon.firstCall.calledWithExactly(geometry)).to.be(true);
});
it('calls drawMultiPoint() with a MultiPoint', function() {
var context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
const context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
sinon.spy(context, 'drawMultiPoint');
var geometry = new MultiPoint([[1, 2], [3, 4]]);
const geometry = new MultiPoint([[1, 2], [3, 4]]);
context.drawGeometry(geometry);
expect(context.drawMultiPoint.calledOnce).to.be(true);
expect(context.drawMultiPoint.firstCall.calledWithExactly(geometry)).to.be(true);
});
it('calls drawMultiLineString() with a MultiLineString', function() {
var context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
const context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
sinon.spy(context, 'drawMultiLineString');
var geometry = new MultiLineString([[[1, 2], [3, 4]]]);
const geometry = new MultiLineString([[[1, 2], [3, 4]]]);
context.drawGeometry(geometry);
expect(context.drawMultiLineString.calledOnce).to.be(true);
expect(context.drawMultiLineString.firstCall.calledWithExactly(geometry)).to.be(true);
});
it('calls drawMultiPolygon() with a MultiPolygon', function() {
var context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
const context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
sinon.spy(context, 'drawMultiPolygon');
var geometry = new MultiPolygon([[[[1, 2], [3, 4], [5, 6], [1, 2]]]]);
const geometry = new MultiPolygon([[[[1, 2], [3, 4], [5, 6], [1, 2]]]]);
context.drawGeometry(geometry);
expect(context.drawMultiPolygon.calledOnce).to.be(true);
expect(context.drawMultiPolygon.firstCall.calledWithExactly(geometry)).to.be(true);
});
it('calls drawGeometryCollection() with a GeometryCollection', function() {
var context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
const context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
sinon.spy(context, 'drawGeometryCollection');
sinon.spy(context, 'drawPoint');
sinon.spy(context, 'drawLineString');
sinon.spy(context, 'drawPolygon');
var point = new Point([1, 2]);
var linestring = new LineString([[1, 2], [3, 4]]);
var polygon = new Polygon([[[1, 2], [3, 4], [5, 6], [1, 2]]]);
const point = new Point([1, 2]);
const linestring = new LineString([[1, 2], [3, 4]]);
const polygon = new Polygon([[[1, 2], [3, 4], [5, 6], [1, 2]]]);
var geometry = new GeometryCollection([point, linestring, polygon]);
const geometry = new GeometryCollection([point, linestring, polygon]);
context.drawGeometry(geometry);
expect(context.drawGeometryCollection.calledOnce).to.be(true);
@@ -151,10 +151,10 @@ describe('ol.render.canvas.Immediate', function() {
});
it('calls drawCircle() with a Circle', function() {
var context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
const context = new CanvasImmediateRenderer(getMockContext(), 1, extent);
sinon.spy(context, 'drawCircle');
var geometry = new Circle([0, 0]);
const geometry = new Circle([0, 0]);
context.drawGeometry(geometry);
expect(context.drawCircle.calledOnce).to.be(true);
@@ -167,13 +167,13 @@ describe('ol.render.canvas.Immediate', function() {
it('creates the correct canvas instructions for 3D geometries', function() {
var instructions = [];
const instructions = [];
function serialize(index, instruction) {
if (!instruction) {
return 'id: ' + index + ' NO INSTRUCTION';
}
var parts = [
const parts = [
'id: ' + index,
'type: ' + instruction.type
];
@@ -189,7 +189,7 @@ describe('ol.render.canvas.Immediate', function() {
return parts.join(', ');
}
var context = {
const context = {
beginPath: function() {},
moveTo: function(x, y) {
instructions.push({
@@ -212,18 +212,18 @@ describe('ol.render.canvas.Immediate', function() {
stroke: function() {}
};
var transform = [
const transform = [
0.0004088332670837288, 0,
0, -0.0004088332670837288,
4480.991370439071, 1529.5752568707105
];
var extent = [
const extent = [
-10960437.252092224, 2762924.0275091752,
-7572748.158493212, 3741317.9895594316
];
var canvas = new CanvasImmediateRenderer(context, 1, extent, transform);
const canvas = new CanvasImmediateRenderer(context, 1, extent, transform);
canvas.strokeState_ = {
lineCap: 'round',
@@ -234,7 +234,7 @@ describe('ol.render.canvas.Immediate', function() {
strokeStyle: '#00FFFF'
};
var multiPolygonGeometry = new MultiPolygon([[[
const multiPolygonGeometry = new MultiPolygon([[[
// first polygon
[-80.736061, 28.788576000000006, 0], // moveTo()
[-80.763557, 28.821799999999996, 0], // lineTo()
@@ -257,7 +257,7 @@ describe('ol.render.canvas.Immediate', function() {
canvas.drawMultiPolygon(multiPolygonGeometry, null);
var expected = [
const expected = [
// first polygon
{type: 'moveTo', args: [806.6035275946265, 160.48916296287916]},
{type: 'lineTo', args: [805.3521540835154, 158.76358389011807]},
@@ -278,9 +278,9 @@ describe('ol.render.canvas.Immediate', function() {
];
for (var i = 0, ii = instructions.length; i < ii; ++i) {
var actualInstruction = serialize(i, instructions[i]);
var expectedInstruction = serialize(i, expected[i]);
for (let i = 0, ii = instructions.length; i < ii; ++i) {
const actualInstruction = serialize(i, instructions[i]);
const expectedInstruction = serialize(i, expected[i]);
expect(actualInstruction).to.equal(expectedInstruction);
}
+11 -11
View File
@@ -5,10 +5,10 @@ import _ol_render_canvas_ from '../../../../../src/ol/render/canvas.js';
describe('ol.render.canvas', function() {
var font = document.createElement('link');
const font = document.createElement('link');
font.href = 'https://fonts.googleapis.com/css?family=Abel&text=wmytzilWMYTZIL%40%23%2F%26%3F%24%2510';
font.rel = 'stylesheet';
var head = document.getElementsByTagName('head')[0];
const head = document.getElementsByTagName('head')[0];
describe('ol.render.canvas.checkFont()', function() {
@@ -18,14 +18,14 @@ describe('ol.render.canvas', function() {
_ol_render_canvas_.measureTextHeight('12px sans-serif');
});
var checkFont = _ol_render_canvas_.checkFont;
var retries = 60;
const checkFont = _ol_render_canvas_.checkFont;
const retries = 60;
it('does not clear label cache and measurements for unavailable fonts', function(done) {
this.timeout(3000);
var spy = sinon.spy();
const spy = sinon.spy();
_ol_events_.listen(_ol_render_canvas_.labelCache, 'clear', spy);
var interval = setInterval(function() {
const interval = setInterval(function() {
if (_ol_render_canvas_.checkedFonts_['foo'] == retries && _ol_render_canvas_.checkedFonts_['sans-serif'] == retries) {
clearInterval(interval);
_ol_events_.unlisten(_ol_render_canvas_.labelCache, 'clear', spy);
@@ -39,9 +39,9 @@ describe('ol.render.canvas', function() {
});
it('does not clear label cache and measurements for available fonts', function(done) {
var spy = sinon.spy();
const spy = sinon.spy();
_ol_events_.listen(_ol_render_canvas_.labelCache, 'clear', spy);
var interval = setInterval(function() {
const interval = setInterval(function() {
if (_ol_render_canvas_.checkedFonts_['sans-serif'] == retries) {
clearInterval(interval);
_ol_events_.unlisten(_ol_render_canvas_.labelCache, 'clear', spy);
@@ -55,9 +55,9 @@ describe('ol.render.canvas', function() {
});
it('does not clear label cache and measurements for the \'monospace\' font', function(done) {
var spy = sinon.spy();
const spy = sinon.spy();
_ol_events_.listen(_ol_render_canvas_.labelCache, 'clear', spy);
var interval = setInterval(function() {
const interval = setInterval(function() {
if (_ol_render_canvas_.checkedFonts_['monospace'] == retries) {
clearInterval(interval);
_ol_events_.unlisten(_ol_render_canvas_.labelCache, 'clear', spy);
@@ -85,7 +85,7 @@ describe('ol.render.canvas', function() {
describe('rotateAtOffset', function() {
it('rotates a canvas at an offset point', function() {
var context = {
const context = {
translate: sinon.spy(),
rotate: sinon.spy()
};
+10 -10
View File
@@ -5,19 +5,19 @@ describe('ol.render.canvas.ReplayGroup', function() {
describe('#getCircleArray_', function() {
it('creates an array with a pixelated circle marked with true', function() {
var radius = 10;
var minRadiusSq = Math.pow(radius - Math.SQRT2, 2);
var maxRadiusSq = Math.pow(radius + Math.SQRT2, 2);
var circleArray = _ol_render_canvas_ReplayGroup_.getCircleArray_(radius);
var size = radius * 2 + 1;
const radius = 10;
const minRadiusSq = Math.pow(radius - Math.SQRT2, 2);
const maxRadiusSq = Math.pow(radius + Math.SQRT2, 2);
const circleArray = _ol_render_canvas_ReplayGroup_.getCircleArray_(radius);
const size = radius * 2 + 1;
expect(circleArray.length).to.be(size);
for (var i = 0; i < size; i++) {
for (let i = 0; i < size; i++) {
expect(circleArray[i].length).to.be(size);
for (var j = 0; j < size; j++) {
var dx = Math.abs(radius - i);
var dy = Math.abs(radius - j);
var distanceSq = Math.pow(dx, 2) + Math.pow(dy, 2);
for (let j = 0; j < size; j++) {
const dx = Math.abs(radius - i);
const dy = Math.abs(radius - j);
const distanceSq = Math.pow(dx, 2) + Math.pow(dy, 2);
if (circleArray[i][j] === true) {
expect(distanceSq).to.be.within(0, maxRadiusSq);
} else {
@@ -7,9 +7,9 @@ import Text from '../../../../../src/ol/style/Text.js';
describe('ol.render.canvas.TextReplay', function() {
it('renders polygon labels only when they fit', function() {
var replay = new _ol_render_canvas_TextReplay_(1, [-180, -90, 180, 90], 0.02, 1, true);
var geometry = new Polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]);
var feature = new Feature(geometry);
const replay = new _ol_render_canvas_TextReplay_(1, [-180, -90, 180, 90], 0.02, 1, true);
const geometry = new Polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]);
const feature = new Feature(geometry);
replay.setTextStyle(new Text({
text: 'This is a long text'
@@ -25,12 +25,12 @@ describe('ol.render.canvas.TextReplay', function() {
});
it('renders multipolygon labels only when they fit', function() {
var replay = new _ol_render_canvas_TextReplay_(1, [-180, -90, 180, 90], 0.02, 1, true);
var geometry = new MultiPolygon([
const replay = new _ol_render_canvas_TextReplay_(1, [-180, -90, 180, 90], 0.02, 1, true);
const geometry = new MultiPolygon([
[[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]],
[[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]
]);
var feature = new Feature(geometry);
const feature = new Feature(geometry);
replay.setTextStyle(new Text({
text: 'This is a long text'
+17 -17
View File
@@ -7,11 +7,11 @@ import RenderFeature from '../../../../src/ol/render/Feature.js';
describe('ol.render.Feature', function() {
var renderFeature;
var type = 'Point';
var flatCoordinates = [0, 0];
var ends = null;
var properties = {foo: 'bar'};
let renderFeature;
const type = 'Point';
const flatCoordinates = [0, 0];
const ends = null;
const properties = {foo: 'bar'};
describe('Constructor', function() {
it('creates an instance', function() {
@@ -41,7 +41,7 @@ describe('ol.render.Feature', function() {
expect(renderFeature.getExtent()).to.equal(renderFeature.extent_);
});
it('returns the correct extent for a linestring', function() {
var feature =
const feature =
new RenderFeature('LineString', [-1, -2, 2, 1], null, {});
expect(feature.getExtent()).to.eql([-1, -2, 2, 1]);
});
@@ -55,9 +55,9 @@ describe('ol.render.Feature', function() {
describe('#getFlatInteriorPoint()', function() {
it('returns correct point and caches it', function() {
var polygon = new Polygon([[[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]]);
var feature = new RenderFeature('Polygon', polygon.getOrientedFlatCoordinates(),
polygon.getEnds());
const polygon = new Polygon([[[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]]);
const feature = new RenderFeature('Polygon', polygon.getOrientedFlatCoordinates(),
polygon.getEnds());
expect(feature.getFlatInteriorPoint()).to.eql([5, 5, 10]);
expect(feature.getFlatInteriorPoint()).to.be(feature.flatInteriorPoints_);
});
@@ -65,12 +65,12 @@ describe('ol.render.Feature', function() {
describe('#getFlatInteriorPoints()', function() {
it('returns correct points and caches them', function() {
var polygon = new MultiPolygon([
const polygon = new MultiPolygon([
[[[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]],
[[[10, 0], [10, 10], [20, 10], [20, 0], [10, 0]]]
]);
var feature = new RenderFeature('MultiPolygon', polygon.getOrientedFlatCoordinates(),
polygon.getEndss());
const feature = new RenderFeature('MultiPolygon', polygon.getOrientedFlatCoordinates(),
polygon.getEndss());
expect(feature.getFlatInteriorPoints()).to.eql([5, 5, 10, 15, 5, 10]);
expect(feature.getFlatInteriorPoints()).to.be(feature.flatInteriorPoints_);
});
@@ -78,8 +78,8 @@ describe('ol.render.Feature', function() {
describe('#getFlatMidpoint()', function() {
it('returns correct point', function() {
var line = new LineString([[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]);
var feature = new RenderFeature('LineString', line.getFlatCoordinates());
const line = new LineString([[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]);
const feature = new RenderFeature('LineString', line.getFlatCoordinates());
expect(feature.getFlatMidpoint()).to.eql([10, 10]);
expect(feature.getFlatMidpoint()).to.eql(feature.flatMidpoints_);
});
@@ -87,12 +87,12 @@ describe('ol.render.Feature', function() {
describe('#getFlatMidpoints()', function() {
it('returns correct points and caches them', function() {
var line = new MultiLineString([
const line = new MultiLineString([
[[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]],
[[10, 0], [10, 10], [20, 10], [20, 0], [10, 0]]
]);
var feature = new RenderFeature('MultiLineString', line.getFlatCoordinates(),
line.getEnds());
const feature = new RenderFeature('MultiLineString', line.getFlatCoordinates(),
line.getEnds());
expect(feature.getFlatMidpoints()).to.eql([10, 10, 20, 10]);
expect(feature.getFlatMidpoints()).to.be(feature.flatMidpoints_);
});
+22 -22
View File
@@ -8,19 +8,19 @@ import Fill from '../../../../../src/ol/style/Fill.js';
import Stroke from '../../../../../src/ol/style/Stroke.js';
describe('ol.render.webgl.CircleReplay', function() {
var replay;
let replay;
var strokeStyle = new Stroke({
const strokeStyle = new Stroke({
color: [0, 255, 0, 0.4]
});
var fillStyle = new Fill({
const fillStyle = new Fill({
color: [255, 0, 0, 1]
});
beforeEach(function() {
var tolerance = 0.1;
var maxExtent = [-10000, -20000, 10000, 20000];
const tolerance = 0.1;
const maxExtent = [-10000, -20000, 10000, 20000];
replay = new _ol_render_webgl_CircleReplay_(tolerance, maxExtent);
});
@@ -48,7 +48,7 @@ describe('ol.render.webgl.CircleReplay', function() {
describe('#drawCircle', function() {
it('sets the buffer data', function() {
var circle = new Circle([0, 0], 5000);
const circle = new Circle([0, 0], 5000);
replay.setFillStrokeStyle(fillStyle, strokeStyle);
replay.drawCircle(circle, null);
@@ -61,7 +61,7 @@ describe('ol.render.webgl.CircleReplay', function() {
});
it('does not draw if radius is zero', function() {
var circle = new Circle([0, 0], 0);
const circle = new Circle([0, 0], 0);
replay.drawCircle(circle, null);
expect(replay.vertices).to.have.length(0);
@@ -71,7 +71,7 @@ describe('ol.render.webgl.CircleReplay', function() {
});
it('resets state and removes style if it belongs to a zero radius circle', function() {
var circle = new Circle([0, 0], 0);
const circle = new Circle([0, 0], 0);
replay.setFillStrokeStyle(fillStyle, strokeStyle);
replay.setFillStrokeStyle(null, strokeStyle);
@@ -97,7 +97,7 @@ describe('ol.render.webgl.CircleReplay', function() {
});
describe('#setUpProgram', function() {
var context, gl;
let context, gl;
beforeEach(function() {
context = {
getProgram: function() {},
@@ -114,9 +114,9 @@ describe('ol.render.webgl.CircleReplay', function() {
});
it('returns the locations used by the shaders', function() {
var locations = replay.setUpProgram(gl, context, [2, 2], 1);
const locations = replay.setUpProgram(gl, context, [2, 2], 1);
expect(locations).to.be.a(
_ol_render_webgl_circlereplay_defaultshader_Locations_);
_ol_render_webgl_circlereplay_defaultshader_Locations_);
});
it('gets and compiles the shaders', function() {
@@ -125,8 +125,8 @@ describe('ol.render.webgl.CircleReplay', function() {
replay.setUpProgram(gl, context, [2, 2], 1);
expect(context.getProgram.calledWithExactly(
_ol_render_webgl_circlereplay_defaultshader_.fragment,
_ol_render_webgl_circlereplay_defaultshader_.vertex)).to.be(true);
_ol_render_webgl_circlereplay_defaultshader_.fragment,
_ol_render_webgl_circlereplay_defaultshader_.vertex)).to.be(true);
expect(context.useProgram.calledOnce).to.be(true);
});
@@ -138,12 +138,12 @@ describe('ol.render.webgl.CircleReplay', function() {
replay.setUpProgram(gl, context, [2, 2], 1);
expect(gl.vertexAttribPointer.callCount).to.be(gl.getAttribLocation.callCount);
expect(gl.enableVertexAttribArray.callCount).to.be(
gl.getAttribLocation.callCount);
gl.getAttribLocation.callCount);
});
});
describe('#shutDownProgram', function() {
var context, gl;
let context, gl;
beforeEach(function() {
context = {
getProgram: function() {},
@@ -164,22 +164,22 @@ describe('ol.render.webgl.CircleReplay', function() {
sinon.spy(gl, 'getAttribLocation');
sinon.spy(gl, 'disableVertexAttribArray');
var locations = replay.setUpProgram(gl, context, [2, 2], 1);
const locations = replay.setUpProgram(gl, context, [2, 2], 1);
replay.shutDownProgram(gl, locations);
expect(gl.disableVertexAttribArray.callCount).to.be(
gl.getAttribLocation.callCount);
gl.getAttribLocation.callCount);
});
});
describe('#drawReplay', function() {
var gl, context;
var feature1 = new Feature({
let gl, context;
const feature1 = new Feature({
geometry: new Circle([0, 0], 5000)
});
var feature2 = new Feature({
const feature2 = new Feature({
geometry: new Circle([10, 10], 5000)
});
var feature3 = new Feature({
const feature3 = new Feature({
geometry: new Circle([20, 20], 5000)
});
beforeEach(function() {
@@ -231,7 +231,7 @@ describe('ol.render.webgl.CircleReplay', function() {
replay.setFillStrokeStyle(fillStyle, strokeStyle);
replay.drawCircle(feature3.getGeometry(), feature3);
replay.startIndices.push(replay.indices.length);
var skippedFeatHash = {};
const skippedFeatHash = {};
skippedFeatHash[getUid(feature2).toString()] = true;
replay.drawReplay(gl, context, skippedFeatHash, false);
+15 -15
View File
@@ -4,10 +4,10 @@ import _ol_render_webgl_ImageReplay_ from '../../../../../src/ol/render/webgl/Im
import ImageStyle from '../../../../../src/ol/style/Image.js';
describe('ol.render.webgl.ImageReplay', function() {
var replay;
let replay;
var createImageStyle = function(image) {
var imageStyle = new ImageStyle({
const createImageStyle = function(image) {
const imageStyle = new ImageStyle({
opacity: 0.1,
rotateWithView: true,
rotation: 1.5,
@@ -38,14 +38,14 @@ describe('ol.render.webgl.ImageReplay', function() {
};
beforeEach(function() {
var tolerance = 0.1;
var maxExtent = [-10000, -20000, 10000, 20000];
const tolerance = 0.1;
const maxExtent = [-10000, -20000, 10000, 20000];
replay = new _ol_render_webgl_ImageReplay_(tolerance, maxExtent);
});
describe('#setImageStyle', function() {
var imageStyle1, imageStyle2;
let imageStyle1, imageStyle2;
beforeEach(function() {
imageStyle1 = createImageStyle(new Image());
@@ -87,12 +87,12 @@ describe('ol.render.webgl.ImageReplay', function() {
describe('#drawPoint', function() {
beforeEach(function() {
var imageStyle = createImageStyle(new Image());
const imageStyle = createImageStyle(new Image());
replay.setImageStyle(imageStyle);
});
it('sets the buffer data', function() {
var point;
let point;
point = new Point([1000, 2000]);
replay.drawPoint(point, null);
@@ -120,15 +120,15 @@ describe('ol.render.webgl.ImageReplay', function() {
describe('#drawMultiPoint', function() {
beforeEach(function() {
var imageStyle = createImageStyle(new Image());
const imageStyle = createImageStyle(new Image());
replay.setImageStyle(imageStyle);
});
it('sets the buffer data', function() {
var multiPoint;
let multiPoint;
multiPoint = new MultiPoint(
[[1000, 2000], [2000, 3000]]);
[[1000, 2000], [2000, 3000]]);
replay.drawMultiPoint(multiPoint, null);
expect(replay.vertices).to.have.length(64);
expect(replay.indices).to.have.length(12);
@@ -146,7 +146,7 @@ describe('ol.render.webgl.ImageReplay', function() {
expect(replay.indices[11]).to.be(7);
multiPoint = new MultiPoint(
[[3000, 4000], [4000, 5000]]);
[[3000, 4000], [4000, 5000]]);
replay.drawMultiPoint(multiPoint, null);
expect(replay.vertices).to.have.length(128);
expect(replay.indices).to.have.length(24);
@@ -172,7 +172,7 @@ describe('ol.render.webgl.ImageReplay', function() {
});
it('returns the textures', function() {
var textures = replay.getTextures();
const textures = replay.getTextures();
expect(textures).to.have.length(2);
expect(textures[0]).to.be(1);
@@ -180,7 +180,7 @@ describe('ol.render.webgl.ImageReplay', function() {
});
it('can additionally return the hit detection textures', function() {
var textures = replay.getTextures(true);
const textures = replay.getTextures(true);
expect(textures).to.have.length(4);
expect(textures[0]).to.be(1);
@@ -197,7 +197,7 @@ describe('ol.render.webgl.ImageReplay', function() {
});
it('returns the hit detection textures', function() {
var textures = replay.getHitDetectionTextures();
const textures = replay.getHitDetectionTextures();
expect(textures).to.have.length(2);
expect(textures[0]).to.be(3);
+12 -12
View File
@@ -18,7 +18,7 @@ import Stroke from '../../../../../src/ol/style/Stroke.js';
import Style from '../../../../../src/ol/style/Style.js';
describe('ol.render.webgl.Immediate', function() {
var context, style, circle, line, multiLine, point, multiPoint, polygon, multiPolygon;
let context, style, circle, line, multiLine, point, multiPoint, polygon, multiPolygon;
beforeEach(function() {
context = new _ol_render_webgl_Immediate_({}, [0, 0], 0, 0, [0, 0], [-180, -90, 180, 90], 1);
style = new Style({
@@ -45,7 +45,7 @@ describe('ol.render.webgl.Immediate', function() {
});
describe('#drawFeature', function() {
var feat;
let feat;
beforeEach(function() {
feat = new Feature({
geometry: circle
@@ -84,7 +84,7 @@ describe('ol.render.webgl.Immediate', function() {
});
describe('#drawGeometryCollection', function() {
var geomColl;
let geomColl;
beforeEach(function() {
geomColl = new GeometryCollection([circle, point, multiPoint,
line, multiLine, polygon, multiPolygon]);
@@ -101,7 +101,7 @@ describe('ol.render.webgl.Immediate', function() {
describe('geometry functions', function() {
function mock(ctor, geomFunc) {
var tmpObj = {};
const tmpObj = {};
tmpObj.replay = ctor.prototype.replay;
ctor.prototype.replay = sinon.spy();
tmpObj.finish = ctor.prototype.finish;
@@ -124,13 +124,13 @@ describe('ol.render.webgl.Immediate', function() {
}
function restore(ctor, tmpObj) {
for (var i in tmpObj) {
for (const i in tmpObj) {
ctor.prototype[i] = tmpObj[i];
}
}
describe('#drawPoint', function() {
var tmpObj;
let tmpObj;
beforeEach(function() {
tmpObj = mock(_ol_render_webgl_ImageReplay_, 'drawPoint');
});
@@ -150,7 +150,7 @@ describe('ol.render.webgl.Immediate', function() {
});
describe('#drawMultiPoint', function() {
var tmpObj;
let tmpObj;
beforeEach(function() {
tmpObj = mock(_ol_render_webgl_ImageReplay_, 'drawMultiPoint');
});
@@ -170,7 +170,7 @@ describe('ol.render.webgl.Immediate', function() {
});
describe('#drawLineString', function() {
var tmpObj;
let tmpObj;
beforeEach(function() {
tmpObj = mock(_ol_render_webgl_LineStringReplay_, 'drawLineString');
});
@@ -190,7 +190,7 @@ describe('ol.render.webgl.Immediate', function() {
});
describe('#drawMultiLineString', function() {
var tmpObj;
let tmpObj;
beforeEach(function() {
tmpObj = mock(_ol_render_webgl_LineStringReplay_, 'drawMultiLineString');
});
@@ -210,7 +210,7 @@ describe('ol.render.webgl.Immediate', function() {
});
describe('#drawPolygon', function() {
var tmpObj;
let tmpObj;
beforeEach(function() {
tmpObj = mock(_ol_render_webgl_PolygonReplay_, 'drawPolygon');
});
@@ -230,7 +230,7 @@ describe('ol.render.webgl.Immediate', function() {
});
describe('#drawMultiPolygon', function() {
var tmpObj;
let tmpObj;
beforeEach(function() {
tmpObj = mock(_ol_render_webgl_PolygonReplay_, 'drawMultiPolygon');
});
@@ -250,7 +250,7 @@ describe('ol.render.webgl.Immediate', function() {
});
describe('#drawCircle', function() {
var tmpObj;
let tmpObj;
beforeEach(function() {
tmpObj = mock(_ol_render_webgl_CircleReplay_, 'drawCircle');
});
+7 -7
View File
@@ -1,7 +1,7 @@
import _ol_render_webgl_Replay_ from '../../../../../src/ol/render/webgl/Replay.js';
describe('ol.render.Replay', function() {
var replay;
let replay;
beforeEach(function() {
replay = new _ol_render_webgl_Replay_(5, [-180, -90, 180, 90]);
});
@@ -15,8 +15,8 @@ describe('ol.render.Replay', function() {
});
it ('sets up the required matrices', function() {
var mat3 = [1, 0, 0, 1, 0, 0];
var mat4 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
const mat3 = [1, 0, 0, 1, 0, 0];
const mat4 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
expect(replay.projectionMatrix_).to.eql(mat3);
expect(replay.offsetRotateMatrix_).to.eql(mat3);
expect(replay.offsetScaleMatrix_).to.eql(mat3);
@@ -25,11 +25,11 @@ describe('ol.render.Replay', function() {
});
describe('#replay', function() {
var gl = {
const gl = {
uniformMatrix4fv: function() {},
uniform1f: function() {}
};
var context = {
const context = {
bindBuffer: function() {},
getGL: function() {
return gl;
@@ -47,9 +47,9 @@ describe('ol.render.Replay', function() {
});
it('calculates the correct matrices', function() {
var sin = Math.sin(Math.PI);
const sin = Math.sin(Math.PI);
replay.replay(context, [0, 0], 10, Math.PI, [10, 10], 1, 0, {}, undefined,
false, undefined);
false, undefined);
expect(replay.projectionMatrix_).to.eql([-0.02, -sin * 0.02, sin * 0.02,
-0.02, 0, 0]);
@@ -8,21 +8,21 @@ import _ol_render_webgl_linestringreplay_defaultshader_Locations_ from '../../..
import Stroke from '../../../../../src/ol/style/Stroke.js';
describe('ol.render.webgl.LineStringReplay', function() {
var replay;
let replay;
var strokeStyle1 = new Stroke({
const strokeStyle1 = new Stroke({
color: [0, 255, 0, 0.4]
});
var strokeStyle2 = new Stroke({
const strokeStyle2 = new Stroke({
color: [255, 0, 0, 1],
lineCap: 'square',
lineJoin: 'miter'
});
beforeEach(function() {
var tolerance = 0.1;
var maxExtent = [-10000, -20000, 10000, 20000];
const tolerance = 0.1;
const maxExtent = [-10000, -20000, 10000, 20000];
replay = new _ol_render_webgl_LineStringReplay_(tolerance, maxExtent);
});
@@ -54,10 +54,10 @@ describe('ol.render.webgl.LineStringReplay', function() {
describe('#drawLineString', function() {
it('sets the buffer data', function() {
var linestring;
let linestring;
linestring = new LineString(
[[1000, 2000], [2000, 3000]]);
[[1000, 2000], [2000, 3000]]);
replay.setFillStrokeStyle(null, strokeStyle1);
replay.drawLineString(linestring, null);
expect(replay.vertices).to.have.length(56);
@@ -67,7 +67,7 @@ describe('ol.render.webgl.LineStringReplay', function() {
expect(replay.startIndicesFeature).to.have.length(1);
linestring = new LineString(
[[1000, 3000], [2000, 4000], [3000, 3000]]);
[[1000, 3000], [2000, 4000], [3000, 3000]]);
replay.drawLineString(linestring, null);
expect(replay.vertices).to.have.length(140);
expect(replay.indices).to.have.length(48);
@@ -80,11 +80,9 @@ describe('ol.render.webgl.LineStringReplay', function() {
describe('#drawMultiLineString', function() {
it('sets the buffer data', function() {
var multilinestring;
multilinestring = new MultiLineString(
[[[1000, 2000], [2000, 3000]],
[[1000, 3000], [2000, 4000], [3000, 3000]]]);
const multilinestring = new MultiLineString(
[[[1000, 2000], [2000, 3000]],
[[1000, 3000], [2000, 4000], [3000, 3000]]]);
replay.setFillStrokeStyle(null, strokeStyle1);
replay.drawMultiLineString(multilinestring, null);
expect(replay.vertices).to.have.length(140);
@@ -98,119 +96,109 @@ describe('ol.render.webgl.LineStringReplay', function() {
describe('#drawCoordinates_', function() {
it('triangulates linestrings', function() {
var linestring;
var stroke = new Stroke({
const stroke = new Stroke({
color: [0, 255, 0, 1],
lineCap: 'butt',
lineJoin: 'bevel'
});
linestring = new LineString(
[[1000, 3000], [2000, 4000], [3000, 3000]]);
var flatCoordinates = linestring.getFlatCoordinates();
const linestring = new LineString(
[[1000, 3000], [2000, 4000], [3000, 3000]]);
const flatCoordinates = linestring.getFlatCoordinates();
replay.setFillStrokeStyle(null, stroke);
replay.drawCoordinates_(flatCoordinates, 0,
flatCoordinates.length, 2);
flatCoordinates.length, 2);
expect(replay.indices).to.eql(
[2, 0, 1, 4, 2, 1,
2, 4, 3,
5, 3, 4, 4, 6, 5]);
[2, 0, 1, 4, 2, 1,
2, 4, 3,
5, 3, 4, 4, 6, 5]);
});
it('optionally creates miters', function() {
var linestring;
var stroke = new Stroke({
const stroke = new Stroke({
color: [0, 255, 0, 1],
lineCap: 'butt'
});
linestring = new LineString(
[[1000, 3000], [2000, 4000], [3000, 3000]]);
var flatCoordinates = linestring.getFlatCoordinates();
const linestring = new LineString(
[[1000, 3000], [2000, 4000], [3000, 3000]]);
const flatCoordinates = linestring.getFlatCoordinates();
replay.setFillStrokeStyle(null, stroke);
replay.drawCoordinates_(flatCoordinates, 0,
flatCoordinates.length, 2);
flatCoordinates.length, 2);
expect(replay.indices).to.eql(
[2, 0, 1, 4, 2, 1,
2, 4, 3, 3, 5, 2,
6, 3, 4, 4, 7, 6]);
[2, 0, 1, 4, 2, 1,
2, 4, 3, 3, 5, 2,
6, 3, 4, 4, 7, 6]);
});
it('optionally creates caps', function() {
var linestring;
var stroke = new Stroke({
const stroke = new Stroke({
color: [0, 255, 0, 1]
});
linestring = new LineString(
[[1000, 3000], [2000, 4000], [3000, 3000]]);
var flatCoordinates = linestring.getFlatCoordinates();
const linestring = new LineString(
[[1000, 3000], [2000, 4000], [3000, 3000]]);
const flatCoordinates = linestring.getFlatCoordinates();
replay.setFillStrokeStyle(null, stroke);
replay.drawCoordinates_(flatCoordinates, 0,
flatCoordinates.length, 2);
flatCoordinates.length, 2);
expect(replay.indices).to.eql(
[2, 0, 1, 1, 3, 2,
4, 2, 3, 6, 4, 3,
4, 6, 5, 5, 7, 4,
8, 5, 6, 6, 9, 8,
10, 8, 9, 9, 11, 10]);
[2, 0, 1, 1, 3, 2,
4, 2, 3, 6, 4, 3,
4, 6, 5, 5, 7, 4,
8, 5, 6, 6, 9, 8,
10, 8, 9, 9, 11, 10]);
});
it('respects segment orientation', function() {
var linestring;
var stroke = new Stroke({
const stroke = new Stroke({
color: [0, 255, 0, 1],
lineCap: 'butt',
lineJoin: 'bevel'
});
linestring = new LineString(
[[1000, 3000], [2000, 2000], [3000, 3000]]);
var flatCoordinates = linestring.getFlatCoordinates();
const linestring = new LineString(
[[1000, 3000], [2000, 2000], [3000, 3000]]);
const flatCoordinates = linestring.getFlatCoordinates();
replay.setFillStrokeStyle(null, stroke);
replay.drawCoordinates_(flatCoordinates, 0,
flatCoordinates.length, 2);
flatCoordinates.length, 2);
expect(replay.indices).to.eql(
[2, 0, 1, 4, 2, 0,
2, 4, 3,
5, 3, 4, 4, 6, 5]);
[2, 0, 1, 4, 2, 0,
2, 4, 3,
5, 3, 4, 4, 6, 5]);
});
it('closes boundaries', function() {
var linestring;
var stroke = new Stroke({
const stroke = new Stroke({
color: [0, 255, 0, 1],
lineCap: 'butt',
lineJoin: 'bevel'
});
linestring = new LineString(
[[1000, 3000], [2000, 4000], [3000, 3000], [1000, 3000]]);
var flatCoordinates = linestring.getFlatCoordinates();
const linestring = new LineString(
[[1000, 3000], [2000, 4000], [3000, 3000], [1000, 3000]]);
const flatCoordinates = linestring.getFlatCoordinates();
replay.setFillStrokeStyle(null, stroke);
replay.drawCoordinates_(flatCoordinates, 0,
flatCoordinates.length, 2);
flatCoordinates.length, 2);
expect(replay.indices).to.eql(
[0, 2, 1, 3, 1, 2,
5, 3, 2,
3, 5, 4, 6, 4, 5,
8, 6, 5,
6, 8, 7, 9, 7, 8,
10, 9, 8]);
[0, 2, 1, 3, 1, 2,
5, 3, 2,
3, 5, 4, 6, 4, 5,
8, 6, 5,
6, 8, 7, 9, 7, 8,
10, 9, 8]);
expect(replay.vertices.slice(0, 7)).to.eql(
replay.vertices.slice(-14, -7));
replay.vertices.slice(-14, -7));
expect(replay.vertices.slice(14, 21)).to.eql(
replay.vertices.slice(-7));
replay.vertices.slice(-7));
});
});
describe('#setUpProgram', function() {
var context, gl;
let context, gl;
beforeEach(function() {
context = {
getProgram: function() {},
@@ -227,9 +215,9 @@ describe('ol.render.webgl.LineStringReplay', function() {
});
it('returns the locations used by the shaders', function() {
var locations = replay.setUpProgram(gl, context, [2, 2], 1);
const locations = replay.setUpProgram(gl, context, [2, 2], 1);
expect(locations).to.be.a(
_ol_render_webgl_linestringreplay_defaultshader_Locations_);
_ol_render_webgl_linestringreplay_defaultshader_Locations_);
});
it('gets and compiles the shaders', function() {
@@ -238,8 +226,8 @@ describe('ol.render.webgl.LineStringReplay', function() {
replay.setUpProgram(gl, context, [2, 2], 1);
expect(context.getProgram.calledWithExactly(
_ol_render_webgl_linestringreplay_defaultshader_.fragment,
_ol_render_webgl_linestringreplay_defaultshader_.vertex)).to.be(true);
_ol_render_webgl_linestringreplay_defaultshader_.fragment,
_ol_render_webgl_linestringreplay_defaultshader_.vertex)).to.be(true);
expect(context.useProgram.calledOnce).to.be(true);
});
@@ -251,12 +239,12 @@ describe('ol.render.webgl.LineStringReplay', function() {
replay.setUpProgram(gl, context, [2, 2], 1);
expect(gl.vertexAttribPointer.callCount).to.be(gl.getAttribLocation.callCount);
expect(gl.enableVertexAttribArray.callCount).to.be(
gl.getAttribLocation.callCount);
gl.getAttribLocation.callCount);
});
});
describe('#shutDownProgram', function() {
var context, gl;
let context, gl;
beforeEach(function() {
context = {
getProgram: function() {},
@@ -277,22 +265,22 @@ describe('ol.render.webgl.LineStringReplay', function() {
sinon.spy(gl, 'getAttribLocation');
sinon.spy(gl, 'disableVertexAttribArray');
var locations = replay.setUpProgram(gl, context, [2, 2], 1);
const locations = replay.setUpProgram(gl, context, [2, 2], 1);
replay.shutDownProgram(gl, locations);
expect(gl.disableVertexAttribArray.callCount).to.be(
gl.getAttribLocation.callCount);
gl.getAttribLocation.callCount);
});
});
describe('#drawReplay', function() {
var gl, context;
var feature1 = new Feature({
let gl, context;
const feature1 = new Feature({
geometry: new LineString([[0, 0], [500, 500]])
});
var feature2 = new Feature({
const feature2 = new Feature({
geometry: new LineString([[0, 0], [500, 500]])
});
var feature3 = new Feature({
const feature3 = new Feature({
geometry: new LineString([[0, 0], [500, 500]])
});
beforeEach(function() {
@@ -350,7 +338,7 @@ describe('ol.render.webgl.LineStringReplay', function() {
replay.setFillStrokeStyle(null, strokeStyle1);
replay.drawLineString(feature3.getGeometry(), feature3);
replay.startIndices.push(replay.indices.length);
var skippedFeatHash = {};
const skippedFeatHash = {};
skippedFeatHash[getUid(feature2).toString()] = true;
replay.drawReplay(gl, context, skippedFeatHash, false);
+61 -61
View File
@@ -11,18 +11,18 @@ import Fill from '../../../../../src/ol/style/Fill.js';
import Stroke from '../../../../../src/ol/style/Stroke.js';
describe('ol.render.webgl.PolygonReplay', function() {
var replay;
let replay;
var fillStyle = new Fill({
const fillStyle = new Fill({
color: [0, 0, 255, 0.5]
});
var strokeStyle = new Stroke({
const strokeStyle = new Stroke({
color: [0, 255, 0, 0.4]
});
beforeEach(function() {
var tolerance = 0.1;
var maxExtent = [-10000, -20000, 10000, 20000];
const tolerance = 0.1;
const maxExtent = [-10000, -20000, 10000, 20000];
replay = new _ol_render_webgl_PolygonReplay_(tolerance, maxExtent);
});
@@ -32,8 +32,8 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
it('sets the buffer data', function() {
var polygon1 = new Polygon(
[[[1000, 2000], [1200, 2000], [1200, 3000]]]
const polygon1 = new Polygon(
[[[1000, 2000], [1200, 2000], [1200, 3000]]]
);
replay.drawPolygon(polygon1, null);
expect(replay.vertices).to.have.length(8);
@@ -43,8 +43,8 @@ describe('ol.render.webgl.PolygonReplay', function() {
1000, 2000, 1200, 3000, 1200, 2000, 1000, 2000]);
expect(replay.indices).to.eql([2, 0, 1]);
var polygon2 = new Polygon(
[[[4000, 2000], [4200, 2000], [4200, 3000]]]
const polygon2 = new Polygon(
[[[4000, 2000], [4200, 2000], [4200, 3000]]]
);
replay.drawPolygon(polygon2, null);
expect(replay.vertices).to.have.length(16);
@@ -64,7 +64,7 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
it('sets the buffer data', function() {
var multiPolygon = new MultiPolygon([
const multiPolygon = new MultiPolygon([
[[[1000, 2000], [1200, 2000], [1200, 3000]]],
[[[4000, 2000], [4200, 2000], [4200, 3000]]]
]);
@@ -81,7 +81,7 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
describe('triangulating functions', function() {
var list, rtree;
let list, rtree;
beforeEach(function() {
list = new LinkedList();
rtree = new RBush();
@@ -89,7 +89,7 @@ describe('ol.render.webgl.PolygonReplay', function() {
describe('#createPoint_', function() {
it('creates a WebGL polygon vertex', function() {
var p = replay.createPoint_(1, 1, 1);
const p = replay.createPoint_(1, 1, 1);
expect(p.x).to.be(1);
expect(p.y).to.be(1);
expect(p.i).to.be(1);
@@ -105,20 +105,20 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
describe('#insertItem_', function() {
var p0, p1;
let p0, p1;
beforeEach(function() {
p0 = replay.createPoint_(1, 1, 1);
p1 = replay.createPoint_(2, 2, 2);
});
it('creates a WebGL polygon segment', function() {
var seg = replay.insertItem_(p0, p1, list, rtree);
const seg = replay.insertItem_(p0, p1, list, rtree);
expect(seg.p0).to.be(p0);
expect(seg.p1).to.be(p1);
});
it('inserts the segment into the provided linked list', function() {
var seg = replay.insertItem_(p0, p1, list, rtree);
const seg = replay.insertItem_(p0, p1, list, rtree);
expect(list.head_.data).to.be(seg);
});
@@ -131,13 +131,13 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
describe('#removeItem_', function() {
var s0, s1;
let s0, s1;
beforeEach(function() {
var p = replay.createPoint_(2, 2, 2);
const p = replay.createPoint_(2, 2, 2);
s0 = replay.insertItem_(replay.createPoint_(1, 1, 1),
p, list, rtree);
p, list, rtree);
s1 = replay.insertItem_(p,
replay.createPoint_(5, 2, 3), list, rtree);
replay.createPoint_(5, 2, 3), list, rtree);
});
it('removes the current item', function() {
@@ -147,7 +147,7 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
it('updates the preceding segment', function() {
var dataExtent = rtree.getExtent();
const dataExtent = rtree.getExtent();
replay.removeItem_(s0, s1, list, rtree);
expect(s0.p1).to.be(s1.p1);
expect(rtree.getExtent()).to.eql(dataExtent);
@@ -155,7 +155,7 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
describe('#getPointsInTriangle_', function() {
var p0, p1, p2, p3;
let p0, p1, p2, p3;
beforeEach(function() {
p0 = replay.createPoint_(2, 0, 0);
p1 = replay.createPoint_(0, 5, 1);
@@ -169,20 +169,20 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
it('gets every point in a triangle', function() {
var points = replay.getPointsInTriangle_({x: -3, y: 6}, {x: 7, y: 6},
{x: 2, y: 2}, rtree);
const points = replay.getPointsInTriangle_({x: -3, y: 6}, {x: 7, y: 6},
{x: 2, y: 2}, rtree);
expect(points).to.eql([p1, p2, p3]);
});
it('gets only reflex points in a triangle', function() {
var points = replay.getPointsInTriangle_({x: -3, y: 6}, {x: 7, y: 6},
{x: 2, y: 2}, rtree, true);
const points = replay.getPointsInTriangle_({x: -3, y: 6}, {x: 7, y: 6},
{x: 2, y: 2}, rtree, true);
expect(points).to.eql([p2]);
});
});
describe('#getIntersections_', function() {
var p0, p1, p2, p3, s0, s1, s2, s3;
let p0, p1, p2, p3, s0, s1, s2, s3;
beforeEach(function() {
p0 = replay.createPoint_(2, 0, 0);
p1 = replay.createPoint_(0, 5, 1);
@@ -195,39 +195,39 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
it('gets intersecting, but non touching segments', function() {
var segments = replay.getIntersections_({p0: {x: 0, y: 3}, p1: {x: 4, y: 5}},
rtree);
const segments = replay.getIntersections_({p0: {x: 0, y: 3}, p1: {x: 4, y: 5}},
rtree);
expect(segments).to.eql([s0, s1]);
});
it('gets intersecting and touching segments', function() {
var segments = replay.getIntersections_({p0: {x: 0, y: 3}, p1: {x: 4, y: 5}},
rtree, true);
const segments = replay.getIntersections_({p0: {x: 0, y: 3}, p1: {x: 4, y: 5}},
rtree, true);
expect(segments).to.eql([s0, s1, s2, s3]);
});
});
describe('#calculateIntersection_', function() {
var p0 = {x: 0, y: 0};
var p1 = {x: 4, y: 4};
var p2 = {x: 0, y: 4};
var p3 = {x: 4, y: 0};
const p0 = {x: 0, y: 0};
const p1 = {x: 4, y: 4};
const p2 = {x: 0, y: 4};
const p3 = {x: 4, y: 0};
it('calculates the intersection point of two intersecting segments', function() {
var i = replay.calculateIntersection_(p0, p1, p2, p3);
var t = replay.calculateIntersection_(p0, p1, p1, p2);
const i = replay.calculateIntersection_(p0, p1, p2, p3);
const t = replay.calculateIntersection_(p0, p1, p1, p2);
expect(i).to.eql([2, 2]);
expect(t).to.be(undefined);
});
it('calculates the intersection point of two touching segments', function() {
var t = replay.calculateIntersection_(p0, p1, p1, p2, true);
const t = replay.calculateIntersection_(p0, p1, p1, p2, true);
expect(t).to.eql([4, 4]);
});
});
describe('#diagonalIsInside_', function() {
var p0, p1, p2, p3;
let p0, p1, p2, p3;
beforeEach(function() {
p0 = replay.createPoint_(2, 0, 0);
p1 = replay.createPoint_(0, 5, 1);
@@ -241,18 +241,18 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
it('identifies if diagonal is inside the polygon', function() {
var inside = replay.diagonalIsInside_(p1, p2, p3, p0, p1);
const inside = replay.diagonalIsInside_(p1, p2, p3, p0, p1);
expect(inside).to.be(true);
});
it('identifies if diagonal is outside the polygon', function() {
var inside = replay.diagonalIsInside_(p0, p1, p2, p3, p0);
const inside = replay.diagonalIsInside_(p0, p1, p2, p3, p0);
expect(inside).to.be(false);
});
});
describe('#classifyPoints_', function() {
var p0, p1, p2, p3;
let p0, p1, p2, p3;
beforeEach(function() {
p0 = replay.createPoint_(2, 0, 0);
p1 = replay.createPoint_(0, 5, 1);
@@ -289,7 +289,7 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
describe('#isSimple_', function() {
var p0, p1, p2, p3;
let p0, p1, p2, p3;
beforeEach(function() {
p0 = replay.createPoint_(2, 0, 0);
p1 = replay.createPoint_(0, 5, 1);
@@ -302,24 +302,24 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
it('identifies simple polygons', function() {
var simple = replay.isSimple_(list, rtree);
const simple = replay.isSimple_(list, rtree);
expect(simple).to.be(true);
});
it('identifies self-intersecting polygons', function() {
var p4 = replay.createPoint_(2, 5, 4);
var p5 = replay.createPoint_(4, 2, 5);
const p4 = replay.createPoint_(2, 5, 4);
const p5 = replay.createPoint_(4, 2, 5);
replay.insertItem_(p0, p4, list, rtree);
replay.insertItem_(p4, p5, list, rtree);
replay.insertItem_(p5, p0, list, rtree);
var simple = replay.isSimple_(list, rtree);
const simple = replay.isSimple_(list, rtree);
expect(simple).to.be(false);
});
});
});
describe('#setUpProgram', function() {
var context, gl;
let context, gl;
beforeEach(function() {
context = {
getProgram: function() {},
@@ -336,9 +336,9 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
it('returns the locations used by the shaders', function() {
var locations = replay.setUpProgram(gl, context, [2, 2], 1);
const locations = replay.setUpProgram(gl, context, [2, 2], 1);
expect(locations).to.be.a(
_ol_render_webgl_polygonreplay_defaultshader_Locations_);
_ol_render_webgl_polygonreplay_defaultshader_Locations_);
});
it('gets and compiles the shaders', function() {
@@ -347,8 +347,8 @@ describe('ol.render.webgl.PolygonReplay', function() {
replay.setUpProgram(gl, context, [2, 2], 1);
expect(context.getProgram.calledWithExactly(
_ol_render_webgl_polygonreplay_defaultshader_.fragment,
_ol_render_webgl_polygonreplay_defaultshader_.vertex)).to.be(true);
_ol_render_webgl_polygonreplay_defaultshader_.fragment,
_ol_render_webgl_polygonreplay_defaultshader_.vertex)).to.be(true);
expect(context.useProgram.calledOnce).to.be(true);
});
@@ -360,12 +360,12 @@ describe('ol.render.webgl.PolygonReplay', function() {
replay.setUpProgram(gl, context, [2, 2], 1);
expect(gl.vertexAttribPointer.callCount).to.be(gl.getAttribLocation.callCount);
expect(gl.enableVertexAttribArray.callCount).to.be(
gl.getAttribLocation.callCount);
gl.getAttribLocation.callCount);
});
});
describe('#shutDownProgram', function() {
var context, gl;
let context, gl;
beforeEach(function() {
context = {
getProgram: function() {},
@@ -386,22 +386,22 @@ describe('ol.render.webgl.PolygonReplay', function() {
sinon.spy(gl, 'getAttribLocation');
sinon.spy(gl, 'disableVertexAttribArray');
var locations = replay.setUpProgram(gl, context, [2, 2], 1);
const locations = replay.setUpProgram(gl, context, [2, 2], 1);
replay.shutDownProgram(gl, locations);
expect(gl.disableVertexAttribArray.callCount).to.be(
gl.getAttribLocation.callCount);
gl.getAttribLocation.callCount);
});
});
describe('#drawReplay', function() {
var gl, context;
var feature1 = new Feature({
let gl, context;
const feature1 = new Feature({
geometry: new Polygon([[[0, 0], [500, 500], [500, 0], [0, 0]]])
});
var feature2 = new Feature({
const feature2 = new Feature({
geometry: new Polygon([[[0, 0], [500, 500], [500, 0], [0, 0]]])
});
var feature3 = new Feature({
const feature3 = new Feature({
geometry: new Polygon([[[0, 0], [500, 500], [500, 0], [0, 0]]])
});
beforeEach(function() {
@@ -435,7 +435,7 @@ describe('ol.render.webgl.PolygonReplay', function() {
});
it('draws the elements in batches if there are multiple fill styles', function() {
var fillStyle2 = new Fill({
const fillStyle2 = new Fill({
color: [0, 255, 0, 1]
});
replay.setFillStrokeStyle(fillStyle, strokeStyle);
@@ -459,7 +459,7 @@ describe('ol.render.webgl.PolygonReplay', function() {
replay.setFillStrokeStyle(fillStyle, strokeStyle);
replay.drawPolygon(feature3.getGeometry(), feature3);
replay.startIndices.push(replay.indices.length);
var skippedFeatHash = {};
const skippedFeatHash = {};
skippedFeatHash[getUid(feature2).toString()] = true;
replay.drawReplay(gl, context, skippedFeatHash, false);
+79 -80
View File
@@ -6,10 +6,10 @@ import Stroke from '../../../../../src/ol/style/Stroke.js';
import Text from '../../../../../src/ol/style/Text.js';
describe('ol.render.webgl.TextReplay', function() {
var replay;
let replay;
var createTextStyle = function(fillStyle, strokeStyle, text) {
var textStyle = new Text({
const createTextStyle = function(fillStyle, strokeStyle, text) {
const textStyle = new Text({
rotateWithView: true,
rotation: 1.5,
scale: 2,
@@ -26,50 +26,50 @@ describe('ol.render.webgl.TextReplay', function() {
};
beforeEach(function() {
var tolerance = 0.1;
var maxExtent = [-10000, -20000, 10000, 20000];
const tolerance = 0.1;
const maxExtent = [-10000, -20000, 10000, 20000];
replay = new _ol_render_webgl_TextReplay_(tolerance, maxExtent);
});
describe('#setTextStyle', function() {
var textStyle1, textStyle2, textStyle3, textStyle4;
let textStyle1, textStyle2, textStyle3, textStyle4;
beforeEach(function() {
textStyle1 = createTextStyle(
new Fill({
color: [0, 0, 0, 1]
}),
new Stroke({
width: 1,
color: [0, 0, 0, 1],
lineCap: 'butt',
lineJoin: 'bevel',
lineDash: [5, 5],
lineDashOffset: 15,
miterLimit: 2
}),
'someText');
new Fill({
color: [0, 0, 0, 1]
}),
new Stroke({
width: 1,
color: [0, 0, 0, 1],
lineCap: 'butt',
lineJoin: 'bevel',
lineDash: [5, 5],
lineDashOffset: 15,
miterLimit: 2
}),
'someText');
textStyle2 = createTextStyle(
new Fill({
color: [255, 255, 255, 1]
}),
new Stroke({
width: 1,
color: [255, 255, 255, 1]
}),
'someText'
new Fill({
color: [255, 255, 255, 1]
}),
new Stroke({
width: 1,
color: [255, 255, 255, 1]
}),
'someText'
);
textStyle3 = createTextStyle(null, null, 'someText');
textStyle4 = createTextStyle(
new Fill({
color: [0, 0, 0, 1]
}),
new Stroke({
width: 1,
color: [0, 0, 0, 1]
}),
''
new Fill({
color: [0, 0, 0, 1]
}),
new Stroke({
width: 1,
color: [0, 0, 0, 1]
}),
''
);
});
@@ -114,16 +114,16 @@ describe('ol.render.webgl.TextReplay', function() {
describe('#drawText', function() {
beforeEach(function() {
var textStyle = createTextStyle(
new Fill({
color: [0, 0, 0, 1]
}),
null, 'someText');
const textStyle = createTextStyle(
new Fill({
color: [0, 0, 0, 1]
}),
null, 'someText');
replay.setTextStyle(textStyle);
});
it('sets the buffer data', function() {
var point;
let point;
point = [1000, 2000];
replay.drawText(new Point(point), null);
@@ -137,15 +137,15 @@ describe('ol.render.webgl.TextReplay', function() {
});
it('sets part of its state during drawing', function() {
var point = [1000, 2000];
const point = [1000, 2000];
replay.drawText(new Point(point), null);
var height = replay.currAtlas_.height;
var widths = replay.currAtlas_.width;
var width = widths.t;
var widthX = widths.s + widths.o + widths.m + widths.e + widths.T +
const height = replay.currAtlas_.height;
const widths = replay.currAtlas_.width;
const width = widths.t;
const widthX = widths.s + widths.o + widths.m + widths.e + widths.T +
widths.e + widths.x;
var charInfo = replay.currAtlas_.atlas.getInfo('t');
const charInfo = replay.currAtlas_.atlas.getInfo('t');
expect(replay.height).to.be(height);
expect(replay.width).to.be(width);
@@ -159,9 +159,8 @@ describe('ol.render.webgl.TextReplay', function() {
it('does not draw if text is empty', function() {
replay.text_ = '';
var point;
point = [1000, 2000];
const point = [1000, 2000];
replay.drawText(new Point(point), null);
expect(replay.vertices).to.have.length(0);
expect(replay.indices).to.have.length(0);
@@ -170,17 +169,17 @@ describe('ol.render.webgl.TextReplay', function() {
describe('#addCharToAtlas_', function() {
beforeEach(function() {
var textStyle = createTextStyle(
new Fill({
color: [0, 0, 0, 1]
}),
null, 'someText');
const textStyle = createTextStyle(
new Fill({
color: [0, 0, 0, 1]
}),
null, 'someText');
replay.setTextStyle(textStyle);
});
it('adds a single character to the current atlas', function() {
var glyphAtlas = replay.currAtlas_.atlas;
var info;
const glyphAtlas = replay.currAtlas_.atlas;
let info;
replay.addCharToAtlas_('someText');
info = glyphAtlas.getInfo('someText');
@@ -195,7 +194,7 @@ describe('ol.render.webgl.TextReplay', function() {
});
it('keeps the atlas and the width dictionary synced', function() {
var glyphAtlas = replay.currAtlas_;
const glyphAtlas = replay.currAtlas_;
replay.addCharToAtlas_('e');
replay.addCharToAtlas_('x');
@@ -208,18 +207,18 @@ describe('ol.render.webgl.TextReplay', function() {
describe('#getTextSize_', function() {
beforeEach(function() {
var textStyle = createTextStyle(
new Fill({
color: [0, 0, 0, 1]
}),
null, 'someText');
const textStyle = createTextStyle(
new Fill({
color: [0, 0, 0, 1]
}),
null, 'someText');
textStyle.setScale(1);
replay.setTextStyle(textStyle);
});
it('adds missing characters to the current atlas', function() {
var glyphAtlas = replay.currAtlas_;
var info;
const glyphAtlas = replay.currAtlas_;
let info;
expect(Object.keys(glyphAtlas.width)).to.have.length(0);
replay.getTextSize_(['someText']);
@@ -241,12 +240,12 @@ describe('ol.render.webgl.TextReplay', function() {
});
it('returns the size of the label\'s bounding box in pixels', function() {
var size;
var mCtx = createCanvasContext2D(0, 0);
let size;
const mCtx = createCanvasContext2D(0, 0);
mCtx.font = '12px Arial';
var width = mCtx.measureText('someText').width;
var width2 = mCtx.measureText('anEvenLongerLine').width;
var height = Math.ceil(mCtx.measureText('M').width * 1.5);
const width = mCtx.measureText('someText').width;
const width2 = mCtx.measureText('anEvenLongerLine').width;
const height = Math.ceil(mCtx.measureText('M').width * 1.5);
size = replay.getTextSize_(['someText']);
expect(size[0]).to.be.within(width, width + 8);
@@ -260,17 +259,17 @@ describe('ol.render.webgl.TextReplay', function() {
describe('#getAtlas_', function() {
beforeEach(function() {
var textStyle = createTextStyle(
new Fill({
color: [0, 0, 0, 1]
}),
null, 'someText');
const textStyle = createTextStyle(
new Fill({
color: [0, 0, 0, 1]
}),
null, 'someText');
replay.setTextStyle(textStyle);
});
it('returns the appropriate atlas for the current state', function() {
var atlas = replay.currAtlas_;
var state = replay.state_;
const atlas = replay.currAtlas_;
const state = replay.state_;
expect(Object.keys(replay.atlases_)).to.have.length(1);
expect(replay.getAtlas_(state)).to.be(atlas);
@@ -278,8 +277,8 @@ describe('ol.render.webgl.TextReplay', function() {
});
it('creates a new atlas if it cannot find the one for the current state', function() {
var atlas = replay.currAtlas_;
var state = replay.state_;
const atlas = replay.currAtlas_;
const state = replay.state_;
state.lineWidth = 50;
expect(Object.keys(replay.atlases_)).to.have.length(1);
@@ -294,7 +293,7 @@ describe('ol.render.webgl.TextReplay', function() {
});
it('returns the textures', function() {
var textures = replay.getTextures();
const textures = replay.getTextures();
expect(textures).to.have.length(2);
expect(textures[0]).to.be(1);
@@ -309,7 +308,7 @@ describe('ol.render.webgl.TextReplay', function() {
});
it('returns the textures', function() {
var textures = replay.getHitDetectionTextures();
const textures = replay.getHitDetectionTextures();
expect(textures).to.have.length(2);
expect(textures[0]).to.be(1);
+12 -12
View File
@@ -3,16 +3,16 @@ import _ol_render_webgl_texturereplay_defaultshader_ from '../../../../../src/ol
import _ol_render_webgl_texturereplay_defaultshader_Locations_ from '../../../../../src/ol/render/webgl/texturereplay/defaultshader/Locations.js';
describe('ol.render.webgl.TextureReplay', function() {
var replay;
let replay;
beforeEach(function() {
var tolerance = 0.1;
var maxExtent = [-10000, -20000, 10000, 20000];
const tolerance = 0.1;
const maxExtent = [-10000, -20000, 10000, 20000];
replay = new _ol_render_webgl_TextureReplay_(tolerance, maxExtent);
});
describe('#setUpProgram', function() {
var context, gl;
let context, gl;
beforeEach(function() {
context = {
getProgram: function() {},
@@ -29,9 +29,9 @@ describe('ol.render.webgl.TextureReplay', function() {
});
it('returns the locations used by the shaders', function() {
var locations = replay.setUpProgram(gl, context, [2, 2], 1);
const locations = replay.setUpProgram(gl, context, [2, 2], 1);
expect(locations).to.be.a(
_ol_render_webgl_texturereplay_defaultshader_Locations_);
_ol_render_webgl_texturereplay_defaultshader_Locations_);
});
it('gets and compiles the shaders', function() {
@@ -40,8 +40,8 @@ describe('ol.render.webgl.TextureReplay', function() {
replay.setUpProgram(gl, context, [2, 2], 1);
expect(context.getProgram.calledWithExactly(
_ol_render_webgl_texturereplay_defaultshader_.fragment,
_ol_render_webgl_texturereplay_defaultshader_.vertex)).to.be(true);
_ol_render_webgl_texturereplay_defaultshader_.fragment,
_ol_render_webgl_texturereplay_defaultshader_.vertex)).to.be(true);
expect(context.useProgram.calledOnce).to.be(true);
});
@@ -53,12 +53,12 @@ describe('ol.render.webgl.TextureReplay', function() {
replay.setUpProgram(gl, context, [2, 2], 1);
expect(gl.vertexAttribPointer.callCount).to.be(gl.getAttribLocation.callCount);
expect(gl.enableVertexAttribArray.callCount).to.be(
gl.getAttribLocation.callCount);
gl.getAttribLocation.callCount);
});
});
describe('#shutDownProgram', function() {
var context, gl;
let context, gl;
beforeEach(function() {
context = {
getProgram: function() {},
@@ -79,10 +79,10 @@ describe('ol.render.webgl.TextureReplay', function() {
sinon.spy(gl, 'getAttribLocation');
sinon.spy(gl, 'disableVertexAttribArray');
var locations = replay.setUpProgram(gl, context, [2, 2], 1);
const locations = replay.setUpProgram(gl, context, [2, 2], 1);
replay.shutDownProgram(gl, locations);
expect(gl.disableVertexAttribArray.callCount).to.be(
gl.getAttribLocation.callCount);
gl.getAttribLocation.callCount);
});
});
});