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
+44 -44
View File
@@ -5,7 +5,7 @@ describe('ol.geom.Circle', function() {
describe('with a unit circle', function() {
var circle;
let circle;
beforeEach(function() {
circle = new Circle([0, 0], 1);
});
@@ -13,7 +13,7 @@ describe('ol.geom.Circle', function() {
describe('#clone', function() {
it('returns a clone', function() {
var clone = circle.clone();
const clone = circle.clone();
expect(clone).to.be.an(Circle);
expect(clone.getCenter()).to.eql(circle.getCenter());
expect(clone.getCenter()).not.to.be(circle.getCenter());
@@ -62,7 +62,7 @@ describe('ol.geom.Circle', function() {
describe('#getClosestPoint', function() {
it('returns the closest point on the perimeter', function() {
var closestPoint;
let closestPoint;
closestPoint = circle.getClosestPoint([2, 0]);
expect(closestPoint[0]).to.roughlyEqual(1, 1e-15);
expect(closestPoint[1]).to.roughlyEqual(0, 1e-15);
@@ -90,9 +90,9 @@ describe('ol.geom.Circle', function() {
});
it('maintains Z coordinates', function() {
var circle = new Circle([0, 0, 1], 1);
const circle = new Circle([0, 0, 1], 1);
expect(circle.getLayout()).to.be('XYZ');
var closestPoint = circle.getClosestPoint([2, 0]);
const closestPoint = circle.getClosestPoint([2, 0]);
expect(closestPoint).to.have.length(3);
expect(closestPoint[0]).to.roughlyEqual(1, 1e-15);
expect(closestPoint[1]).to.roughlyEqual(0, 1e-15);
@@ -100,9 +100,9 @@ describe('ol.geom.Circle', function() {
});
it('maintains M coordinates', function() {
var circle = new Circle([0, 0, 2], 1,
'XYM');
var closestPoint = circle.getClosestPoint([2, 0]);
const circle = new Circle([0, 0, 2], 1,
'XYM');
const closestPoint = circle.getClosestPoint([2, 0]);
expect(closestPoint).to.have.length(3);
expect(closestPoint[0]).to.roughlyEqual(1, 1e-15);
expect(closestPoint[1]).to.roughlyEqual(0, 1e-15);
@@ -110,9 +110,9 @@ describe('ol.geom.Circle', function() {
});
it('maintains Z and M coordinates', function() {
var circle = new Circle([0, 0, 1, 2], 1);
const circle = new Circle([0, 0, 1, 2], 1);
expect(circle.getLayout()).to.be('XYZM');
var closestPoint = circle.getClosestPoint([2, 0]);
const closestPoint = circle.getClosestPoint([2, 0]);
expect(closestPoint).to.have.length(4);
expect(closestPoint[0]).to.roughlyEqual(1, 1e-15);
expect(closestPoint[1]).to.roughlyEqual(0, 1e-15);
@@ -162,7 +162,7 @@ describe('ol.geom.Circle', function() {
});
it('fires a change event', function() {
var spy = sinon.spy();
const spy = sinon.spy();
circle.on('change', spy);
circle.setCenter([1, 2]);
expect(spy.calledOnce).to.be(true);
@@ -179,7 +179,7 @@ describe('ol.geom.Circle', function() {
});
it('fires a single change event', function() {
var spy = sinon.spy();
const spy = sinon.spy();
circle.on('change', spy);
circle.setFlatCoordinates('XY', [1, 2, 4, 2]);
expect(spy.calledOnce).to.be(true);
@@ -195,7 +195,7 @@ describe('ol.geom.Circle', function() {
});
it('fires a change event', function() {
var spy = sinon.spy();
const spy = sinon.spy();
circle.on('change', spy);
circle.setRadius(2);
expect(spy.calledOnce).to.be(true);
@@ -206,36 +206,36 @@ describe('ol.geom.Circle', function() {
describe('#intersectsExtent', function() {
it('returns false for non-intersecting extents (wide outside own bbox)',
function() {
var wideOutsideLeftTop = [-3, 2, -2, 3];
var wideOutsideRightTop = [2, 2, 3, 3];
var wideOutsideRightBottom = [2, -3, 3, -2];
var wideOutsideLeftBottom = [-3, -3, -2, -2];
expect(circle.intersectsExtent(wideOutsideLeftTop)).to.be(false);
expect(circle.intersectsExtent(wideOutsideRightTop)).to.be(false);
expect(circle.intersectsExtent(wideOutsideRightBottom)).to.be(false);
expect(circle.intersectsExtent(wideOutsideLeftBottom)).to.be(false);
}
function() {
const wideOutsideLeftTop = [-3, 2, -2, 3];
const wideOutsideRightTop = [2, 2, 3, 3];
const wideOutsideRightBottom = [2, -3, 3, -2];
const wideOutsideLeftBottom = [-3, -3, -2, -2];
expect(circle.intersectsExtent(wideOutsideLeftTop)).to.be(false);
expect(circle.intersectsExtent(wideOutsideRightTop)).to.be(false);
expect(circle.intersectsExtent(wideOutsideRightBottom)).to.be(false);
expect(circle.intersectsExtent(wideOutsideLeftBottom)).to.be(false);
}
);
it('returns false for non-intersecting extents (inside own bbox)',
function() {
var nearOutsideLeftTop = [-1, 0.9, -0.9, 1];
var nearOutsideRightTop = [0.9, 0.9, 1, 1];
var nearOutsideRightBottom = [0.9, -1, 1, -0.9];
var nearOutsideLeftBottom = [-1, -1, -0.9, -0.9];
expect(circle.intersectsExtent(nearOutsideLeftTop)).to.be(false);
expect(circle.intersectsExtent(nearOutsideRightTop)).to.be(false);
expect(circle.intersectsExtent(nearOutsideRightBottom)).to.be(false);
expect(circle.intersectsExtent(nearOutsideLeftBottom)).to.be(false);
}
function() {
const nearOutsideLeftTop = [-1, 0.9, -0.9, 1];
const nearOutsideRightTop = [0.9, 0.9, 1, 1];
const nearOutsideRightBottom = [0.9, -1, 1, -0.9];
const nearOutsideLeftBottom = [-1, -1, -0.9, -0.9];
expect(circle.intersectsExtent(nearOutsideLeftTop)).to.be(false);
expect(circle.intersectsExtent(nearOutsideRightTop)).to.be(false);
expect(circle.intersectsExtent(nearOutsideRightBottom)).to.be(false);
expect(circle.intersectsExtent(nearOutsideLeftBottom)).to.be(false);
}
);
it('returns true for extents that intersect clearly', function() {
var intersectingLeftTop = [-1.5, 0.5, -0.5, 1.5];
var intersectingRightTop = [0.5, 0.5, 1.5, 1.5];
var intersectingRightBottom = [0.5, -1.5, 1.5, -0.5];
var intersectingLeftBottom = [-1.5, -1.5, -0.5, -0.5];
const intersectingLeftTop = [-1.5, 0.5, -0.5, 1.5];
const intersectingRightTop = [0.5, 0.5, 1.5, 1.5];
const intersectingRightBottom = [0.5, -1.5, 1.5, -0.5];
const intersectingLeftBottom = [-1.5, -1.5, -0.5, -0.5];
expect(circle.intersectsExtent(intersectingLeftTop)).to.be(true);
expect(circle.intersectsExtent(intersectingRightTop)).to.be(true);
expect(circle.intersectsExtent(intersectingRightBottom)).to.be(true);
@@ -243,10 +243,10 @@ describe('ol.geom.Circle', function() {
});
it('returns true for extents that touch the circumference', function() {
var touchCircumferenceLeft = [-2, 0, -1, 1];
var touchCircumferenceTop = [0, 1, 1, 2];
var touchCircumferenceRight = [1, -1, 2, 0];
var touchCircumferenceBottom = [-1, -2, 0, -1];
const touchCircumferenceLeft = [-2, 0, -1, 1];
const touchCircumferenceTop = [0, 1, 1, 2];
const touchCircumferenceRight = [1, -1, 2, 0];
const touchCircumferenceBottom = [-1, -2, 0, -1];
expect(circle.intersectsExtent(touchCircumferenceLeft)).to.be(true);
expect(circle.intersectsExtent(touchCircumferenceTop)).to.be(true);
expect(circle.intersectsExtent(touchCircumferenceRight)).to.be(true);
@@ -254,17 +254,17 @@ describe('ol.geom.Circle', function() {
});
it('returns true for a contained extent', function() {
var containedExtent = [-0.5, -0.5, 0.5, 0.5];
const containedExtent = [-0.5, -0.5, 0.5, 0.5];
expect(circle.intersectsExtent(containedExtent)).to.be(true);
});
it('returns true for a covering extent', function() {
var bigCoveringExtent = [-5, -5, 5, 5];
const bigCoveringExtent = [-5, -5, 5, 5];
expect(circle.intersectsExtent(bigCoveringExtent)).to.be(true);
});
it('returns true for the geom\'s own extent', function() {
var circleExtent = circle.getExtent();
const circleExtent = circle.getExtent();
expect(circle.intersectsExtent(circleExtent)).to.be(true);
});
+4 -4
View File
@@ -5,12 +5,12 @@ describe('ol.geom.flat.area', function() {
describe('ol.geom.flat.area.linearRing', function() {
it('calculates the area of a triangle', function() {
var area = _ol_geom_flat_area_.linearRing([0, 0, 0.5, 1, 1, 0], 0, 6, 2);
const area = _ol_geom_flat_area_.linearRing([0, 0, 0.5, 1, 1, 0], 0, 6, 2);
expect(area).to.be(0.5);
});
it('calculates the area of a unit square', function() {
var area =
const area =
_ol_geom_flat_area_.linearRing([0, 0, 0, 1, 1, 1, 1, 0], 0, 8, 2);
expect(area).to.be(1);
});
@@ -20,8 +20,8 @@ describe('ol.geom.flat.area', function() {
describe('ol.geom.flat.area.linearRings', function() {
it('calculates the area with holes', function() {
var area = _ol_geom_flat_area_.linearRings(
[0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 2, 1, 2, 2, 1, 2], 0, [8, 16], 2);
const area = _ol_geom_flat_area_.linearRings(
[0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 2, 1, 2, 2, 1, 2], 0, [8, 16], 2);
expect(area).to.be(8);
});
+18 -18
View File
@@ -7,20 +7,20 @@ describe('ol.geom.flat.center', function() {
describe('ol.geom.flat.center.linearRingss', function() {
it('calculates the center of a square', function() {
var squareMultiPoly = new MultiPolygon([[
const squareMultiPoly = new MultiPolygon([[
[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]
]]);
var got = _ol_geom_flat_center_.linearRingss(
squareMultiPoly.flatCoordinates,
0,
squareMultiPoly.endss_,
2
const got = _ol_geom_flat_center_.linearRingss(
squareMultiPoly.flatCoordinates,
0,
squareMultiPoly.endss_,
2
);
expect(got).to.eql([0.5, 0.5]);
});
it('calculates the centers of two squares', function() {
var squareMultiPoly = new MultiPolygon([
const squareMultiPoly = new MultiPolygon([
[
[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]
],
@@ -28,25 +28,25 @@ describe('ol.geom.flat.center', function() {
[[3, 0], [3, 1], [4, 1], [4, 0], [3, 0]]
]
]);
var got = _ol_geom_flat_center_.linearRingss(
squareMultiPoly.flatCoordinates,
0,
squareMultiPoly.endss_,
2
const got = _ol_geom_flat_center_.linearRingss(
squareMultiPoly.flatCoordinates,
0,
squareMultiPoly.endss_,
2
);
expect(got).to.eql([0.5, 0.5, 3.5, 0.5]);
});
it('does not care about holes', function() {
var polywithHole = new MultiPolygon([[
const polywithHole = new MultiPolygon([[
[[0, 0], [0, 5], [5, 5], [5, 0], [0, 0]],
[[1, 1], [1, 4], [4, 4], [4, 1], [1, 1]]
]]);
var got = _ol_geom_flat_center_.linearRingss(
polywithHole.flatCoordinates,
0,
polywithHole.endss_,
2
const got = _ol_geom_flat_center_.linearRingss(
polywithHole.flatCoordinates,
0,
polywithHole.endss_,
2
);
expect(got).to.eql([2.5, 2.5]);
});
+36 -36
View File
@@ -5,13 +5,13 @@ describe('ol.geom.flat.closest', function() {
describe('with simple data', function() {
var flatCoordinates = [0, 0, 1, 0, 3, 0, 5, 0, 6, 0, 8, 0, 11, 0];
const flatCoordinates = [0, 0, 1, 0, 3, 0, 5, 0, 6, 0, 8, 0, 11, 0];
describe('ol.geom.flat.closest.getMaxSquaredDelta', function() {
it('returns the expected value in simple cases', function() {
expect(_ol_geom_flat_closest_.getMaxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0)).to.be(9);
flatCoordinates, 0, flatCoordinates.length, 2, 0)).to.be(9);
});
});
@@ -19,25 +19,25 @@ describe('ol.geom.flat.closest', function() {
describe('ol.geom.flat.closest.getClosestPoint', function() {
it('returns the expected value', function() {
var maxDelta = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0));
const maxDelta = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0));
expect(maxDelta).to.be(3);
var closestPoint = [NaN, NaN];
const closestPoint = [NaN, NaN];
expect(_ol_geom_flat_closest_.getClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 0, 0, closestPoint, Infinity)).to.be(0);
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 0, 0, closestPoint, Infinity)).to.be(0);
expect(closestPoint).to.eql([0, 0]);
expect(_ol_geom_flat_closest_.getClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 4, 1, closestPoint, Infinity)).to.be(1);
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 4, 1, closestPoint, Infinity)).to.be(1);
expect(closestPoint).to.eql([4, 0]);
expect(_ol_geom_flat_closest_.getClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 5, 2, closestPoint, Infinity)).to.be(4);
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 5, 2, closestPoint, Infinity)).to.be(4);
expect(closestPoint).to.eql([5, 0]);
expect(_ol_geom_flat_closest_.getClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 10, 100, closestPoint, Infinity)).to.be(10000);
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 10, 100, closestPoint, Infinity)).to.be(10000);
expect(closestPoint).to.eql([10, 0]);
});
@@ -47,7 +47,7 @@ describe('ol.geom.flat.closest', function() {
describe('with real data', 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,
@@ -79,8 +79,8 @@ describe('ol.geom.flat.closest', function() {
it('returns the expected value', function() {
expect(_ol_geom_flat_closest_.getMaxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0)).
to.roughlyEqual(1389.1058, 1e-9);
flatCoordinates, 0, flatCoordinates.length, 2, 0)).
to.roughlyEqual(1389.1058, 1e-9);
});
});
@@ -88,24 +88,24 @@ describe('ol.geom.flat.closest', function() {
describe('ol.geom.flat.closest.getClosestPoint', function() {
it('returns the expected value', function() {
var maxDelta = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0));
const maxDelta = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0));
expect(maxDelta).to.roughlyEqual(Math.sqrt(1389.1058), 1e-9);
var closestPoint = [NaN, NaN];
const closestPoint = [NaN, NaN];
expect(_ol_geom_flat_closest_.getClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 0, 0, closestPoint, Infinity)).
to.roughlyEqual(110902.405, 1e-9);
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 0, 0, closestPoint, Infinity)).
to.roughlyEqual(110902.405, 1e-9);
expect(closestPoint).to.eql([292.41, 159.37]);
expect(_ol_geom_flat_closest_.getClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 500, 500, closestPoint, Infinity)).
to.roughlyEqual(106407.905, 1e-9);
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 500, 500, closestPoint, Infinity)).
to.roughlyEqual(106407.905, 1e-9);
expect(closestPoint).to.eql([671.55, 222.55]);
expect(_ol_geom_flat_closest_.getClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 1000, 500, closestPoint, Infinity)).
to.roughlyEqual(18229.4425, 1e-9);
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 1000, 500, closestPoint, Infinity)).
to.roughlyEqual(18229.4425, 1e-9);
expect(closestPoint).to.eql([866.36, 480.77]);
});
@@ -115,20 +115,20 @@ describe('ol.geom.flat.closest', function() {
describe('with multi-dimensional data', function() {
var flatCoordinates = [0, 0, 10, -10, 2, 2, 30, -20];
var stride = 4;
const flatCoordinates = [0, 0, 10, -10, 2, 2, 30, -20];
const stride = 4;
describe('ol.geom.flat.closest.getClosestPoint', function() {
it('interpolates M coordinates', function() {
var maxDelta = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, stride, 0));
const maxDelta = Math.sqrt(_ol_geom_flat_closest_.getMaxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, stride, 0));
expect(maxDelta).to.roughlyEqual(Math.sqrt(8), 1e-9);
var closestPoint = [NaN, NaN];
const closestPoint = [NaN, NaN];
expect(_ol_geom_flat_closest_.getClosestPoint(
flatCoordinates, 0, flatCoordinates.length, stride,
maxDelta, false, 1, 1, closestPoint, Infinity)).
to.roughlyEqual(0, 1e-9);
flatCoordinates, 0, flatCoordinates.length, stride,
maxDelta, false, 1, 1, closestPoint, Infinity)).
to.roughlyEqual(0, 1e-9);
expect(closestPoint).to.have.length(stride);
expect(closestPoint[0]).to.be(1);
expect(closestPoint[1]).to.be(1);
+7 -7
View File
@@ -5,34 +5,34 @@ describe('ol.geom.flat.contains', function() {
describe('with simple data', function() {
var flatCoordinatesSimple = [0, 0, 1, 0, 1, 1, 0, 1];
var flatCoordinatesNonSimple = [0, 0, 4, 0, 4, 3, 1, 3, 1, 2, 3, 2, 3, 1, 2, 1, 2, 4, 0, 4];
const flatCoordinatesSimple = [0, 0, 1, 0, 1, 1, 0, 1];
const flatCoordinatesNonSimple = [0, 0, 4, 0, 4, 3, 1, 3, 1, 2, 3, 2, 3, 1, 2, 1, 2, 4, 0, 4];
describe('ol.geom.flat.contains.linearRingContainsXY', function() {
it('returns true for point inside a simple polygon', function() {
expect(_ol_geom_flat_contains_.linearRingContainsXY(
flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 0.5, 0.5)).to.be(true);
flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 0.5, 0.5)).to.be(true);
});
it('returns false for point outside a simple polygon', function() {
expect(_ol_geom_flat_contains_.linearRingContainsXY(
flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 1.5, 1.5)).to.be(false);
flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 1.5, 1.5)).to.be(false);
});
it('returns true for point inside a non-simple polygon', function() {
expect(_ol_geom_flat_contains_.linearRingContainsXY(
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1, 1)).to.be(true);
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1, 1)).to.be(true);
});
it('returns true for point inside an overlap of a non-simple polygon', function() {
expect(_ol_geom_flat_contains_.linearRingContainsXY(
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1.5, 2.5)).to.be(true);
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1.5, 2.5)).to.be(true);
});
it('returns false for a point inside a hole of a non-simple polygon', function() {
expect(_ol_geom_flat_contains_.linearRingContainsXY(
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 2.5, 1.5)).to.be(false);
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 2.5, 1.5)).to.be(false);
});
});
+6 -6
View File
@@ -5,14 +5,14 @@ describe('ol.geom.flat.deflate', function() {
describe('ol.geom.flat.deflate.coordinates', function() {
var flatCoordinates;
let flatCoordinates;
beforeEach(function() {
flatCoordinates = [];
});
it('flattens coordinates', function() {
var offset = _ol_geom_flat_deflate_.coordinates(
flatCoordinates, 0, [[1, 2], [3, 4]], 2);
const offset = _ol_geom_flat_deflate_.coordinates(
flatCoordinates, 0, [[1, 2], [3, 4]], 2);
expect(offset).to.be(4);
expect(flatCoordinates).to.eql([1, 2, 3, 4]);
});
@@ -21,14 +21,14 @@ describe('ol.geom.flat.deflate', function() {
describe('ol.geom.flat.deflate.coordinatess', function() {
var flatCoordinates;
let flatCoordinates;
beforeEach(function() {
flatCoordinates = [];
});
it('flattens arrays of coordinates', function() {
var ends = _ol_geom_flat_deflate_.coordinatess(flatCoordinates, 0,
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], 2);
const ends = _ol_geom_flat_deflate_.coordinatess(flatCoordinates, 0,
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], 2);
expect(ends).to.eql([4, 8]);
expect(flatCoordinates).to.eql([1, 2, 3, 4, 5, 6, 7, 8]);
});
+12 -12
View File
@@ -6,31 +6,31 @@ describe('ol.geom.flat.flip', function() {
describe('ol.geom.flat.flip.flipXY', function() {
it('can flip XY coordinates', function() {
var flatCoordinates = _ol_geom_flat_flip_.flipXY([1, 2, 3, 4], 0, 4, 2);
const flatCoordinates = _ol_geom_flat_flip_.flipXY([1, 2, 3, 4], 0, 4, 2);
expect(flatCoordinates).to.eql([2, 1, 4, 3]);
});
it('can flip XY coordinates while preserving other dimensions', function() {
var flatCoordinates = _ol_geom_flat_flip_.flipXY(
[1, 2, 3, 4, 5, 6, 7, 8], 0, 8, 4);
const flatCoordinates = _ol_geom_flat_flip_.flipXY(
[1, 2, 3, 4, 5, 6, 7, 8], 0, 8, 4);
expect(flatCoordinates).to.eql([2, 1, 3, 4, 6, 5, 7, 8]);
});
it('can flip XY coordinates in place', function() {
var flatCoordinates = [1, 2, 3, 4];
const flatCoordinates = [1, 2, 3, 4];
expect(_ol_geom_flat_flip_.flipXY(
flatCoordinates, 0, 4, 2, flatCoordinates)).to.be(flatCoordinates);
flatCoordinates, 0, 4, 2, flatCoordinates)).to.be(flatCoordinates);
expect(flatCoordinates).to.eql([2, 1, 4, 3]);
});
it('can flip XY coordinates in place while preserving other dimensions',
function() {
var flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
expect(_ol_geom_flat_flip_.flipXY(
flatCoordinates, 0, 9, 3, flatCoordinates)).
to.be(flatCoordinates);
expect(flatCoordinates).to.eql([2, 1, 3, 5, 4, 6, 8, 7, 9]);
});
function() {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
expect(_ol_geom_flat_flip_.flipXY(
flatCoordinates, 0, 9, 3, flatCoordinates)).
to.be(flatCoordinates);
expect(flatCoordinates).to.eql([2, 1, 3, 5, 4, 6, 8, 7, 9]);
});
});
+3 -3
View File
@@ -6,7 +6,7 @@ describe('ol.geom.flat.inflate', function() {
describe('ol.geom.flat.inflate.coordinates', function() {
it('inflates coordinates', function() {
var coordinates = _ol_geom_flat_inflate_.coordinates([1, 2, 3, 4], 0, 4, 2);
const coordinates = _ol_geom_flat_inflate_.coordinates([1, 2, 3, 4], 0, 4, 2);
expect(coordinates).to.eql([[1, 2], [3, 4]]);
});
@@ -15,8 +15,8 @@ describe('ol.geom.flat.inflate', function() {
describe('ol.geom.flat.inflate.coordinatess', function() {
it('inflates arrays of coordinates', function() {
var coordinatess = _ol_geom_flat_inflate_.coordinatess(
[1, 2, 3, 4, 5, 6, 7, 8], 0, [4, 8], 2);
const coordinatess = _ol_geom_flat_inflate_.coordinatess(
[1, 2, 3, 4, 5, 6, 7, 8], 0, [4, 8], 2);
expect(coordinatess).to.eql([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
});
+34 -34
View File
@@ -6,15 +6,15 @@ describe('ol.geom.flat.interpolate', function() {
describe('ol.geom.flat.interpolate.lineString', function() {
it('returns the expected value for single points', function() {
var flatCoordinates = [0, 1];
var point =
const flatCoordinates = [0, 1];
const point =
_ol_geom_flat_interpolate_.lineString(flatCoordinates, 0, 2, 2, 0.5);
expect(point).to.eql([0, 1]);
});
it('returns the expected value for simple line segments', function() {
var flatCoordinates = [0, 1, 2, 3];
var point =
const flatCoordinates = [0, 1, 2, 3];
const point =
_ol_geom_flat_interpolate_.lineString(flatCoordinates, 0, 4, 2, 0.5);
expect(point).to.eql([1, 2]);
});
@@ -22,58 +22,58 @@ describe('ol.geom.flat.interpolate', function() {
it('returns the expected value when the mid point is an existing ' +
'coordinate',
function() {
var flatCoordinates = [0, 1, 2, 3, 4, 5];
var point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 6, 2, 0.5);
const flatCoordinates = [0, 1, 2, 3, 4, 5];
const point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([2, 3]);
});
xit('also when vertices are repeated', function() {
var flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5];
var point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 6, 2, 0.5);
const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5];
const point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([2, 3]);
});
it('returns the expected value when the midpoint falls halfway between ' +
'two existing coordinates',
function() {
var flatCoordinates = [0, 1, 2, 3, 4, 5, 6, 7];
var point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 8, 2, 0.5);
const flatCoordinates = [0, 1, 2, 3, 4, 5, 6, 7];
const point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 8, 2, 0.5);
expect(point).to.eql([3, 4]);
});
xit('also when vertices are repeated', function() {
var flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5, 6, 7];
var point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 8, 2, 0.5);
const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5, 6, 7];
const point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 8, 2, 0.5);
expect(point).to.eql([3, 4]);
});
it('returns the expected value when the coordinates are not evenly spaced',
function() {
var flatCoordinates = [0, 1, 2, 3, 6, 7];
var point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([3, 4]);
});
function() {
const flatCoordinates = [0, 1, 2, 3, 6, 7];
const point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([3, 4]);
});
xit('also when vertices are repeated',
function() {
var flatCoordinates = [0, 1, 2, 3, 2, 3, 6, 7];
var point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([3, 4]);
});
function() {
const flatCoordinates = [0, 1, 2, 3, 2, 3, 6, 7];
const point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([3, 4]);
});
it('returns the expected value when using opt_dest',
function() {
var flatCoordinates = [0, 1, 2, 3, 6, 7];
var point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 6, 2, 0.5, [0, 0]);
expect(point).to.eql([3, 4]);
});
function() {
const flatCoordinates = [0, 1, 2, 3, 6, 7];
const point = _ol_geom_flat_interpolate_.lineString(
flatCoordinates, 0, 6, 2, 0.5, [0, 0]);
expect(point).to.eql([3, 4]);
});
});
+33 -33
View File
@@ -4,69 +4,69 @@ import _ol_geom_flat_intersectsextent_ from '../../../../../src/ol/geom/flat/int
describe('ol.geom.flat.intersectsextent', function() {
describe('ol.geom.flat.intersectsextent.lineString', function() {
var flatCoordinates;
let flatCoordinates;
beforeEach(function() {
flatCoordinates = [0, 0, 1, 1, 2, 2];
});
describe('linestring envelope does not intersect the extent', function() {
it('returns false', function() {
var extent = [3, 3, 4, 4];
var r = _ol_geom_flat_intersectsextent_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
const extent = [3, 3, 4, 4];
const r = _ol_geom_flat_intersectsextent_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(false);
});
});
describe('linestring envelope within the extent', function() {
it('returns true', function() {
var extent = [-1, -1, 3, 3];
var r = _ol_geom_flat_intersectsextent_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
const extent = [-1, -1, 3, 3];
const r = _ol_geom_flat_intersectsextent_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(true);
});
});
describe('linestring envelope bisected by an edge of the extent',
function() {
it('returns true', function() {
var extent = [-0.1, 0.1, 2.1, 0.1];
var r = _ol_geom_flat_intersectsextent_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(true);
});
function() {
it('returns true', function() {
const extent = [-0.1, 0.1, 2.1, 0.1];
const r = _ol_geom_flat_intersectsextent_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(true);
});
});
describe('a segment intersects the extent', function() {
it('returns true', function() {
var extent = [-0.5, -0.5, 0.5, 0.5];
var r = _ol_geom_flat_intersectsextent_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
const extent = [-0.5, -0.5, 0.5, 0.5];
const r = _ol_geom_flat_intersectsextent_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(true);
});
});
describe('no segments intersect the extent', function() {
it('returns false', function() {
var extent = [0.5, 1.5, 1, 1.75];
var r = _ol_geom_flat_intersectsextent_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
const extent = [0.5, 1.5, 1, 1.75];
const r = _ol_geom_flat_intersectsextent_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(false);
});
it('returns false', function() {
var extent = [1, 0.25, 1.5, 0.5];
var r = _ol_geom_flat_intersectsextent_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
const extent = [1, 0.25, 1.5, 0.5];
const r = _ol_geom_flat_intersectsextent_.lineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(false);
});
});
});
describe('ol.geom.flat.intersectsextent.linearRing', function() {
var flatCoordinates;
let flatCoordinates;
beforeEach(function() {
flatCoordinates = [0, 0, 1, 1, 2, 0, 1, -1, 0, 0];
});
describe('boundary intersects the extent', function() {
it('returns true', function() {
var extent = [1.5, 0.0, 2.5, 1.0];
var r = _ol_geom_flat_intersectsextent_.linearRing(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
const extent = [1.5, 0.0, 2.5, 1.0];
const r = _ol_geom_flat_intersectsextent_.linearRing(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(true);
});
});
@@ -74,17 +74,17 @@ describe('ol.geom.flat.intersectsextent', function() {
'contain a corner of the extent',
function() {
it('returns false', function() {
var extent = [2.0, 0.5, 3, 1.5];
var r = _ol_geom_flat_intersectsextent_.linearRing(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
const extent = [2.0, 0.5, 3, 1.5];
const r = _ol_geom_flat_intersectsextent_.linearRing(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(false);
});
});
describe('ring contains the extent', function() {
it('returns true', function() {
var extent = [0.75, -0.25, 1.25, 0.25];
var r = _ol_geom_flat_intersectsextent_.linearRing(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
const extent = [0.75, -0.25, 1.25, 0.25];
const r = _ol_geom_flat_intersectsextent_.linearRing(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(true);
});
});
+40 -40
View File
@@ -6,60 +6,60 @@ describe('ol.geom.flat.length', function() {
describe('ol.geom.flat.length.lineString', function() {
describe('stride = 2', function() {
var flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
var stride = 2;
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
const stride = 2;
it('calculates the total length of a lineString', function() {
var offset = 0;
var end = 8;
var expected = 3;
var got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
const offset = 0;
const end = 8;
const expected = 3;
const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
it('calculates a partwise length of a lineString (offset)', function() {
var offset = 2;
var end = 8;
var expected = 2;
var got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
const offset = 2;
const end = 8;
const expected = 2;
const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
it('calculates a partwise length of a lineString (end)', function() {
var offset = 0;
var end = 4;
var expected = 1;
var got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
const offset = 0;
const end = 4;
const expected = 1;
const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
});
describe('stride = 3', function() {
var flatCoords = [0, 0, 42, 1, 0, 42, 1, 1, 42, 0, 1, 42];
var stride = 3;
const flatCoords = [0, 0, 42, 1, 0, 42, 1, 1, 42, 0, 1, 42];
const stride = 3;
it('calculates the total length of a lineString', function() {
var offset = 0;
var end = 12;
var expected = 3;
var got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
const offset = 0;
const end = 12;
const expected = 3;
const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
it('calculates a partwise length of a lineString (offset)', function() {
var offset = 3;
var end = 12;
var expected = 2;
var got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
const offset = 3;
const end = 12;
const expected = 2;
const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
it('calculates a partwise length of a lineString (end)', function() {
var offset = 0;
var end = 6;
var expected = 1;
var got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
const offset = 0;
const end = 6;
const expected = 1;
const got = _ol_geom_flat_length_.lineString(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
@@ -69,22 +69,22 @@ describe('ol.geom.flat.length', function() {
describe('ol.geom.flat.length.linearRing', function() {
it('calculates the total length of a simple linearRing', function() {
var flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
var stride = 2;
var offset = 0;
var end = 8;
var expected = 4;
var got = _ol_geom_flat_length_.linearRing(flatCoords, offset, end, stride);
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
const stride = 2;
const offset = 0;
const end = 8;
const expected = 4;
const got = _ol_geom_flat_length_.linearRing(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
it('calculates the total length of a figure-8 linearRing', function() {
var flatCoords = [0, 0, 1, 0, 1, 1, 0, 1, 0, -1, -1, -1, -1, 0];
var stride = 2;
var offset = 0;
var end = 14;
var expected = 8;
var got = _ol_geom_flat_length_.linearRing(flatCoords, offset, end, stride);
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1, 0, -1, -1, -1, -1, 0];
const stride = 2;
const offset = 0;
const end = 14;
const expected = 8;
const got = _ol_geom_flat_length_.linearRing(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
+30 -30
View File
@@ -6,35 +6,35 @@ describe('ol.geom.flat.orient', function() {
describe('ol.geom.flat.orient.linearRingIsClockwise()', function() {
it('identifies clockwise rings', function() {
var flatCoordinates = [0, 1, 1, 4, 4, 3, 3, 0];
var isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
flatCoordinates, 0, flatCoordinates.length, 2);
const flatCoordinates = [0, 1, 1, 4, 4, 3, 3, 0];
const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
flatCoordinates, 0, flatCoordinates.length, 2);
expect(isClockwise).to.be(true);
});
it('identifies anti-clockwise rings', function() {
var flatCoordinates = [2, 2, 3, 2, 3, 3, 2, 3];
var isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
flatCoordinates, 0, flatCoordinates.length, 2);
const flatCoordinates = [2, 2, 3, 2, 3, 3, 2, 3];
const isClockwise = _ol_geom_flat_orient_.linearRingIsClockwise(
flatCoordinates, 0, flatCoordinates.length, 2);
expect(isClockwise).to.be(false);
});
});
describe('ol.geom.flat.orient.linearRingsAreOriented()', function() {
var oriented = _ol_geom_flat_orient_.linearRingsAreOriented;
const oriented = _ol_geom_flat_orient_.linearRingsAreOriented;
var rightCoords = [
const rightCoords = [
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
-100, -45, -100, 45, 100, 45, 100, -45, -100, -45
];
var leftCoords = [
const leftCoords = [
-180, -90, -180, 90, 180, 90, 180, -90, -180, -90,
-100, -45, 100, -45, 100, 45, -100, 45, -100, -45
];
var ends = [10, 20];
const ends = [10, 20];
it('checks for left-hand orientation by default', function() {
expect(oriented(rightCoords, 0, ends, 2)).to.be(false);
@@ -49,23 +49,23 @@ describe('ol.geom.flat.orient', function() {
});
describe('ol.geom.flat.orient.linearRingssAreOriented()', function() {
var oriented = _ol_geom_flat_orient_.linearRingssAreOriented;
const oriented = _ol_geom_flat_orient_.linearRingssAreOriented;
var rightCoords = [
const rightCoords = [
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
-100, -45, -100, 45, 100, 45, 100, -45, -100, -45,
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
-100, -45, -100, 45, 100, 45, 100, -45, -100, -45
];
var leftCoords = [
const leftCoords = [
-180, -90, -180, 90, 180, 90, 180, -90, -180, -90,
-100, -45, 100, -45, 100, 45, -100, 45, -100, -45,
-180, -90, -180, 90, 180, 90, 180, -90, -180, -90,
-100, -45, 100, -45, 100, 45, -100, 45, -100, -45
];
var ends = [[10, 20], [30, 40]];
const ends = [[10, 20], [30, 40]];
it('checks for left-hand orientation by default', function() {
expect(oriented(rightCoords, 0, ends, 2)).to.be(false);
@@ -80,36 +80,36 @@ describe('ol.geom.flat.orient', function() {
});
describe('ol.geom.flat.orient.orientLinearRings()', function() {
var orient = _ol_geom_flat_orient_.orientLinearRings;
const orient = _ol_geom_flat_orient_.orientLinearRings;
var rightCoords = [
const rightCoords = [
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
-100, -45, -100, 45, 100, 45, 100, -45, -100, -45
];
var leftCoords = [
const leftCoords = [
-180, -90, -180, 90, 180, 90, 180, -90, -180, -90,
-100, -45, 100, -45, 100, 45, -100, 45, -100, -45
];
var ends = [10, 20];
const ends = [10, 20];
it('orients using the left-hand rule by default', function() {
var rightClone = rightCoords.slice();
const rightClone = rightCoords.slice();
orient(rightClone, 0, ends, 2);
expect(rightClone).to.eql(leftCoords);
var leftClone = leftCoords.slice();
const leftClone = leftCoords.slice();
orient(leftClone, 0, ends, 2);
expect(leftClone).to.eql(leftCoords);
});
it('can orient using the right-hand rule', function() {
var rightClone = rightCoords.slice();
const rightClone = rightCoords.slice();
orient(rightClone, 0, ends, 2, true);
expect(rightClone).to.eql(rightCoords);
var leftClone = leftCoords.slice();
const leftClone = leftCoords.slice();
orient(leftClone, 0, ends, 2, true);
expect(leftClone).to.eql(rightCoords);
});
@@ -117,40 +117,40 @@ describe('ol.geom.flat.orient', function() {
});
describe('ol.geom.flat.orient.orientLinearRingss()', function() {
var orient = _ol_geom_flat_orient_.orientLinearRingss;
const orient = _ol_geom_flat_orient_.orientLinearRingss;
var rightCoords = [
const rightCoords = [
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
-100, -45, -100, 45, 100, 45, 100, -45, -100, -45,
-180, -90, 180, -90, 180, 90, -180, 90, -180, -90,
-100, -45, -100, 45, 100, 45, 100, -45, -100, -45
];
var leftCoords = [
const leftCoords = [
-180, -90, -180, 90, 180, 90, 180, -90, -180, -90,
-100, -45, 100, -45, 100, 45, -100, 45, -100, -45,
-180, -90, -180, 90, 180, 90, 180, -90, -180, -90,
-100, -45, 100, -45, 100, 45, -100, 45, -100, -45
];
var ends = [[10, 20], [30, 40]];
const ends = [[10, 20], [30, 40]];
it('orients using the left-hand rule by default', function() {
var rightClone = rightCoords.slice();
const rightClone = rightCoords.slice();
orient(rightClone, 0, ends, 2);
expect(rightClone).to.eql(leftCoords);
var leftClone = leftCoords.slice();
const leftClone = leftCoords.slice();
orient(leftClone, 0, ends, 2);
expect(leftClone).to.eql(leftCoords);
});
it('can orient using the right-hand rule', function() {
var rightClone = rightCoords.slice();
const rightClone = rightCoords.slice();
orient(rightClone, 0, ends, 2, true);
expect(rightClone).to.eql(rightCoords);
var leftClone = leftCoords.slice();
const leftClone = leftCoords.slice();
orient(leftClone, 0, ends, 2, true);
expect(leftClone).to.eql(rightCoords);
});
+31 -31
View File
@@ -8,37 +8,37 @@ describe('ol.geom.flat.reverse', function() {
describe('with a stride of 2', function() {
it('can reverse empty flat coordinates', function() {
var flatCoordinates = [];
const flatCoordinates = [];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.be.empty();
});
it('can reverse one flat coordinates', function() {
var flatCoordinates = [1, 2];
const flatCoordinates = [1, 2];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([1, 2]);
});
it('can reverse two flat coordinates', function() {
var flatCoordinates = [1, 2, 3, 4];
const flatCoordinates = [1, 2, 3, 4];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([3, 4, 1, 2]);
});
it('can reverse three flat coordinates', function() {
var flatCoordinates = [1, 2, 3, 4, 5, 6];
const flatCoordinates = [1, 2, 3, 4, 5, 6];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([5, 6, 3, 4, 1, 2]);
});
it('can reverse four flat coordinates', function() {
var flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8];
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([7, 8, 5, 6, 3, 4, 1, 2]);
});
@@ -47,37 +47,37 @@ describe('ol.geom.flat.reverse', function() {
describe('with a stride of 3', function() {
it('can reverse empty flat coordinates', function() {
var flatCoordinates = [];
const flatCoordinates = [];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 3);
flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.be.empty();
});
it('can reverse one flat coordinates', function() {
var flatCoordinates = [1, 2, 3];
const flatCoordinates = [1, 2, 3];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 3);
flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([1, 2, 3]);
});
it('can reverse two flat coordinates', function() {
var flatCoordinates = [1, 2, 3, 4, 5, 6];
const flatCoordinates = [1, 2, 3, 4, 5, 6];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 3);
flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([4, 5, 6, 1, 2, 3]);
});
it('can reverse three flat coordinates', function() {
var flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 3);
flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([7, 8, 9, 4, 5, 6, 1, 2, 3]);
});
it('can reverse four flat coordinates', function() {
var flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 3);
flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([10, 11, 12, 7, 8, 9, 4, 5, 6, 1, 2, 3]);
});
@@ -86,40 +86,40 @@ describe('ol.geom.flat.reverse', function() {
describe('with a stride of 4', function() {
it('can reverse empty flat coordinates', function() {
var flatCoordinates = [];
const flatCoordinates = [];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 4);
flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.be.empty();
});
it('can reverse one flat coordinates', function() {
var flatCoordinates = [1, 2, 3, 4];
const flatCoordinates = [1, 2, 3, 4];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 4);
flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql([1, 2, 3, 4]);
});
it('can reverse two flat coordinates', function() {
var flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8];
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 4);
flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql([5, 6, 7, 8, 1, 2, 3, 4]);
});
it('can reverse three flat coordinates', function() {
var flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 4);
flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql([9, 10, 11, 12, 5, 6, 7, 8, 1, 2, 3, 4]);
});
it('can reverse four flat coordinates', function() {
var flatCoordinates =
const flatCoordinates =
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
_ol_geom_flat_reverse_.coordinates(
flatCoordinates, 0, flatCoordinates.length, 4);
flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql(
[13, 14, 15, 16, 9, 10, 11, 12, 5, 6, 7, 8, 1, 2, 3, 4]);
[13, 14, 15, 16, 9, 10, 11, 12, 5, 6, 7, 8, 1, 2, 3, 4]);
});
});
+9 -9
View File
@@ -4,7 +4,7 @@ import _ol_geom_flat_segments_ from '../../../../../src/ol/geom/flat/segments.js
describe('ol.geom.flat.segments', function() {
describe('ol.geom.flat.segments.forEach', function() {
var flatCoordinates, offset, end, stride;
let flatCoordinates, offset, end, stride;
beforeEach(function() {
flatCoordinates = [0, 0, 1, 1, 2, 2, 3, 3];
offset = 0;
@@ -13,12 +13,12 @@ describe('ol.geom.flat.segments', function() {
});
describe('callback returns undefined', function() {
it('executes the callback for each segment', function() {
var args = [];
var spy = sinon.spy(function(point1, point2) {
const args = [];
const spy = sinon.spy(function(point1, point2) {
args.push([point1[0], point1[1], point2[0], point2[1]]);
});
var ret = _ol_geom_flat_segments_.forEach(
flatCoordinates, offset, end, stride, spy);
const ret = _ol_geom_flat_segments_.forEach(
flatCoordinates, offset, end, stride, spy);
expect(spy.callCount).to.be(3);
expect(args[0][0]).to.be(0);
expect(args[0][1]).to.be(0);
@@ -37,13 +37,13 @@ describe('ol.geom.flat.segments', function() {
});
describe('callback returns true', function() {
it('executes the callback for the first segment', function() {
var args = [];
var spy = sinon.spy(function(point1, point2) {
const args = [];
const spy = sinon.spy(function(point1, point2) {
args.push([point1[0], point1[1], point2[0], point2[1]]);
return true;
});
var ret = _ol_geom_flat_segments_.forEach(
flatCoordinates, offset, end, stride, spy);
const ret = _ol_geom_flat_segments_.forEach(
flatCoordinates, offset, end, stride, spy);
expect(spy.callCount).to.be(1);
expect(args[0][0]).to.be(0);
expect(args[0][1]).to.be(0);
+66 -66
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]);
});
+12 -12
View File
@@ -6,48 +6,48 @@ describe('ol.geom.flat.straightchunk', function() {
describe('ol.geom.flat.straightchunk.lineString', function() {
describe('single segment with stride == 3', function() {
var flatCoords = [0, 0, 42, 1, 1, 42];
var stride = 3;
const flatCoords = [0, 0, 42, 1, 1, 42];
const stride = 3;
it('returns whole line with angle delta', function() {
var got = _ol_geom_flat_straightchunk_.lineString(Math.PI / 4, flatCoords, 0, 6, stride);
const got = _ol_geom_flat_straightchunk_.lineString(Math.PI / 4, flatCoords, 0, 6, stride);
expect(got).to.eql([0, 6]);
});
it('returns whole line with zero angle delta', function() {
var got = _ol_geom_flat_straightchunk_.lineString(0, flatCoords, 0, 6, stride);
const got = _ol_geom_flat_straightchunk_.lineString(0, flatCoords, 0, 6, stride);
expect(got).to.eql([0, 6]);
});
});
describe('short line string', function() {
var flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
var stride = 2;
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
const stride = 2;
it('returns whole line if straight enough', function() {
var got = _ol_geom_flat_straightchunk_.lineString(Math.PI, flatCoords, 0, 8, stride);
const got = _ol_geom_flat_straightchunk_.lineString(Math.PI, flatCoords, 0, 8, stride);
expect(got).to.eql([0, 8]);
});
it('returns first matching chunk if all chunk lengths are the same', function() {
var got = _ol_geom_flat_straightchunk_.lineString(Math.PI / 4, flatCoords, 0, 8, stride);
const got = _ol_geom_flat_straightchunk_.lineString(Math.PI / 4, flatCoords, 0, 8, stride);
expect(got).to.eql([0, 4]);
});
});
describe('longer line string', function() {
var flatCoords = [0, 0, 1, 0, 1, 1, 0, 1, 0, -1, -1, -1, -1, 0, -1, 2, -2, 4];
var stride = 2;
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1, 0, -1, -1, -1, -1, 0, -1, 2, -2, 4];
const stride = 2;
it('returns stright chunk from within the linestring', function() {
var got = _ol_geom_flat_straightchunk_.lineString(0, flatCoords, 0, 18, stride);
const got = _ol_geom_flat_straightchunk_.lineString(0, flatCoords, 0, 18, stride);
expect(got).to.eql([10, 16]);
});
it('returns long chunk at the end if angle and length within threshold', function() {
var got = _ol_geom_flat_straightchunk_.lineString(Math.PI / 4, flatCoords, 0, 18, stride);
const got = _ol_geom_flat_straightchunk_.lineString(Math.PI / 4, flatCoords, 0, 18, stride);
expect(got).to.eql([10, 18]);
});
+47 -47
View File
@@ -3,74 +3,74 @@ import _ol_geom_flat_length_ from '../../../../../src/ol/geom/flat/length.js';
describe('textpath', function() {
var horizontal = [0, 0, 100, 0];
var vertical = [0, 0, 0, 100];
var diagonal = [0, 0, 100, 100];
var reverse = [100, 0, 0, 100];
var angled = [0, 0, 100, 100, 200, 0];
var reverseangled = [151, 17, 163, 22, 159, 30, 150, 30, 143, 24, 151, 17];
const horizontal = [0, 0, 100, 0];
const vertical = [0, 0, 0, 100];
const diagonal = [0, 0, 100, 100];
const reverse = [100, 0, 0, 100];
const angled = [0, 0, 100, 100, 200, 0];
const reverseangled = [151, 17, 163, 22, 159, 30, 150, 30, 143, 24, 151, 17];
function measure(text) {
return 10 * text.length;
}
it('center-aligns text on a horizontal line', function() {
var startM = 50 - 15;
var instructions = _ol_geom_flat_textpath_.lineString(
horizontal, 0, horizontal.length, 2, 'foo', measure, startM, Infinity);
const startM = 50 - 15;
const instructions = _ol_geom_flat_textpath_.lineString(
horizontal, 0, horizontal.length, 2, 'foo', measure, startM, Infinity);
expect(instructions).to.eql([[40, 0, 5, 0, 'foo']]);
});
it('left-aligns text on a horizontal line', function() {
var instructions = _ol_geom_flat_textpath_.lineString(
horizontal, 0, horizontal.length, 2, 'foo', measure, 0, Infinity);
const instructions = _ol_geom_flat_textpath_.lineString(
horizontal, 0, horizontal.length, 2, 'foo', measure, 0, Infinity);
expect(instructions).to.eql([[5, 0, 5, 0, 'foo']]);
});
it('right-aligns text on a horizontal line', function() {
var startM = 100 - 30;
var instructions = _ol_geom_flat_textpath_.lineString(
horizontal, 0, horizontal.length, 2, 'foo', measure, startM, Infinity);
const startM = 100 - 30;
const instructions = _ol_geom_flat_textpath_.lineString(
horizontal, 0, horizontal.length, 2, 'foo', measure, startM, Infinity);
expect(instructions).to.eql([[75, 0, 5, 0, 'foo']]);
});
it('draws text on a vertical line', function() {
var startM = 50 - 15;
var instructions = _ol_geom_flat_textpath_.lineString(
vertical, 0, vertical.length, 2, 'foo', measure, startM, Infinity);
var a = 90 * Math.PI / 180;
const startM = 50 - 15;
const instructions = _ol_geom_flat_textpath_.lineString(
vertical, 0, vertical.length, 2, 'foo', measure, startM, Infinity);
const a = 90 * Math.PI / 180;
expect(instructions).to.eql([[0, 40, 5, a, 'foo']]);
});
it('draws text on a diagonal line', function() {
var startM = Math.sqrt(2) * 50 - 15;
var instructions = _ol_geom_flat_textpath_.lineString(
diagonal, 0, diagonal.length, 2, 'foo', measure, startM, Infinity);
const startM = Math.sqrt(2) * 50 - 15;
const instructions = _ol_geom_flat_textpath_.lineString(
diagonal, 0, diagonal.length, 2, 'foo', measure, startM, Infinity);
expect(instructions[0][3]).to.be(45 * Math.PI / 180);
expect(instructions.length).to.be(1);
});
it('draws reverse text on a diagonal line', function() {
var startM = Math.sqrt(2) * 50 - 15;
var instructions = _ol_geom_flat_textpath_.lineString(
reverse, 0, reverse.length, 2, 'foo', measure, startM, Infinity);
const startM = Math.sqrt(2) * 50 - 15;
const instructions = _ol_geom_flat_textpath_.lineString(
reverse, 0, reverse.length, 2, 'foo', measure, startM, Infinity);
expect(instructions[0][3]).to.be(-45 * Math.PI / 180);
expect(instructions.length).to.be(1);
});
it('renders long text with extrapolation', function() {
var startM = 50 - 75;
var instructions = _ol_geom_flat_textpath_.lineString(
horizontal, 0, horizontal.length, 2, 'foo-foo-foo-foo', measure, startM, Infinity);
const startM = 50 - 75;
const instructions = _ol_geom_flat_textpath_.lineString(
horizontal, 0, horizontal.length, 2, 'foo-foo-foo-foo', measure, startM, Infinity);
expect(instructions[0]).to.eql([-20, 0, 5, 0, 'foo-foo-foo-foo']);
expect(instructions.length).to.be(1);
});
it('renders angled text', function() {
var length = _ol_geom_flat_length_.lineString(angled, 0, angled.length, 2);
var startM = length / 2 - 15;
var instructions = _ol_geom_flat_textpath_.lineString(
angled, 0, angled.length, 2, 'foo', measure, startM, Infinity);
const length = _ol_geom_flat_length_.lineString(angled, 0, angled.length, 2);
const startM = length / 2 - 15;
const instructions = _ol_geom_flat_textpath_.lineString(
angled, 0, angled.length, 2, 'foo', measure, startM, Infinity);
expect(instructions[0][3]).to.eql(45 * Math.PI / 180);
expect(instructions[0][4]).to.be('fo');
expect(instructions[1][3]).to.eql(-45 * Math.PI / 180);
@@ -78,35 +78,35 @@ describe('textpath', function() {
});
it('respects maxAngle', function() {
var length = _ol_geom_flat_length_.lineString(angled, 0, angled.length, 2);
var startM = length / 2 - 15;
var instructions = _ol_geom_flat_textpath_.lineString(
angled, 0, angled.length, 2, 'foo', measure, startM, Math.PI / 4);
const length = _ol_geom_flat_length_.lineString(angled, 0, angled.length, 2);
const startM = length / 2 - 15;
const instructions = _ol_geom_flat_textpath_.lineString(
angled, 0, angled.length, 2, 'foo', measure, startM, Math.PI / 4);
expect(instructions).to.be(null);
});
it('uses the smallest angle for maxAngleDelta', function() {
var length = _ol_geom_flat_length_.lineString(reverseangled, 0, reverseangled.length, 2);
var startM = length / 2 - 15;
var instructions = _ol_geom_flat_textpath_.lineString(
reverseangled, 0, reverseangled.length, 2, 'foo', measure, startM, Math.PI);
const length = _ol_geom_flat_length_.lineString(reverseangled, 0, reverseangled.length, 2);
const startM = length / 2 - 15;
const instructions = _ol_geom_flat_textpath_.lineString(
reverseangled, 0, reverseangled.length, 2, 'foo', measure, startM, Math.PI);
expect(instructions).to.not.be(undefined);
});
it('respects the offset option', function() {
var length = _ol_geom_flat_length_.lineString(angled, 2, angled.length, 2);
var startM = length / 2 - 15;
var instructions = _ol_geom_flat_textpath_.lineString(
angled, 2, angled.length, 2, 'foo', measure, startM, Infinity);
const length = _ol_geom_flat_length_.lineString(angled, 2, angled.length, 2);
const startM = length / 2 - 15;
const instructions = _ol_geom_flat_textpath_.lineString(
angled, 2, angled.length, 2, 'foo', measure, startM, Infinity);
expect(instructions[0][3]).to.be(-45 * Math.PI / 180);
expect(instructions.length).to.be(1);
});
it('respects the end option', function() {
var length = _ol_geom_flat_length_.lineString(angled, 0, 4, 2);
var startM = length / 2 - 15;
var instructions = _ol_geom_flat_textpath_.lineString(
angled, 0, 4, 2, 'foo', measure, startM, Infinity);
const length = _ol_geom_flat_length_.lineString(angled, 0, 4, 2);
const startM = length / 2 - 15;
const instructions = _ol_geom_flat_textpath_.lineString(
angled, 0, 4, 2, 'foo', measure, startM, Infinity);
expect(instructions[0][3]).to.be(45 * Math.PI / 180);
expect(instructions.length).to.be(1);
});
@@ -5,20 +5,20 @@ describe('ol.geom.flat.topology', function() {
describe('ol.geom.flat.topology.lineStringIsClosed', function() {
it('identifies closed lines aka boundaries', function() {
var flatCoordinates = [0, 0, 3, 0, 0, 3, 0, 0];
var isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
const flatCoordinates = [0, 0, 3, 0, 0, 3, 0, 0];
const isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
expect(isClosed).to.be(true);
});
it('identifies regular linestrings', function() {
var flatCoordinates = [0, 0, 3, 0, 0, 3, 5, 2];
var isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
const flatCoordinates = [0, 0, 3, 0, 0, 3, 5, 2];
const isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
expect(isClosed).to.be(false);
});
it('identifies degenerate boundaries', function() {
var flatCoordinates = [0, 0, 3, 0, 0, 0];
var isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
let flatCoordinates = [0, 0, 3, 0, 0, 0];
let isClosed = _ol_geom_flat_topology_.lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
expect(isClosed).to.be(false);
flatCoordinates = [0, 0, 1, 1, 3, 3, 5, 5, 0, 0];
+16 -16
View File
@@ -9,7 +9,7 @@ describe('ol.geom.flat.transform', function() {
it('transforms a Simple Geometry to 2D', function() {
var multiPolygonGeometry = new MultiPolygon([
const multiPolygonGeometry = new MultiPolygon([
[[[-80.736061, 28.788576000000006, 0],
[-80.763557, 28.821799999999996, 0],
[-80.817406, 28.895123999999996, 0],
@@ -26,13 +26,13 @@ describe('ol.geom.flat.transform', function() {
[-82.128838, 26.693342, 0],
[-82.102127, 26.585724, 0]]]
]).transform('EPSG:4326', 'EPSG:3857');
var transform = [
const transform = [
0.0004088332670837288, 0,
0, -0.0004088332670837288,
4480.991370439071, 1529.5752568707105
];
var pixelCoordinates = SimpleGeometry.transform2D(
multiPolygonGeometry, transform, []);
const pixelCoordinates = SimpleGeometry.transform2D(
multiPolygonGeometry, transform, []);
expect(pixelCoordinates[0]).to.roughlyEqual(806.6035275946265, 1e-9);
expect(pixelCoordinates[1]).to.roughlyEqual(160.48916296287916, 1e-9);
expect(pixelCoordinates[2]).to.roughlyEqual(805.3521540835154, 1e-9);
@@ -69,15 +69,15 @@ describe('ol.geom.flat.transform', function() {
describe('ol.geom.flat.transform.translate', function() {
it('translates the coordinates array', function() {
var multiPolygon = new MultiPolygon([
const multiPolygon = new MultiPolygon([
[[[0, 0, 2], [0, 1, 2], [1, 1, 2], [1, 0, 2], [0, 0, 2]]],
[[[2, 2, 3], [2, 3, 3], [3, 3, 3], [3, 2, 3], [2, 2, 3]]]]);
var flatCoordinates = multiPolygon.getFlatCoordinates();
var deltaX = 1;
var deltaY = 2;
const flatCoordinates = multiPolygon.getFlatCoordinates();
const deltaX = 1;
const deltaY = 2;
_ol_geom_flat_transform_.translate(flatCoordinates, 0,
flatCoordinates.length, multiPolygon.getStride(),
deltaX, deltaY, flatCoordinates);
flatCoordinates.length, multiPolygon.getStride(),
deltaX, deltaY, flatCoordinates);
expect(flatCoordinates).to.eql([
1, 2, 2, 1, 3, 2, 2, 3, 2, 2, 2, 2, 1, 2, 2,
3, 4, 3, 3, 5, 3, 4, 5, 3, 4, 4, 3, 3, 4, 3]);
@@ -86,15 +86,15 @@ describe('ol.geom.flat.transform', function() {
describe('ol.geom.flat.transform.rotate', function() {
it('rotates the coordinates array', function() {
var multiPolygon = new MultiPolygon([
const multiPolygon = new MultiPolygon([
[[[0, 0, 2], [0, 1, 2], [1, 1, 2], [1, 0, 2], [0, 0, 2]]],
[[[2, 2, 3], [2, 3, 3], [3, 3, 3], [3, 2, 3], [2, 2, 3]]]]);
var flatCoordinates = multiPolygon.getFlatCoordinates();
var angle = Math.PI / 2;
var anchor = [0, 1];
const flatCoordinates = multiPolygon.getFlatCoordinates();
const angle = Math.PI / 2;
const anchor = [0, 1];
_ol_geom_flat_transform_.rotate(flatCoordinates, 0,
flatCoordinates.length, multiPolygon.getStride(),
angle, anchor, flatCoordinates);
flatCoordinates.length, multiPolygon.getStride(),
angle, anchor, flatCoordinates);
expect(flatCoordinates[0]).to.roughlyEqual(1, 1e-9);
expect(flatCoordinates[1]).to.roughlyEqual(1, 1e-9);
expect(flatCoordinates[2]).to.roughlyEqual(2, 1e-9);
+45 -45
View File
@@ -6,13 +6,13 @@ import Polygon from '../../../../src/ol/geom/Polygon.js';
describe('ol.geom.GeometryCollection', function() {
var outer = [[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]];
var inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]];
var inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
const outer = [[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]];
const inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]];
const inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
describe('constructor', function() {
var line, multi, point, poly;
let line, multi, point, poly;
beforeEach(function() {
point = new Point([10, 20]);
line = new LineString([[10, 20], [30, 40]]);
@@ -26,12 +26,12 @@ describe('ol.geom.GeometryCollection', function() {
});
it('fires a change event when one of its component changes',
function(done) {
multi.on('change', function() {
done();
});
point.setCoordinates([10, 10]);
}
function(done) {
multi.on('change', function() {
done();
});
point.setCoordinates([10, 10]);
}
);
it('deregister old components', function() {
@@ -43,7 +43,7 @@ describe('ol.geom.GeometryCollection', function() {
});
it('register new components', function(done) {
var point2 = new Point([10, 20]);
const point2 = new Point([10, 20]);
multi.setGeometriesArray([point2]);
multi.on('change', function() {
done();
@@ -56,12 +56,12 @@ describe('ol.geom.GeometryCollection', function() {
describe('#getGeometries', function() {
it('returns a collection of geometries', function() {
var point = new Point([10, 20]);
var line = new LineString([[10, 20], [30, 40]]);
var poly = new Polygon([outer, inner1, inner2]);
var multi = new GeometryCollection([point, line, poly]);
const point = new Point([10, 20]);
const line = new LineString([[10, 20], [30, 40]]);
const poly = new Polygon([outer, inner1, inner2]);
const multi = new GeometryCollection([point, line, poly]);
var geometries = multi.getGeometries();
const geometries = multi.getGeometries();
expect(geometries).to.be.an(Array);
expect(geometries).to.have.length(3);
expect(geometries[0]).to.be.a(Point);
@@ -74,30 +74,30 @@ describe('ol.geom.GeometryCollection', function() {
describe('#clone()', function() {
it('has a working clone method', function() {
var point = new Point([10, 20]);
var line = new LineString([[10, 20], [30, 40]]);
var poly = new Polygon([outer, inner1, inner2]);
var multi = new GeometryCollection([point, line, poly]);
var clone = multi.clone();
const point = new Point([10, 20]);
const line = new LineString([[10, 20], [30, 40]]);
const poly = new Polygon([outer, inner1, inner2]);
const multi = new GeometryCollection([point, line, poly]);
const clone = multi.clone();
expect(clone).to.not.be(multi);
var geometries = clone.getGeometries();
const geometries = clone.getGeometries();
expect(geometries[0].getCoordinates()).to.eql([10, 20]);
expect(geometries[1].getCoordinates()).to.eql([[10, 20], [30, 40]]);
expect(geometries[2].getCoordinates()).to.eql([outer, inner1, inner2]);
});
it('does a deep clone', function() {
var point = new Point([30, 40]);
var originalGeometries = [point];
var multi = new GeometryCollection(originalGeometries);
var clone = multi.clone();
var clonedGeometries = clone.getGeometries();
const point = new Point([30, 40]);
const originalGeometries = [point];
const multi = new GeometryCollection(originalGeometries);
const clone = multi.clone();
const clonedGeometries = clone.getGeometries();
expect(clonedGeometries).not.to.be(originalGeometries);
expect(clonedGeometries).to.have.length(originalGeometries.length);
expect(clonedGeometries).to.have.length(1);
expect(clonedGeometries[0]).not.to.be(originalGeometries[0]);
expect(clonedGeometries[0].getCoordinates()).
to.eql(originalGeometries[0].getCoordinates());
to.eql(originalGeometries[0].getCoordinates());
});
});
@@ -105,10 +105,10 @@ describe('ol.geom.GeometryCollection', function() {
describe('#getExtent()', function() {
it('returns the bounding extent', function() {
var point = new Point([10, 2]);
var line = new LineString([[1, 20], [30, 40]]);
var multi = new GeometryCollection([point, line]);
var extent = multi.getExtent();
const point = new Point([10, 2]);
const line = new LineString([[1, 20], [30, 40]]);
const multi = new GeometryCollection([point, line]);
const extent = multi.getExtent();
expect(extent[0]).to.be(1);
expect(extent[2]).to.be(30);
expect(extent[1]).to.be(2);
@@ -119,7 +119,7 @@ describe('ol.geom.GeometryCollection', function() {
describe('#intersectsExtent()', function() {
var point, line, poly, multi;
let point, line, poly, multi;
beforeEach(function() {
point = new Point([5, 20]);
@@ -141,7 +141,7 @@ describe('ol.geom.GeometryCollection', function() {
});
it('returns false for non-matching extent within own extent', function() {
var extent = [0, 35, 5, 40];
const extent = [0, 35, 5, 40];
expect(poly.intersectsExtent(extent)).to.be(false);
});
@@ -149,7 +149,7 @@ describe('ol.geom.GeometryCollection', function() {
describe('#setGeometries', function() {
var line, multi, point, poly;
let line, multi, point, poly;
beforeEach(function() {
point = new Point([10, 20]);
line = new LineString([[10, 20], [30, 40]]);
@@ -158,7 +158,7 @@ describe('ol.geom.GeometryCollection', function() {
});
it('fires a change event', function() {
var listener = sinon.spy();
const listener = sinon.spy();
multi.on('change', listener);
multi.setGeometries([point, line, poly]);
expect(listener.calledOnce).to.be(true);
@@ -175,34 +175,34 @@ describe('ol.geom.GeometryCollection', function() {
describe('#scale()', function() {
it('scales a collection', function() {
var geom = new GeometryCollection([
const geom = new GeometryCollection([
new Point([-1, -2]),
new LineString([[0, 0], [1, 2]])
]);
geom.scale(10);
var geometries = geom.getGeometries();
const geometries = geom.getGeometries();
expect(geometries[0].getCoordinates()).to.eql([-10, -20]);
expect(geometries[1].getCoordinates()).to.eql([[0, 0], [10, 20]]);
});
it('accepts sx and sy', function() {
var geom = new GeometryCollection([
const geom = new GeometryCollection([
new Point([-1, -2]),
new LineString([[0, 0], [1, 2]])
]);
geom.scale(2, 3);
var geometries = geom.getGeometries();
const geometries = geom.getGeometries();
expect(geometries[0].getCoordinates()).to.eql([-2, -6]);
expect(geometries[1].getCoordinates()).to.eql([[0, 0], [2, 6]]);
});
it('accepts an anchor', function() {
var geom = new GeometryCollection([
const geom = new GeometryCollection([
new Point([-1, -2]),
new LineString([[0, 0], [1, 2]])
]);
geom.scale(10, 15, [-1, -2]);
var geometries = geom.getGeometries();
const geometries = geom.getGeometries();
expect(geometries[0].getCoordinates()).to.eql([-1, -2]);
expect(geometries[1].getCoordinates()).to.eql([[9, 28], [19, 58]]);
});
@@ -211,7 +211,7 @@ describe('ol.geom.GeometryCollection', function() {
describe('#transform()', function() {
var line, multi, point;
let line, multi, point;
beforeEach(function() {
point = new Point([10, 20]);
line = new LineString([[10, 20], [30, 40]]);
@@ -221,11 +221,11 @@ describe('ol.geom.GeometryCollection', function() {
it('transforms all geometries', function() {
multi.transform('EPSG:4326', 'EPSG:3857');
var geometries = multi.getGeometries();
const geometries = multi.getGeometries();
expect(geometries[0]).to.be.a(Point);
expect(geometries[1]).to.be.a(LineString);
var coords = geometries[0].getCoordinates();
let coords = geometries[0].getCoordinates();
expect(coords[0]).to.roughlyEqual(1113194.90, 1e-2);
expect(coords[1]).to.roughlyEqual(2273030.92, 1e-2);
+34 -34
View File
@@ -12,7 +12,7 @@ describe('ol.geom.LineString', function() {
describe('construct empty', function() {
var lineString;
let lineString;
beforeEach(function() {
lineString = new LineString([]);
});
@@ -48,7 +48,7 @@ describe('ol.geom.LineString', function() {
describe('construct with 2D coordinates', function() {
var lineString;
let lineString;
beforeEach(function() {
lineString = new LineString([[1, 2], [3, 4]]);
});
@@ -109,7 +109,7 @@ describe('ol.geom.LineString', function() {
describe('construct with 3D coordinates', function() {
var lineString;
let lineString;
beforeEach(function() {
lineString = new LineString([[1, 2, 3], [4, 5, 6]]);
});
@@ -154,10 +154,10 @@ describe('ol.geom.LineString', function() {
describe('construct with 3D coordinates and layout XYM', function() {
var lineString;
let lineString;
beforeEach(function() {
lineString = new LineString(
[[1, 2, 3], [4, 5, 6]], 'XYM');
[[1, 2, 3], [4, 5, 6]], 'XYM');
});
it('has the expected layout', function() {
@@ -200,7 +200,7 @@ describe('ol.geom.LineString', function() {
describe('construct with 4D coordinates', function() {
var lineString;
let lineString;
beforeEach(function() {
lineString = new LineString([[1, 2, 3, 4], [5, 6, 7, 8]]);
});
@@ -246,23 +246,23 @@ describe('ol.geom.LineString', function() {
describe('#scale()', function() {
it('scales a linestring', function() {
var geom = new LineString([[-10, -20], [10, 20]]);
const geom = new LineString([[-10, -20], [10, 20]]);
geom.scale(10);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-100, -200], [100, 200]]);
});
it('accepts sx and sy', function() {
var geom = new LineString([[-10, -20], [10, 20]]);
const geom = new LineString([[-10, -20], [10, 20]]);
geom.scale(2, 3);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-20, -60], [20, 60]]);
});
it('accepts an anchor', function() {
var geom = new LineString([[-10, -20], [10, 20]]);
const geom = new LineString([[-10, -20], [10, 20]]);
geom.scale(3, 2, [10, 20]);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-50, -60], [10, 20]]);
});
@@ -270,10 +270,10 @@ describe('ol.geom.LineString', function() {
describe('with a simple line string', function() {
var lineString;
let lineString;
beforeEach(function() {
lineString = new LineString(
[[0, 0], [1.5, 1], [3, 3], [5, 1], [6, 3.5], [7, 5]]);
[[0, 0], [1.5, 1], [3, 3], [5, 1], [6, 3.5], [7, 5]]);
});
describe('#getFirstCoordinate', function() {
@@ -287,7 +287,7 @@ describe('ol.geom.LineString', function() {
describe('#getFlatMidpoint', function() {
it('returns the expected result', function() {
var midpoint = lineString.getFlatMidpoint();
const midpoint = lineString.getFlatMidpoint();
expect(midpoint).to.be.an(Array);
expect(midpoint).to.have.length(2);
expect(midpoint[0]).to.roughlyEqual(4, 1e-1);
@@ -307,21 +307,21 @@ describe('ol.geom.LineString', function() {
describe('#simplify', function() {
it('returns a simplified geometry', function() {
var simplified = lineString.simplify(1);
const simplified = lineString.simplify(1);
expect(simplified).to.be.an(LineString);
expect(simplified.getCoordinates()).to.eql(
[[0, 0], [3, 3], [5, 1], [7, 5]]);
[[0, 0], [3, 3], [5, 1], [7, 5]]);
});
it('does not modify the original', function() {
lineString.simplify(1);
expect(lineString.getCoordinates()).to.eql(
[[0, 0], [1.5, 1], [3, 3], [5, 1], [6, 3.5], [7, 5]]);
[[0, 0], [1.5, 1], [3, 3], [5, 1], [6, 3.5], [7, 5]]);
});
it('delegates to the internal method', function() {
var simplified = lineString.simplify(2);
var internal = lineString.getSimplifiedGeometry(4);
const simplified = lineString.simplify(2);
const internal = lineString.getSimplifiedGeometry(4);
expect(simplified.getCoordinates()).to.eql(internal.getCoordinates());
});
@@ -330,31 +330,31 @@ describe('ol.geom.LineString', function() {
describe('#getSimplifiedGeometry', function() {
it('returns the expectedResult', function() {
var simplifiedGeometry = lineString.getSimplifiedGeometry(1);
const simplifiedGeometry = lineString.getSimplifiedGeometry(1);
expect(simplifiedGeometry).to.be.an(LineString);
expect(simplifiedGeometry.getCoordinates()).to.eql(
[[0, 0], [3, 3], [5, 1], [7, 5]]);
[[0, 0], [3, 3], [5, 1], [7, 5]]);
});
it('caches by resolution', function() {
var simplifiedGeometry1 = lineString.getSimplifiedGeometry(1);
var simplifiedGeometry2 = lineString.getSimplifiedGeometry(1);
const simplifiedGeometry1 = lineString.getSimplifiedGeometry(1);
const simplifiedGeometry2 = lineString.getSimplifiedGeometry(1);
expect(simplifiedGeometry1).to.be(simplifiedGeometry2);
});
it('invalidates the cache when the geometry changes', function() {
var simplifiedGeometry1 = lineString.getSimplifiedGeometry(1);
const simplifiedGeometry1 = lineString.getSimplifiedGeometry(1);
lineString.setCoordinates(lineString.getCoordinates());
var simplifiedGeometry2 = lineString.getSimplifiedGeometry(1);
const simplifiedGeometry2 = lineString.getSimplifiedGeometry(1);
expect(simplifiedGeometry1).not.to.be(simplifiedGeometry2);
});
it('remembers the minimum squared tolerance', function() {
sinon.spy(lineString, 'getSimplifiedGeometryInternal');
var simplifiedGeometry1 = lineString.getSimplifiedGeometry(0.05);
const simplifiedGeometry1 = lineString.getSimplifiedGeometry(0.05);
expect(lineString.getSimplifiedGeometryInternal.callCount).to.be(1);
expect(simplifiedGeometry1).to.be(lineString);
var simplifiedGeometry2 = lineString.getSimplifiedGeometry(0.01);
const simplifiedGeometry2 = lineString.getSimplifiedGeometry(0.01);
expect(lineString.getSimplifiedGeometryInternal.callCount).to.be(1);
expect(simplifiedGeometry2).to.be(lineString);
});
@@ -372,7 +372,7 @@ describe('ol.geom.LineString', function() {
});
it('return the mid point when fraction is 0.5', function() {
var midpoint = lineString.getFlatMidpoint();
const midpoint = lineString.getFlatMidpoint();
expect(lineString.getCoordinateAt(0.5)).to.eql(midpoint);
});
@@ -382,10 +382,10 @@ describe('ol.geom.LineString', function() {
describe('with a simple XYM coordinates', function() {
var lineString;
let lineString;
beforeEach(function() {
lineString = new LineString(
[[1, 2, 3], [4, 5, 6]], 'XYM');
[[1, 2, 3], [4, 5, 6]], 'XYM');
});
describe('#getCoordinateAtM', function() {
@@ -411,7 +411,7 @@ describe('ol.geom.LineString', function() {
describe('with several XYZM coordinates', function() {
var lineString;
let lineString;
beforeEach(function() {
lineString = new LineString([
[0, 0, 0, 0],
@@ -432,10 +432,10 @@ describe('ol.geom.LineString', function() {
it('returns the expected value', function() {
expect(lineString.getLayout()).to.be('XYZM');
var m;
let m;
for (m = 0; m <= 22; m += 0.5) {
expect(lineString.getCoordinateAtM(m, true)).to.eql(
[m, -m, 2 * m, m]);
[m, -m, 2 * m, m]);
}
});
+71 -71
View File
@@ -13,7 +13,7 @@ describe('ol.geom.MultiLineString', function() {
describe('construct empty', function() {
var multiLineString;
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString([]);
});
@@ -40,23 +40,23 @@ describe('ol.geom.MultiLineString', function() {
it('can append line strings', function() {
multiLineString.appendLineString(
new LineString([[1, 2], [3, 4]]));
new LineString([[1, 2], [3, 4]]));
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]]]);
[[[1, 2], [3, 4]]]);
multiLineString.appendLineString(
new LineString([[5, 6], [7, 8]]));
new LineString([[5, 6], [7, 8]]));
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
});
});
describe('construct with 2D coordinates', function() {
var multiLineString;
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
});
it('has the expected layout', function() {
@@ -65,7 +65,7 @@ describe('ol.geom.MultiLineString', function() {
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
});
it('has the expected extent', function() {
@@ -74,7 +74,7 @@ describe('ol.geom.MultiLineString', function() {
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8]);
[1, 2, 3, 4, 5, 6, 7, 8]);
});
it('has stride the expected stride', function() {
@@ -105,10 +105,10 @@ describe('ol.geom.MultiLineString', function() {
describe('construct with 3D coordinates', function() {
var multiLineString;
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
});
it('has the expected layout', function() {
@@ -117,7 +117,7 @@ describe('ol.geom.MultiLineString', function() {
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
});
it('has the expected extent', function() {
@@ -126,7 +126,7 @@ describe('ol.geom.MultiLineString', function() {
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
});
it('has stride the expected stride', function() {
@@ -137,11 +137,11 @@ describe('ol.geom.MultiLineString', function() {
describe('construct with 3D coordinates and layout XYM', function() {
var multiLineString;
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]],
'XYM');
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]],
'XYM');
});
it('has the expected layout', function() {
@@ -150,7 +150,7 @@ describe('ol.geom.MultiLineString', function() {
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
});
it('has the expected extent', function() {
@@ -159,7 +159,7 @@ describe('ol.geom.MultiLineString', function() {
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
});
it('has stride the expected stride', function() {
@@ -167,11 +167,11 @@ describe('ol.geom.MultiLineString', function() {
});
it('can return individual line strings', function() {
var lineString0 = multiLineString.getLineString(0);
const lineString0 = multiLineString.getLineString(0);
expect(lineString0).to.be.an(LineString);
expect(lineString0.getLayout()).to.be('XYM');
expect(lineString0.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
var lineString1 = multiLineString.getLineString(1);
const lineString1 = multiLineString.getLineString(1);
expect(lineString1).to.be.an(LineString);
expect(lineString1.getLayout()).to.be('XYM');
expect(lineString1.getCoordinates()).to.eql([[7, 8, 9], [10, 11, 12]]);
@@ -183,23 +183,23 @@ describe('ol.geom.MultiLineString', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, true, true)).to.eql(
[1, 2, 0]);
[1, 2, 0]);
expect(multiLineString.getCoordinateAtM(3, true, true)).to.eql(
[1, 2, 3]);
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, true, true)).to.eql(
[2.5, 3.5, 4.5]);
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, true, true)).to.eql(
[4, 5, 6]);
[4, 5, 6]);
expect(multiLineString.getCoordinateAtM(7.5, true, true)).to.eql(
[5.5, 6.5, 7.5]);
[5.5, 6.5, 7.5]);
expect(multiLineString.getCoordinateAtM(9, true, true)).to.eql(
[7, 8, 9]);
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, true, true)).to.eql(
[8.5, 9.5, 10.5]);
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, true, true)).to.eql(
[10, 11, 12]);
[10, 11, 12]);
expect(multiLineString.getCoordinateAtM(15, true, true)).to.eql(
[10, 11, 15]);
[10, 11, 15]);
});
});
@@ -208,23 +208,23 @@ describe('ol.geom.MultiLineString', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, true, false)).to.eql(
[1, 2, 0]);
[1, 2, 0]);
expect(multiLineString.getCoordinateAtM(3, true, false)).to.eql(
[1, 2, 3]);
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, true, false)).to.eql(
[2.5, 3.5, 4.5]);
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, true, false)).to.eql(
[4, 5, 6]);
[4, 5, 6]);
expect(multiLineString.getCoordinateAtM(7.5, true, false)).to.be(
null);
null);
expect(multiLineString.getCoordinateAtM(9, true, false)).to.eql(
[7, 8, 9]);
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, true, false)).to.eql(
[8.5, 9.5, 10.5]);
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, true, false)).to.eql(
[10, 11, 12]);
[10, 11, 12]);
expect(multiLineString.getCoordinateAtM(15, true, false)).to.eql(
[10, 11, 15]);
[10, 11, 15]);
});
});
@@ -233,23 +233,23 @@ describe('ol.geom.MultiLineString', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, false, true)).to.eql(
null);
null);
expect(multiLineString.getCoordinateAtM(3, false, true)).to.eql(
[1, 2, 3]);
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, false, true)).to.eql(
[2.5, 3.5, 4.5]);
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, false, true)).to.eql(
[4, 5, 6]);
[4, 5, 6]);
expect(multiLineString.getCoordinateAtM(7.5, false, true)).to.eql(
[5.5, 6.5, 7.5]);
[5.5, 6.5, 7.5]);
expect(multiLineString.getCoordinateAtM(9, false, true)).to.eql(
[7, 8, 9]);
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, false, true)).to.eql(
[8.5, 9.5, 10.5]);
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, false, true)).to.eql(
[10, 11, 12]);
[10, 11, 12]);
expect(multiLineString.getCoordinateAtM(15, false, true)).to.eql(
null);
null);
});
});
@@ -258,23 +258,23 @@ describe('ol.geom.MultiLineString', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, false, false)).to.eql(
null);
null);
expect(multiLineString.getCoordinateAtM(3, false, false)).to.eql(
[1, 2, 3]);
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, false, false)).to.eql(
[2.5, 3.5, 4.5]);
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, false, false)).to.eql(
[4, 5, 6]);
[4, 5, 6]);
expect(multiLineString.getCoordinateAtM(7.5, false, false)).to.eql(
null);
null);
expect(multiLineString.getCoordinateAtM(9, false, false)).to.eql(
[7, 8, 9]);
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, false, false)).to.eql(
[8.5, 9.5, 10.5]);
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, false, false)).to.eql(
[10, 11, 12]);
[10, 11, 12]);
expect(multiLineString.getCoordinateAtM(15, false, false)).to.eql(
null);
null);
});
});
@@ -285,10 +285,10 @@ describe('ol.geom.MultiLineString', function() {
describe('construct with 4D coordinates', function() {
var multiLineString;
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]);
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]);
});
it('has the expected layout', function() {
@@ -297,7 +297,7 @@ describe('ol.geom.MultiLineString', function() {
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]);
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]);
});
it('has the expected extent', function() {
@@ -306,7 +306,7 @@ describe('ol.geom.MultiLineString', function() {
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
});
it('has stride the expected stride', function() {
@@ -318,23 +318,23 @@ describe('ol.geom.MultiLineString', function() {
describe('#scale()', function() {
it('scales a multi-linestring', function() {
var geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
const geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
geom.scale(10);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-100, -200], [100, 200]], [[50, -100], [-50, 100]]]);
});
it('accepts sx and sy', function() {
var geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
const geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
geom.scale(2, 3);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-20, -60], [20, 60]], [[10, -30], [-10, 30]]]);
});
it('accepts an anchor', function() {
var geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
const geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
geom.scale(3, 2, [10, 20]);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-50, -60], [10, 20]], [[-5, -40], [-35, 0]]]);
});
@@ -343,14 +343,14 @@ describe('ol.geom.MultiLineString', function() {
describe('#setLineStrings', function() {
it('sets the line strings', function() {
var multiLineString = new MultiLineString(null);
var lineString1 = new LineString([[1, 2], [3, 4]]);
var lineString2 = new LineString([[5, 6], [7, 8]]);
const multiLineString = new MultiLineString(null);
const lineString1 = new LineString([[1, 2], [3, 4]]);
const lineString2 = new LineString([[5, 6], [7, 8]]);
multiLineString.setLineStrings([lineString1, lineString2]);
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8]);
[1, 2, 3, 4, 5, 6, 7, 8]);
expect(multiLineString.getEnds()).to.eql([4, 8]);
var coordinates = multiLineString.getCoordinates();
const coordinates = multiLineString.getCoordinates();
expect(coordinates[0]).to.eql(lineString1.getCoordinates());
expect(coordinates[1]).to.eql(lineString2.getCoordinates());
});
+25 -25
View File
@@ -13,7 +13,7 @@ describe('ol.geom.MultiPoint', function() {
describe('construct empty', function() {
var multiPoint;
let multiPoint;
beforeEach(function() {
multiPoint = new MultiPoint([]);
});
@@ -49,7 +49,7 @@ describe('ol.geom.MultiPoint', function() {
describe('construct with 2D coordinates', function() {
var multiPoint;
let multiPoint;
beforeEach(function() {
multiPoint = new MultiPoint([[1, 2], [3, 4]]);
});
@@ -90,7 +90,7 @@ describe('ol.geom.MultiPoint', function() {
describe('construct with 3D coordinates', function() {
var multiPoint;
let multiPoint;
beforeEach(function() {
multiPoint = new MultiPoint([[1, 2, 3], [4, 5, 6]]);
});
@@ -119,10 +119,10 @@ describe('ol.geom.MultiPoint', function() {
describe('construct with 3D coordinates and layout XYM', function() {
var multiPoint;
let multiPoint;
beforeEach(function() {
multiPoint = new MultiPoint(
[[1, 2, 3], [4, 5, 6]], 'XYM');
[[1, 2, 3], [4, 5, 6]], 'XYM');
});
it('has the expected layout', function() {
@@ -146,16 +146,16 @@ describe('ol.geom.MultiPoint', function() {
});
it('can return individual points', function() {
var point0 = multiPoint.getPoint(0);
const point0 = multiPoint.getPoint(0);
expect(point0.getLayout()).to.be('XYM');
expect(point0.getCoordinates()).to.eql([1, 2, 3]);
var point1 = multiPoint.getPoint(1);
const point1 = multiPoint.getPoint(1);
expect(point1.getLayout()).to.be('XYM');
expect(point1.getCoordinates()).to.eql([4, 5, 6]);
});
it('can return all points', function() {
var points = multiPoint.getPoints();
const points = multiPoint.getPoints();
expect(points).to.have.length(2);
expect(points[0]).to.be.an(Point);
expect(points[0].getLayout()).to.be('XYM');
@@ -169,7 +169,7 @@ describe('ol.geom.MultiPoint', function() {
describe('construct with 4D coordinates', function() {
var multiPoint;
let multiPoint;
beforeEach(function() {
multiPoint = new MultiPoint([[1, 2, 3, 4], [5, 6, 7, 8]]);
});
@@ -197,7 +197,7 @@ describe('ol.geom.MultiPoint', function() {
describe('#getClosestPoint', function() {
it('preserves extra dimensions', function() {
var closestPoint = multiPoint.getClosestPoint([6, 6]);
const closestPoint = multiPoint.getClosestPoint([6, 6]);
expect(closestPoint).to.eql([5, 6, 7, 8]);
});
@@ -208,23 +208,23 @@ describe('ol.geom.MultiPoint', function() {
describe('#scale()', function() {
it('scales a multi-point', function() {
var geom = new MultiPoint([[-10, -20], [10, 20]]);
const geom = new MultiPoint([[-10, -20], [10, 20]]);
geom.scale(10);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-100, -200], [100, 200]]);
});
it('accepts sx and sy', function() {
var geom = new MultiPoint([[-10, -20], [10, 20]]);
const geom = new MultiPoint([[-10, -20], [10, 20]]);
geom.scale(2, 3);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-20, -60], [20, 60]]);
});
it('accepts an anchor', function() {
var geom = new MultiPoint([[-10, -20], [10, 20]]);
const geom = new MultiPoint([[-10, -20], [10, 20]]);
geom.scale(3, 2, [-10, -20]);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-10, -20], [50, 60]]);
});
@@ -232,7 +232,7 @@ describe('ol.geom.MultiPoint', function() {
describe('#applyTransform()', function() {
var multi, transform;
let multi, transform;
beforeEach(function() {
multi = new MultiPoint([[1, 2], [3, 4]]);
transform = sinon.spy();
@@ -241,7 +241,7 @@ describe('ol.geom.MultiPoint', function() {
it('calls a transform function', function() {
multi.applyTransform(transform);
expect(transform.calledOnce).to.be(true);
var args = transform.firstCall.args;
const args = transform.firstCall.args;
expect(args).to.have.length(3);
expect(args[0]).to.be(multi.getFlatCoordinates()); // input coords
@@ -250,9 +250,9 @@ describe('ol.geom.MultiPoint', function() {
});
it('allows for modification of coordinates', function() {
var mod = function(input, output, dimension) {
var copy = input.slice();
for (var i = 0, ii = copy.length; i < ii; i += dimension) {
const mod = function(input, output, dimension) {
const copy = input.slice();
for (let i = 0, ii = copy.length; i < ii; i += dimension) {
output[i] = copy[i + 1];
output[i + 1] = copy[i];
}
@@ -262,7 +262,7 @@ describe('ol.geom.MultiPoint', function() {
});
it('returns undefined', function() {
var got = multi.applyTransform(transform);
const got = multi.applyTransform(transform);
expect(got).to.be(undefined);
});
@@ -271,12 +271,12 @@ describe('ol.geom.MultiPoint', function() {
describe('#transform()', function() {
it('transforms a geometry given CRS identifiers', function() {
var multi = new MultiPoint([[-111, 45], [111, -45]]).transform(
'EPSG:4326', 'EPSG:3857');
const multi = new MultiPoint([[-111, 45], [111, -45]]).transform(
'EPSG:4326', 'EPSG:3857');
expect(multi).to.be.a(MultiPoint);
var coords = multi.getCoordinates();
const coords = multi.getCoordinates();
expect(coords[0][0]).to.roughlyEqual(-12356463.47, 1e-2);
expect(coords[0][1]).to.roughlyEqual(5621521.48, 1e-2);
+35 -35
View File
@@ -12,18 +12,18 @@ describe('ol.geom.MultiPolygon', function() {
describe('with a null MultiPolygon', function() {
var multiPolygon;
let multiPolygon;
beforeEach(function() {
multiPolygon = new MultiPolygon(null);
});
it('can append polygons', function() {
multiPolygon.appendPolygon(
new Polygon([[[0, 0], [0, 2], [1, 1], [2, 0]]]));
new Polygon([[[0, 0], [0, 2], [1, 1], [2, 0]]]));
expect(multiPolygon.getCoordinates()).to.eql(
[[[[0, 0], [0, 2], [1, 1], [2, 0]]]]);
[[[[0, 0], [0, 2], [1, 1], [2, 0]]]]);
multiPolygon.appendPolygon(
new Polygon([[[3, 0], [4, 1], [5, 2], [5, 0]]]));
new Polygon([[[3, 0], [4, 1], [5, 2], [5, 0]]]));
expect(multiPolygon.getCoordinates()).to.eql([
[[[0, 0], [0, 2], [1, 1], [2, 0]]],
[[[3, 0], [4, 1], [5, 2], [5, 0]]]
@@ -35,18 +35,18 @@ describe('ol.geom.MultiPolygon', function() {
describe('with an empty MultiPolygon', function() {
var multiPolygon;
let multiPolygon;
beforeEach(function() {
multiPolygon = new MultiPolygon([]);
});
it('can append polygons', function() {
multiPolygon.appendPolygon(
new Polygon([[[0, 0], [0, 2], [1, 1], [2, 0]]]));
new Polygon([[[0, 0], [0, 2], [1, 1], [2, 0]]]));
expect(multiPolygon.getCoordinates()).to.eql(
[[[[0, 0], [0, 2], [1, 1], [2, 0]]]]);
[[[[0, 0], [0, 2], [1, 1], [2, 0]]]]);
multiPolygon.appendPolygon(
new Polygon([[[3, 0], [4, 1], [5, 2], [5, 0]]]));
new Polygon([[[3, 0], [4, 1], [5, 2], [5, 0]]]));
expect(multiPolygon.getCoordinates()).to.eql([
[[[0, 0], [0, 2], [1, 1], [2, 0]]],
[[[3, 0], [4, 1], [5, 2], [5, 0]]]
@@ -59,29 +59,29 @@ describe('ol.geom.MultiPolygon', function() {
describe('#scale()', function() {
it('scales a multi-polygon', function() {
var geom = new MultiPolygon([[
const geom = new MultiPolygon([[
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
]]);
geom.scale(10);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[[-10, -20], [10, -20], [10, 20], [-10, 20], [-10, -20]]]]);
});
it('accepts sx and sy', function() {
var geom = new MultiPolygon([[
const geom = new MultiPolygon([[
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
]]);
geom.scale(2, 3);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[[-2, -6], [2, -6], [2, 6], [-2, 6], [-2, -6]]]]);
});
it('accepts an anchor', function() {
var geom = new MultiPolygon([[
const geom = new MultiPolygon([[
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
]]);
geom.scale(3, 2, [-1, -2]);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[[-1, -2], [5, -2], [5, 6], [-1, 6], [-1, -2]]]]);
});
@@ -89,7 +89,7 @@ describe('ol.geom.MultiPolygon', function() {
describe('with a simple MultiPolygon', function() {
var multiPolygon;
let multiPolygon;
beforeEach(function() {
multiPolygon = new MultiPolygon([
[[[0, 0], [0, 2], [1, 1], [2, 0]]],
@@ -98,32 +98,32 @@ describe('ol.geom.MultiPolygon', function() {
});
it('can return individual polygons', function() {
var polygon0 = multiPolygon.getPolygon(0);
const polygon0 = multiPolygon.getPolygon(0);
expect(polygon0).to.be.an(Polygon);
expect(polygon0.getCoordinates()).to.eql(
[[[0, 0], [0, 2], [1, 1], [2, 0]]]);
var polygon1 = multiPolygon.getPolygon(1);
[[[0, 0], [0, 2], [1, 1], [2, 0]]]);
const polygon1 = multiPolygon.getPolygon(1);
expect(polygon1).to.be.an(Polygon);
expect(polygon1.getCoordinates()).to.eql(
[[[3, 0], [4, 1], [5, 2], [5, 0]]]);
[[[3, 0], [4, 1], [5, 2], [5, 0]]]);
});
it('can return all polygons', function() {
var polygons = multiPolygon.getPolygons();
const polygons = multiPolygon.getPolygons();
expect(polygons).to.be.an(Array);
expect(polygons).to.have.length(2);
expect(polygons[0]).to.be.an(Polygon);
expect(polygons[0].getCoordinates()).to.eql(
[[[0, 0], [0, 2], [1, 1], [2, 0]]]);
[[[0, 0], [0, 2], [1, 1], [2, 0]]]);
expect(polygons[1]).to.be.an(Polygon);
expect(polygons[1].getCoordinates()).to.eql(
[[[3, 0], [4, 1], [5, 2], [5, 0]]]);
[[[3, 0], [4, 1], [5, 2], [5, 0]]]);
});
describe('#clone()', function() {
it('has the expected endss_', function() {
var clone = multiPolygon.clone();
const clone = multiPolygon.clone();
expect(multiPolygon.endss_).to.eql(clone.endss_);
});
@@ -131,12 +131,12 @@ describe('ol.geom.MultiPolygon', function() {
describe('#getCoordinates()', function() {
var cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
var cw2 = [[-140, -60], [-140, 60], [140, 60], [140, -60], [-140, -60]];
var ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
var ccw2 = [[-140, -60], [140, -60], [140, 60], [-140, 60], [-140, -60]];
var right = new MultiPolygon([[ccw, cw], [ccw2, cw2]]);
var left = new MultiPolygon([[cw, ccw], [cw2, ccw2]]);
const cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
const cw2 = [[-140, -60], [-140, 60], [140, 60], [140, -60], [-140, -60]];
const ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
const ccw2 = [[-140, -60], [140, -60], [140, 60], [-140, 60], [-140, -60]];
const right = new MultiPolygon([[ccw, cw], [ccw2, cw2]]);
const left = new MultiPolygon([[cw, ccw], [cw2, ccw2]]);
it('returns coordinates as they were constructed', function() {
expect(right.getCoordinates()).to.eql([[ccw, cw], [ccw2, cw2]]);
@@ -166,7 +166,7 @@ describe('ol.geom.MultiPolygon', function() {
describe('#getSimplifiedGeometry', function() {
it('returns the expected result', function() {
var simplifiedGeometry = multiPolygon.getSimplifiedGeometry(1);
const simplifiedGeometry = multiPolygon.getSimplifiedGeometry(1);
expect(simplifiedGeometry).to.be.an(MultiPolygon);
expect(simplifiedGeometry.getCoordinates()).to.eql([
[[[0, 0], [0, 2], [2, 0]]],
@@ -178,10 +178,10 @@ describe('ol.geom.MultiPolygon', function() {
describe('#intersectsExtent()', function() {
it('returns true for extent of of each polygon', function() {
var polygons = multiPolygon.getPolygons();
for (var i = 0; i < polygons.length; i++) {
const polygons = multiPolygon.getPolygons();
for (let i = 0; i < polygons.length; i++) {
expect(multiPolygon.intersectsExtent(
polygons[i].getExtent())).to.be(true);
polygons[i].getExtent())).to.be(true);
}
});
@@ -196,11 +196,11 @@ describe('ol.geom.MultiPolygon', function() {
describe('#getInteriorPoints', function() {
it('returns XYM multipoint with intersection width as M', function() {
var geom = new MultiPolygon([
const geom = new MultiPolygon([
[[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]],
[[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]
]);
var interiorPoints = geom.getInteriorPoints();
const interiorPoints = geom.getInteriorPoints();
expect(interiorPoints.getType()).to.be('MultiPoint');
expect(interiorPoints.layout).to.be('XYM');
expect(interiorPoints.getCoordinates()).to.eql([[0.5, 0.5, 1], [1.5, 1.5, 1]]);
+20 -20
View File
@@ -11,7 +11,7 @@ describe('ol.geom.Point', function() {
describe('construct with 2D coordinates', function() {
var point;
let point;
beforeEach(function() {
point = new Point([1, 2]);
});
@@ -48,7 +48,7 @@ describe('ol.geom.Point', function() {
describe('construct with 3D coordinates and layout XYM', function() {
var point;
let point;
beforeEach(function() {
point = new Point([1, 2, 3], 'XYM');
});
@@ -85,7 +85,7 @@ describe('ol.geom.Point', function() {
describe('construct with 4D coordinates', function() {
var point;
let point;
beforeEach(function() {
point = new Point([1, 2, 3, 4]);
});
@@ -121,7 +121,7 @@ describe('ol.geom.Point', function() {
describe('#getClosestPoint', function() {
it('preseves extra dimensions', function() {
var closestPoint = point.getClosestPoint([0, 0]);
const closestPoint = point.getClosestPoint([0, 0]);
expect(closestPoint).to.eql([1, 2, 3, 4]);
});
@@ -132,23 +132,23 @@ describe('ol.geom.Point', function() {
describe('#scale()', function() {
it('scales a point', function() {
var geom = new Point([1, 2]);
const geom = new Point([1, 2]);
geom.scale(10e6);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([1, 2]);
});
it('accepts sx and sy', function() {
var geom = new Point([1, 2]);
const geom = new Point([1, 2]);
geom.scale(1e6, -42);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([1, 2]);
});
it('accepts an anchor', function() {
var geom = new Point([1, 2]);
const geom = new Point([1, 2]);
geom.scale(10, 15, [0, 0]);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([10, 30]);
});
@@ -156,7 +156,7 @@ describe('ol.geom.Point', function() {
describe('#applyTransform()', function() {
var point, transform;
let point, transform;
beforeEach(function() {
point = new Point([1, 2]);
transform = sinon.spy();
@@ -165,7 +165,7 @@ describe('ol.geom.Point', function() {
it('calls a transform function', function() {
point.applyTransform(transform);
expect(transform.calledOnce).to.be(true);
var args = transform.firstCall.args;
const args = transform.firstCall.args;
expect(args).to.have.length(3);
expect(args[0]).to.be(point.getFlatCoordinates()); // input coords
@@ -174,8 +174,8 @@ describe('ol.geom.Point', function() {
});
it('allows for modification of coordinates', function() {
var mod = function(input, output, dimension) {
var copy = input.slice();
const mod = function(input, output, dimension) {
const copy = input.slice();
output[1] = copy[0];
output[0] = copy[1];
};
@@ -184,7 +184,7 @@ describe('ol.geom.Point', function() {
});
it('returns undefined', function() {
var got = point.applyTransform(transform);
const got = point.applyTransform(transform);
expect(got).to.be(undefined);
});
@@ -193,21 +193,21 @@ describe('ol.geom.Point', function() {
describe('#transform()', function() {
it('transforms a geometry given CRS identifiers', function() {
var point = new Point([-111, 45]).transform(
'EPSG:4326', 'EPSG:3857');
const point = new Point([-111, 45]).transform(
'EPSG:4326', 'EPSG:3857');
expect(point).to.be.a(Point);
var coords = point.getCoordinates();
const coords = point.getCoordinates();
expect(coords[0]).to.roughlyEqual(-12356463.47, 1e-2);
expect(coords[1]).to.roughlyEqual(5621521.48, 1e-2);
});
it('modifies the original', function() {
var point = new Point([-111, 45]);
const point = new Point([-111, 45]);
point.transform('EPSG:4326', 'EPSG:3857');
var coords = point.getCoordinates();
const coords = point.getCoordinates();
expect(coords[0]).to.roughlyEqual(-12356463.47, 1e-2);
expect(coords[1]).to.roughlyEqual(5621521.48, 1e-2);
+67 -67
View File
@@ -14,7 +14,7 @@ describe('ol/geom/Polygon', function() {
describe('construct empty', function() {
var polygon;
let polygon;
beforeEach(function() {
polygon = new Polygon([]);
});
@@ -41,21 +41,21 @@ describe('ol/geom/Polygon', function() {
it('can append linear rings', function() {
polygon.appendLinearRing(
new LinearRing([[1, 2], [3, 4], [5, 6]]));
new LinearRing([[1, 2], [3, 4], [5, 6]]));
expect(polygon.getCoordinates()).to.eql(
[[[1, 2], [3, 4], [5, 6]]]);
[[[1, 2], [3, 4], [5, 6]]]);
polygon.appendLinearRing(
new LinearRing([[7, 8], [9, 10], [11, 12]]));
new LinearRing([[7, 8], [9, 10], [11, 12]]));
expect(polygon.getCoordinates()).to.eql(
[[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]]);
[[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]]);
});
});
describe('construct with 2D coordinates', function() {
var outerRing, innerRing, polygon, flatCoordinates;
var outsideOuter, inside, insideInner;
let outerRing, innerRing, polygon, flatCoordinates;
let outsideOuter, inside, insideInner;
beforeEach(function() {
outerRing = [[0, 1], [1, 4], [4, 3], [3, 0]];
innerRing = [[2, 2], [3, 2], [3, 3], [2, 3]];
@@ -92,7 +92,7 @@ describe('ol/geom/Polygon', function() {
});
it('has the expected rings', function() {
var linearRings = polygon.getLinearRings();
const linearRings = polygon.getLinearRings();
expect(linearRings).to.be.an(Array);
expect(linearRings).to.have.length(2);
expect(linearRings[0]).to.be.an(LinearRing);
@@ -105,7 +105,7 @@ describe('ol/geom/Polygon', function() {
outerRing.reverse();
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
var coordinates = polygon.getCoordinates();
const coordinates = polygon.getCoordinates();
expect(coordinates[0]).to.eql(outerRing);
expect(coordinates[1]).to.eql(innerRing);
});
@@ -124,10 +124,10 @@ describe('ol/geom/Polygon', function() {
describe('#getCoordinates()', function() {
var cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
var ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
var right = new Polygon([ccw, cw]);
var left = new Polygon([cw, ccw]);
const cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
const ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
const right = new Polygon([ccw, cw]);
const left = new Polygon([cw, ccw]);
it('returns coordinates as they were constructed', function() {
expect(right.getCoordinates()).to.eql([ccw, cw]);
@@ -173,8 +173,8 @@ describe('ol/geom/Polygon', function() {
describe('construct with 3D coordinates', function() {
var outerRing, innerRing, polygon, flatCoordinates;
var outsideOuter, inside, insideInner;
let outerRing, innerRing, polygon, flatCoordinates;
let outsideOuter, inside, insideInner;
beforeEach(function() {
outerRing = [[0, 0, 1], [4, 4, 2], [4, 0, 3]];
innerRing = [[2, 1, 4], [3, 1, 5], [3, 2, 6]];
@@ -221,17 +221,17 @@ describe('ol/geom/Polygon', function() {
it('does not intersect outside extent', function() {
expect(polygon.intersectsExtent(
_ol_extent_.boundingExtent([outsideOuter]))).to.be(false);
_ol_extent_.boundingExtent([outsideOuter]))).to.be(false);
});
it('does intersect inside extent', function() {
expect(polygon.intersectsExtent(
_ol_extent_.boundingExtent([inside]))).to.be(true);
_ol_extent_.boundingExtent([inside]))).to.be(true);
});
it('does intersect boundary extent', function() {
var firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
var firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
const firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
const firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
expect(polygon.intersectsExtent(_ol_extent_.boundingExtent([[firstMidX,
firstMidY]]))).to.be(true);
@@ -239,7 +239,7 @@ describe('ol/geom/Polygon', function() {
it('does not intersect extent fully contained by inner ring', function() {
expect(polygon.intersectsExtent(
_ol_extent_.boundingExtent([insideInner]))).to.be(false);
_ol_extent_.boundingExtent([insideInner]))).to.be(false);
});
});
@@ -271,13 +271,13 @@ describe('ol/geom/Polygon', function() {
describe('construct with 3D coordinates and layout XYM', function() {
var outerRing, innerRing, polygon, flatCoordinates;
var outsideOuter, inside, insideInner;
let outerRing, innerRing, polygon, flatCoordinates;
let outsideOuter, inside, insideInner;
beforeEach(function() {
outerRing = [[0, 0, 1], [4, 4, 2], [4, 0, 3]];
innerRing = [[2, 1, 4], [3, 1, 5], [3, 2, 6]];
polygon = new Polygon(
[outerRing, innerRing], 'XYM');
[outerRing, innerRing], 'XYM');
flatCoordinates = [0, 0, 1, 4, 4, 2, 4, 0, 3, 2, 1, 4, 3, 1, 5, 3, 2, 6];
outsideOuter = [1, 3];
inside = [3.5, 0.5];
@@ -320,17 +320,17 @@ describe('ol/geom/Polygon', function() {
it('does not intersect outside extent', function() {
expect(polygon.intersectsExtent(
_ol_extent_.boundingExtent([outsideOuter]))).to.be(false);
_ol_extent_.boundingExtent([outsideOuter]))).to.be(false);
});
it('does intersect inside extent', function() {
expect(polygon.intersectsExtent(
_ol_extent_.boundingExtent([inside]))).to.be(true);
_ol_extent_.boundingExtent([inside]))).to.be(true);
});
it('does intersect boundary extent', function() {
var firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
var firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
const firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
const firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
expect(polygon.intersectsExtent(_ol_extent_.boundingExtent([[firstMidX,
firstMidY]]))).to.be(true);
@@ -338,7 +338,7 @@ describe('ol/geom/Polygon', function() {
it('does not intersect extent fully contained by inner ring', function() {
expect(polygon.intersectsExtent(
_ol_extent_.boundingExtent([insideInner]))).to.be(false);
_ol_extent_.boundingExtent([insideInner]))).to.be(false);
});
});
@@ -370,8 +370,8 @@ describe('ol/geom/Polygon', function() {
describe('construct with 4D coordinates', function() {
var outerRing, innerRing1, innerRing2, polygon, flatCoordinates;
var outsideOuter, inside, insideInner1, insideInner2;
let outerRing, innerRing1, innerRing2, polygon, flatCoordinates;
let outsideOuter, inside, insideInner1, insideInner2;
beforeEach(function() {
outerRing = [[0, 6, 1, 2], [6, 6, 3, 4], [3, 0, 5, 6]];
innerRing1 =
@@ -395,7 +395,7 @@ describe('ol/geom/Polygon', function() {
it('has the expected coordinates', function() {
expect(polygon.getCoordinates()).to.eql(
[outerRing, innerRing1, innerRing2]);
[outerRing, innerRing1, innerRing2]);
});
it('has the expected extent', function() {
@@ -427,17 +427,17 @@ describe('ol/geom/Polygon', function() {
it('does not intersect outside extent', function() {
expect(polygon.intersectsExtent(
_ol_extent_.boundingExtent([outsideOuter]))).to.be(false);
_ol_extent_.boundingExtent([outsideOuter]))).to.be(false);
});
it('does intersect inside extent', function() {
expect(polygon.intersectsExtent(
_ol_extent_.boundingExtent([inside]))).to.be(true);
_ol_extent_.boundingExtent([inside]))).to.be(true);
});
it('does intersect boundary extent', function() {
var firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
var firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
const firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
const firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
expect(polygon.intersectsExtent(_ol_extent_.boundingExtent([[firstMidX,
firstMidY]]))).to.be(true);
@@ -445,9 +445,9 @@ describe('ol/geom/Polygon', function() {
it('does not intersect extent fully contained by inner ring', function() {
expect(polygon.intersectsExtent(
_ol_extent_.boundingExtent([insideInner1]))).to.be(false);
_ol_extent_.boundingExtent([insideInner1]))).to.be(false);
expect(polygon.intersectsExtent(
_ol_extent_.boundingExtent([insideInner2]))).to.be(false);
_ol_extent_.boundingExtent([insideInner2]))).to.be(false);
});
});
@@ -481,26 +481,26 @@ describe('ol/geom/Polygon', function() {
describe('with a simple polygon', function() {
var polygon;
let polygon;
beforeEach(function() {
polygon = new Polygon(
[[[3, 0], [1, 3], [0, 6], [2, 6], [3, 7], [4, 6], [6, 6], [4, 3]]]);
[[[3, 0], [1, 3], [0, 6], [2, 6], [3, 7], [4, 6], [6, 6], [4, 3]]]);
});
describe('#getSimplifiedGeometry', function() {
it('returns the expected result', function() {
var simplifiedGeometry = polygon.getSimplifiedGeometry(9);
const simplifiedGeometry = polygon.getSimplifiedGeometry(9);
expect(simplifiedGeometry).to.be.an(Polygon);
expect(simplifiedGeometry.getCoordinates()).to.eql(
[[[3, 0], [0, 3], [0, 6], [6, 6], [3, 3]]]);
[[[3, 0], [0, 3], [0, 6], [6, 6], [3, 3]]]);
});
it('caches multiple simplified geometries', function() {
var simplifiedGeometry1 = polygon.getSimplifiedGeometry(4);
var simplifiedGeometry2 = polygon.getSimplifiedGeometry(9);
var simplifiedGeometry3 = polygon.getSimplifiedGeometry(4);
var simplifiedGeometry4 = polygon.getSimplifiedGeometry(9);
const simplifiedGeometry1 = polygon.getSimplifiedGeometry(4);
const simplifiedGeometry2 = polygon.getSimplifiedGeometry(9);
const simplifiedGeometry3 = polygon.getSimplifiedGeometry(4);
const simplifiedGeometry4 = polygon.getSimplifiedGeometry(9);
expect(simplifiedGeometry1).to.be(simplifiedGeometry3);
expect(simplifiedGeometry2).to.be(simplifiedGeometry4);
});
@@ -511,29 +511,29 @@ describe('ol/geom/Polygon', function() {
describe('#scale()', function() {
it('scales a polygon', function() {
var geom = new Polygon([
const geom = new Polygon([
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
]);
geom.scale(10);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-10, -20], [10, -20], [10, 20], [-10, 20], [-10, -20]]]);
});
it('accepts sx and sy', function() {
var geom = new Polygon([
const geom = new Polygon([
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
]);
geom.scale(2, 3);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-2, -6], [2, -6], [2, 6], [-2, 6], [-2, -6]]]);
});
it('accepts an anchor', function() {
var geom = new Polygon([
const geom = new Polygon([
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
]);
geom.scale(3, 2, [-1, -2]);
var coordinates = geom.getCoordinates();
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-1, -2], [5, -2], [5, 6], [-1, 6], [-1, -2]]]);
});
@@ -542,19 +542,19 @@ describe('ol/geom/Polygon', function() {
describe('#getInteriorPoint', function() {
it('returns XYM point with intersection width as M', function() {
var geom = new Polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]);
var interiorPoint = geom.getInteriorPoint();
const geom = new Polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]);
const interiorPoint = geom.getInteriorPoint();
expect(interiorPoint.getType()).to.be('Point');
expect(interiorPoint.layout).to.be('XYM');
expect(interiorPoint.getCoordinates()).to.eql([0.5, 0.5, 1]);
});
it('returns XYM point for donut polygons', function() {
var geom = new Polygon([
const geom = new Polygon([
[[0.5, 0.5], [0.5, 2.5], [2.5, 2.5], [2.5, 0.5], [0.5, 0.5]],
[[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]
]);
var interiorPoint = geom.getInteriorPoint();
const interiorPoint = geom.getInteriorPoint();
expect(interiorPoint.getType()).to.be('Point');
expect(interiorPoint.layout).to.be('XYM');
expect(interiorPoint.getCoordinates()).to.eql([0.75, 1.5, 0.5]);
@@ -563,23 +563,23 @@ describe('ol/geom/Polygon', function() {
describe('fromExtent()', function() {
it('creates the correct polygon', function() {
var extent = [1, 2, 3, 5];
var polygon = fromExtent(extent);
var flatCoordinates = polygon.getFlatCoordinates();
const extent = [1, 2, 3, 5];
const polygon = fromExtent(extent);
const flatCoordinates = polygon.getFlatCoordinates();
expect(flatCoordinates).to.eql(
[1, 2, 1, 5, 3, 5, 3, 2, 1, 2]);
var orientedFlatCoordinates = polygon.getOrientedFlatCoordinates();
[1, 2, 1, 5, 3, 5, 3, 2, 1, 2]);
const orientedFlatCoordinates = polygon.getOrientedFlatCoordinates();
expect(orientedFlatCoordinates).to.eql(
[1, 2, 1, 5, 3, 5, 3, 2, 1, 2]);
[1, 2, 1, 5, 3, 5, 3, 2, 1, 2]);
});
});
describe('fromCircle()', function() {
it('creates a regular polygon', function() {
var circle = new Circle([0, 0, 0], 1, 'XYZ');
var polygon = fromCircle(circle);
var coordinates = polygon.getLinearRing(0).getCoordinates();
const circle = new Circle([0, 0, 0], 1, 'XYZ');
const polygon = fromCircle(circle);
const coordinates = polygon.getLinearRing(0).getCoordinates();
expect(coordinates[0].length).to.eql(3);
expect(coordinates[0][2]).to.eql(0);
expect(coordinates[32]).to.eql(coordinates[0]);
@@ -598,9 +598,9 @@ describe('ol/geom/Polygon', function() {
});
it('creates a regular polygon with custom sides and angle', function() {
var circle = new Circle([0, 0], 1);
var polygon = fromCircle(circle, 4, Math.PI / 2);
var coordinates = polygon.getLinearRing(0).getCoordinates();
const circle = new Circle([0, 0], 1);
const polygon = fromCircle(circle, 4, Math.PI / 2);
const coordinates = polygon.getLinearRing(0).getCoordinates();
expect(coordinates[4]).to.eql(coordinates[0]);
expect(coordinates[0][0]).to.roughlyEqual(0, 1e-9);
expect(coordinates[0][1]).to.roughlyEqual(1, 1e-9);