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

View File

@@ -3,7 +3,7 @@ import _ol_geom_flat_simplify_ from '../../../../../src/ol/geom/flat/simplify.js
describe('ol.geom.flat.simplify', function() {
var flatCoordinates = [
const flatCoordinates = [
224.55, 250.15, 226.91, 244.19, 233.31, 241.45, 234.98, 236.06,
244.21, 232.76, 262.59, 215.31, 267.76, 213.81, 273.57, 201.84,
273.12, 192.16, 277.62, 189.03, 280.36, 181.41, 286.51, 177.74,
@@ -31,7 +31,7 @@ describe('ol.geom.flat.simplify', function() {
847.16, 458.44, 851.38, 462.79, 853.97, 471.15, 866.36, 480.77
];
var simplifiedRadiallyFlatCoordinates = [
const simplifiedRadiallyFlatCoordinates = [
224.55, 250.15, 226.91, 244.19, 233.31, 241.45, 234.98, 236.06,
244.21, 232.76, 262.59, 215.31, 267.76, 213.81, 273.57, 201.84,
273.12, 192.16, 277.62, 189.03, 280.36, 181.41, 286.51, 177.74,
@@ -57,7 +57,7 @@ describe('ol.geom.flat.simplify', function() {
851.38, 462.79, 853.97, 471.15, 866.36, 480.77
];
var simplifiedFlatCoordinates = [
const simplifiedFlatCoordinates = [
224.55, 250.15, 267.76, 213.81, 296.91, 155.64, 330.33, 137.57,
409.52, 141.14, 439.60, 119.74, 486.51, 106.75, 529.57, 127.86,
539.27, 147.24, 617.74, 159.86, 629.55, 194.60, 671.55, 222.55,
@@ -69,7 +69,7 @@ describe('ol.geom.flat.simplify', function() {
866.36, 480.77
];
var simplifiedHighQualityFlatCoordinates = [
const simplifiedHighQualityFlatCoordinates = [
224.55, 250.15, 267.76, 213.81, 296.91, 155.64, 330.33, 137.57,
409.52, 141.14, 439.60, 119.74, 486.51, 106.75, 529.57, 127.86,
539.27, 147.24, 617.74, 159.86, 629.55, 194.60, 671.55, 222.55,
@@ -85,28 +85,28 @@ describe('ol.geom.flat.simplify', function() {
it('works with empty line strings', function() {
expect(_ol_geom_flat_simplify_.lineString([], 0, 0, 2, 1, true)).to.
eql([]);
eql([]);
expect(_ol_geom_flat_simplify_.lineString([], 0, 0, 2, 1, false)).to.
eql([]);
eql([]);
});
it('works with a line string with a single point', function() {
expect(_ol_geom_flat_simplify_.lineString([1, 2], 0, 2, 2, 1, true)).to.
eql([1, 2]);
eql([1, 2]);
expect(_ol_geom_flat_simplify_.lineString([1, 2], 0, 2, 2, 1, false)).to.
eql([1, 2]);
eql([1, 2]);
});
it('returns the expected result with low quality', function() {
var result = _ol_geom_flat_simplify_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, 25, false);
const result = _ol_geom_flat_simplify_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, 25, false);
expect(result.length).to.be(simplifiedFlatCoordinates.length);
expect(result).to.eql(simplifiedFlatCoordinates);
});
it('returns the expected result with high quality', function() {
var result = _ol_geom_flat_simplify_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, 25, true);
const result = _ol_geom_flat_simplify_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, 25, true);
expect(result.length).to.be(simplifiedHighQualityFlatCoordinates.length);
expect(result).to.eql(simplifiedHighQualityFlatCoordinates);
});
@@ -115,71 +115,71 @@ describe('ol.geom.flat.simplify', function() {
describe('ol.geom.flat.simplify.radialDistance', function() {
var dest;
let dest;
beforeEach(function() {
dest = [];
});
it('works with empty line strings', function() {
expect(_ol_geom_flat_simplify_.radialDistance(
[], 0, 0, 2, 1, dest, 0)).to.be(0);
[], 0, 0, 2, 1, dest, 0)).to.be(0);
expect(dest).to.eql([]);
});
it('works with a line string with a single point', function() {
expect(_ol_geom_flat_simplify_.radialDistance(
[1, 2], 0, 2, 2, 1, dest, 0)).to.be(2);
[1, 2], 0, 2, 2, 1, dest, 0)).to.be(2);
expect(dest).to.eql([1, 2]);
});
it('works with a line string with two points', function() {
expect(_ol_geom_flat_simplify_.radialDistance(
[1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4);
[1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4);
expect(dest).to.eql([1, 2, 3, 4]);
});
it('works when the points are widely spaced', function() {
expect(_ol_geom_flat_simplify_.radialDistance(
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)).to.be(8);
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)).to.be(8);
expect(dest).to.eql([0, 0, 1, 0, 2, 0, 3, 0]);
});
it('works when the spacing matches the tolerance', function() {
expect(_ol_geom_flat_simplify_.radialDistance(
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)).to.be(6);
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)).to.be(6);
expect(dest).to.eql([0, 0, 2, 0, 3, 0]);
});
it('works when the points are closely spaced', function() {
expect(_ol_geom_flat_simplify_.radialDistance(
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)).to.be(6);
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)).to.be(6);
expect(dest).to.eql([0, 0, 2, 0, 3, 0]);
});
it('works when the line oscillates with widely spaced points', function() {
expect(_ol_geom_flat_simplify_.radialDistance(
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 1, dest, 0)).
to.be(12);
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 1, dest, 0)).
to.be(12);
expect(dest).to.eql([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]);
});
it('works when the line oscillates with closely spaced points', function() {
expect(_ol_geom_flat_simplify_.radialDistance(
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 2, dest, 0)).to.be(4);
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 2, dest, 0)).to.be(4);
expect(dest).to.eql([0, 0, 1, 1]);
});
it('works when the line oscillates within the tolerance', function() {
expect(_ol_geom_flat_simplify_.radialDistance(
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], 0, 14, 2, 2, dest, 0)).
to.be(2);
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], 0, 14, 2, 2, dest, 0)).
to.be(2);
expect(dest).to.eql([0, 0]);
});
it('works with real data', function() {
expect(_ol_geom_flat_simplify_.radialDistance(
flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)).
to.be(simplifiedRadiallyFlatCoordinates.length);
flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)).
to.be(simplifiedRadiallyFlatCoordinates.length);
expect(dest).to.eql(simplifiedRadiallyFlatCoordinates);
});
@@ -187,101 +187,101 @@ describe('ol.geom.flat.simplify', function() {
describe('ol.geom.flat.simplify.douglasPeucker', function() {
var dest;
let dest;
beforeEach(function() {
dest = [];
});
it('works with empty line strings', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[], 0, 0, 2, 1, dest, 0)).to.be(0);
[], 0, 0, 2, 1, dest, 0)).to.be(0);
expect(dest).to.eql([]);
});
it('works with a line string with a single point', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[1, 2], 0, 2, 2, 1, dest, 0)).to.be(2);
[1, 2], 0, 2, 2, 1, dest, 0)).to.be(2);
expect(dest).to.eql([1, 2]);
});
it('works with a line string with two points', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4);
[1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4);
expect(dest).to.eql([1, 2, 3, 4]);
});
it('works when the points are widely spaced', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)).to.be(4);
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)).to.be(4);
expect(dest).to.eql([0, 0, 3, 0]);
});
it('works when the spacing matches the tolerance', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)).to.be(4);
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)).to.be(4);
expect(dest).to.eql([0, 0, 3, 0]);
});
it('works when the points are closely spaced', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)).to.be(4);
[0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)).to.be(4);
expect(dest).to.eql([0, 0, 3, 0]);
});
it('does not elimnate points outside the tolerance', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[0, 0, 1, 1, 2, 0], 0, 6, 2, 0.5, dest, 0)).to.be(6);
[0, 0, 1, 1, 2, 0], 0, 6, 2, 0.5, dest, 0)).to.be(6);
expect(dest).to.eql([0, 0, 1, 1, 2, 0]);
});
it('does eliminate points within the tolerance', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[0, 0, 1, 1, 2, 0], 0, 6, 2, 2, dest, 0)).to.be(4);
[0, 0, 1, 1, 2, 0], 0, 6, 2, 2, dest, 0)).to.be(4);
expect(dest).to.eql([0, 0, 2, 0]);
});
it('does not eliminate multiple points outside the tolerance', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 0.5, dest, 0)).to.be(8);
[0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 0.5, dest, 0)).to.be(8);
expect(dest).to.eql([0, 0, 1, 1, 1, -1, 2, 0]);
});
it('does eliminate multiple points within the tolerance', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 2, dest, 0)).to.be(4);
[0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 2, dest, 0)).to.be(4);
expect(dest).to.eql([0, 0, 2, 0]);
});
it('works when the line oscillates with widely spaced points', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 1, dest, 0)).to.be(4);
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 1, dest, 0)).to.be(4);
expect(dest).to.eql([0, 0, 1, 1]);
});
it('works when the line oscillates with closely spaced points', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 2, dest, 0)).
to.be(4);
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], 0, 12, 2, 2, dest, 0)).
to.be(4);
expect(dest).to.eql([0, 0, 1, 1]);
});
it('works when the line oscillates within the tolerance', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], 0, 14, 2, 2, dest, 0)).
to.be(4);
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0], 0, 14, 2, 2, dest, 0)).
to.be(4);
expect(dest).to.eql([0, 0, 0, 0]);
});
it('works on small triangles', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
[3, 0, 4, 1, 5, 2, 5, 0], 0, 8, 2, 1, dest, 0)).to.be(6);
[3, 0, 4, 1, 5, 2, 5, 0], 0, 8, 2, 1, dest, 0)).to.be(6);
expect(dest).to.eql([3, 0, 5, 2, 5, 0]);
});
it('is the same as high quality simplification', function() {
expect(_ol_geom_flat_simplify_.douglasPeucker(
flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)).
to.be(simplifiedHighQualityFlatCoordinates.length);
flatCoordinates, 0, flatCoordinates.length, 2, 25, dest, 0)).
to.be(simplifiedHighQualityFlatCoordinates.length);
expect(dest).to.eql(simplifiedHighQualityFlatCoordinates);
});
@@ -290,63 +290,63 @@ describe('ol.geom.flat.simplify', function() {
describe('ol.geom.flat.simplify.quantize', function() {
it('handles empty coordinates', function() {
var simplifiedFlatCoordinates = [];
const simplifiedFlatCoordinates = [];
expect(_ol_geom_flat_simplify_.quantize(
[], 0, 0, 2, 2, simplifiedFlatCoordinates, 0)).to.be(0);
[], 0, 0, 2, 2, simplifiedFlatCoordinates, 0)).to.be(0);
expect(simplifiedFlatCoordinates).to.be.empty();
});
it('expands points to a zero-length line', function() {
var simplifiedFlatCoordinates = [];
const simplifiedFlatCoordinates = [];
expect(_ol_geom_flat_simplify_.quantize(
[0, 0, 0, 0], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4);
[0, 0, 0, 0], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4);
expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, 0]);
});
it('snaps near-by points to the same value', function() {
var simplifiedFlatCoordinates = [];
const simplifiedFlatCoordinates = [];
expect(_ol_geom_flat_simplify_.quantize(
[0.1, 0, 0, 0.1], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4);
[0.1, 0, 0, 0.1], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)).to.be(4);
expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, 0]);
});
it('eliminates duplicate snapped points', function() {
var simplifiedFlatCoordinates = [];
const simplifiedFlatCoordinates = [];
expect(_ol_geom_flat_simplify_.quantize(
[0.1, 0, 2, 0, 2.1, 0, 2, 0.1, 1.9, 0, 2, -0.1], 0, 12, 2, 2,
simplifiedFlatCoordinates, 0)).to.be(4);
[0.1, 0, 2, 0, 2.1, 0, 2, 0.1, 1.9, 0, 2, -0.1], 0, 12, 2, 2,
simplifiedFlatCoordinates, 0)).to.be(4);
expect(simplifiedFlatCoordinates).to.eql([0, 0, 2, 0]);
});
it('eliminates horizontal colinear points', function() {
var simplifiedFlatCoordinates = [];
const simplifiedFlatCoordinates = [];
expect(_ol_geom_flat_simplify_.quantize(
[0, 0, 2, 0, 4, 0, 6, 0], 0, 8, 2, 2,
simplifiedFlatCoordinates, 0)).to.be(4);
[0, 0, 2, 0, 4, 0, 6, 0], 0, 8, 2, 2,
simplifiedFlatCoordinates, 0)).to.be(4);
expect(simplifiedFlatCoordinates).to.eql([0, 0, 6, 0]);
});
it('eliminates vertical colinear points', function() {
var simplifiedFlatCoordinates = [];
const simplifiedFlatCoordinates = [];
expect(_ol_geom_flat_simplify_.quantize(
[0, 0, 0, -2, 0, -4, 0, -6], 0, 8, 2, 2,
simplifiedFlatCoordinates, 0)).to.be(4);
[0, 0, 0, -2, 0, -4, 0, -6], 0, 8, 2, 2,
simplifiedFlatCoordinates, 0)).to.be(4);
expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, -6]);
});
it('eliminates diagonal colinear points', function() {
var simplifiedFlatCoordinates = [];
const simplifiedFlatCoordinates = [];
expect(_ol_geom_flat_simplify_.quantize(
[0, 0, 2, -2, 4, -4, 6, -6], 0, 8, 2, 2,
simplifiedFlatCoordinates, 0)).to.be(4);
[0, 0, 2, -2, 4, -4, 6, -6], 0, 8, 2, 2,
simplifiedFlatCoordinates, 0)).to.be(4);
expect(simplifiedFlatCoordinates).to.eql([0, 0, 6, -6]);
});
it('handles switchbacks', function() {
var simplifiedFlatCoordinates = [];
const simplifiedFlatCoordinates = [];
expect(_ol_geom_flat_simplify_.quantize(
[0, 0, 2, 0, 0, 0, 4, 0], 0, 8, 2, 2,
simplifiedFlatCoordinates, 0)).to.be(8);
[0, 0, 2, 0, 0, 0, 4, 0], 0, 8, 2, 2,
simplifiedFlatCoordinates, 0)).to.be(8);
expect(simplifiedFlatCoordinates).to.eql([0, 0, 2, 0, 0, 0, 4, 0]);
});