Make code prettier

This updates ESLint and our shared eslint-config-openlayers to use Prettier.  Most formatting changes were automatically applied with this:

    npm run lint -- --fix

A few manual changes were required:

 * In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
 * In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason.  While editing this, I reworked `ExampleBuilder` to be a class.
 * In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions
+65 -100
View File
@@ -1,67 +1,57 @@
import Circle from '../../../../src/ol/geom/Circle.js';
describe('ol.geom.Circle', function() {
describe('with a unit circle', function() {
describe('ol.geom.Circle', function () {
describe('with a unit circle', function () {
let circle;
beforeEach(function() {
beforeEach(function () {
circle = new Circle([0, 0], 1);
});
describe('#clone', function() {
it('returns a clone', function() {
describe('#clone', function () {
it('returns a clone', function () {
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());
expect(clone.getRadius()).to.be(circle.getRadius());
});
});
describe('#intersectsCoordinate', function() {
it('contains the center', function() {
describe('#intersectsCoordinate', function () {
it('contains the center', function () {
expect(circle.intersectsCoordinate([0, 0])).to.be(true);
});
it('contains points inside the perimeter', function() {
it('contains points inside the perimeter', function () {
expect(circle.intersectsCoordinate([0.5, 0.5])).to.be(true);
expect(circle.intersectsCoordinate([-0.5, 0.5])).to.be(true);
expect(circle.intersectsCoordinate([-0.5, -0.5])).to.be(true);
expect(circle.intersectsCoordinate([0.5, -0.5])).to.be(true);
});
it('contains points on the perimeter', function() {
it('contains points on the perimeter', function () {
expect(circle.intersectsCoordinate([1, 0])).to.be(true);
expect(circle.intersectsCoordinate([0, 1])).to.be(true);
expect(circle.intersectsCoordinate([-1, 0])).to.be(true);
expect(circle.intersectsCoordinate([0, -1])).to.be(true);
});
it('does not contain points outside the perimeter', function() {
it('does not contain points outside the perimeter', function () {
expect(circle.intersectsCoordinate([2, 0])).to.be(false);
expect(circle.intersectsCoordinate([1, 1])).to.be(false);
expect(circle.intersectsCoordinate([-2, 0])).to.be(false);
expect(circle.intersectsCoordinate([0, -2])).to.be(false);
});
});
describe('#getCenter', function() {
it('returns the expected value', function() {
describe('#getCenter', function () {
it('returns the expected value', function () {
expect(circle.getCenter()).to.eql([0, 0]);
});
});
describe('#getClosestPoint', function() {
it('returns the closest point on the perimeter', function() {
describe('#getClosestPoint', function () {
it('returns the closest point on the perimeter', function () {
let closestPoint;
closestPoint = circle.getClosestPoint([2, 0]);
expect(closestPoint[0]).to.roughlyEqual(1, 1e-15);
@@ -89,7 +79,7 @@ describe('ol.geom.Circle', function() {
expect(closestPoint[1]).to.roughlyEqual(-Math.sqrt(0.5), 1e-15);
});
it('maintains Z coordinates', function() {
it('maintains Z coordinates', function () {
const circle = new Circle([0, 0, 1], 1);
expect(circle.getLayout()).to.be('XYZ');
const closestPoint = circle.getClosestPoint([2, 0]);
@@ -99,9 +89,8 @@ describe('ol.geom.Circle', function() {
expect(closestPoint[2]).to.be(1);
});
it('maintains M coordinates', function() {
const circle = new Circle([0, 0, 2], 1,
'XYM');
it('maintains M coordinates', function () {
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);
@@ -109,7 +98,7 @@ describe('ol.geom.Circle', function() {
expect(closestPoint[2]).to.be(2);
});
it('maintains Z and M coordinates', function() {
it('maintains Z and M coordinates', function () {
const circle = new Circle([0, 0, 1, 2], 1);
expect(circle.getLayout()).to.be('XYZM');
const closestPoint = circle.getClosestPoint([2, 0]);
@@ -119,112 +108,92 @@ describe('ol.geom.Circle', function() {
expect(closestPoint[2]).to.be(1);
expect(closestPoint[3]).to.be(2);
});
});
describe('#getExtent', function() {
it('returns the expected value', function() {
describe('#getExtent', function () {
it('returns the expected value', function () {
expect(circle.getExtent()).to.eql([-1, -1, 1, 1]);
});
});
describe('#getRadius', function() {
it('returns the expected value', function() {
describe('#getRadius', function () {
it('returns the expected value', function () {
expect(circle.getRadius()).to.be(1);
});
});
describe('#getSimplifiedGeometry', function() {
it('returns the same geometry', function() {
describe('#getSimplifiedGeometry', function () {
it('returns the same geometry', function () {
expect(circle.getSimplifiedGeometry(1)).to.be(circle);
});
});
describe('#getType', function() {
it('returns the expected value', function() {
describe('#getType', function () {
it('returns the expected value', function () {
expect(circle.getType()).to.be('Circle');
});
});
describe('#setCenter', function() {
it('sets the center', function() {
describe('#setCenter', function () {
it('sets the center', function () {
circle.setCenter([1, 2]);
expect(circle.getCenter()).to.eql([1, 2]);
});
it('fires a change event', function() {
it('fires a change event', function () {
const spy = sinon.spy();
circle.on('change', spy);
circle.setCenter([1, 2]);
expect(spy.calledOnce).to.be(true);
});
});
describe('#setFlatCoordinates', function() {
it('sets both center and radius', function() {
describe('#setFlatCoordinates', function () {
it('sets both center and radius', function () {
circle.setFlatCoordinates('XY', [1, 2, 4, 2]);
expect(circle.getCenter()).to.eql([1, 2]);
expect(circle.getRadius()).to.be(3);
});
});
describe('#setRadius', function() {
it('sets the radius', function() {
describe('#setRadius', function () {
it('sets the radius', function () {
circle.setRadius(2);
expect(circle.getRadius()).to.be(2);
});
it('fires a change event', function() {
it('fires a change event', function () {
const spy = sinon.spy();
circle.on('change', spy);
circle.setRadius(2);
expect(spy.calledOnce).to.be(true);
});
});
describe('#intersectsExtent', function() {
describe('#intersectsExtent', function () {
it('returns false for non-intersecting extents (wide outside own bbox)', 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 (wide outside own bbox)',
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 () {
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 false for non-intersecting extents (inside own bbox)',
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() {
it('returns true for extents that intersect clearly', function () {
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];
@@ -235,7 +204,7 @@ describe('ol.geom.Circle', function() {
expect(circle.intersectsExtent(intersectingLeftBottom)).to.be(true);
});
it('returns true for extents that touch the circumference', function() {
it('returns true for extents that touch the circumference', function () {
const touchCircumferenceLeft = [-2, 0, -1, 1];
const touchCircumferenceTop = [0, 1, 1, 2];
const touchCircumferenceRight = [1, -1, 2, 0];
@@ -246,33 +215,31 @@ describe('ol.geom.Circle', function() {
expect(circle.intersectsExtent(touchCircumferenceBottom)).to.be(true);
});
it('returns true for a contained extent', function() {
it('returns true for a contained extent', function () {
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() {
it('returns true for a covering extent', function () {
const bigCoveringExtent = [-5, -5, 5, 5];
expect(circle.intersectsExtent(bigCoveringExtent)).to.be(true);
});
it('returns true for the geom\'s own extent', function() {
it("returns true for the geom's own extent", function () {
const circleExtent = circle.getExtent();
expect(circle.intersectsExtent(circleExtent)).to.be(true);
});
});
describe('#rotate', function() {
it('rotates the center around the anchor', function() {
describe('#rotate', function () {
it('rotates the center around the anchor', function () {
circle.setCenter([1, 0]);
circle.rotate(Math.PI / 2, [2, 0]);
expect(circle.getCenter()).to.eql([2, -1]);
expect(circle.getExtent()).to.eql([1, -2, 3, 0]);
});
it('does not change if the anchor equals the center', function() {
it('does not change if the anchor equals the center', function () {
const center = [1, 0];
circle.setCenter(center);
const extent = circle.getExtent();
@@ -282,9 +249,8 @@ describe('ol.geom.Circle', function() {
});
});
describe('#translate', function() {
it('translates the circle', function() {
describe('#translate', function () {
it('translates the circle', function () {
circle.setCenter([1, 1]);
circle.translate(5, 10);
expect(circle.getCenter()).to.eql([6, 11]);
@@ -292,5 +258,4 @@ describe('ol.geom.Circle', function() {
});
});
});
});
+11 -13
View File
@@ -1,29 +1,27 @@
import {linearRing, linearRings} from '../../../../../src/ol/geom/flat/area.js';
describe('ol.geom.flat.area', function() {
describe('ol.geom.flat.area.linearRing', function() {
it('calculates the area of a triangle', function() {
describe('ol.geom.flat.area', function () {
describe('ol.geom.flat.area.linearRing', function () {
it('calculates the area of a triangle', function () {
const 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() {
it('calculates the area of a unit square', function () {
const area = linearRing([0, 0, 0, 1, 1, 1, 1, 0], 0, 8, 2);
expect(area).to.be(1);
});
});
describe('ol.geom.flat.area.linearRings', function() {
it('calculates the area with holes', function() {
describe('ol.geom.flat.area.linearRings', function () {
it('calculates the area with holes', function () {
const area = linearRings(
[0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 2, 1, 2, 2, 1, 2], 0, [8, 16], 2);
[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);
});
});
});
+50 -21
View File
@@ -1,15 +1,20 @@
import {linearRingss as linearRingssCenter} from '../../../../../src/ol/geom/flat/center.js';
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
import {linearRingss as linearRingssCenter} from '../../../../../src/ol/geom/flat/center.js';
describe('ol.geom.flat.center', function() {
describe('ol.geom.flat.center.linearRingss', function() {
it('calculates the center of a square', function() {
const squareMultiPoly = new MultiPolygon([[
[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]
]]);
describe('ol.geom.flat.center', function () {
describe('ol.geom.flat.center.linearRingss', function () {
it('calculates the center of a square', function () {
const squareMultiPoly = new MultiPolygon([
[
[
[0, 0],
[0, 1],
[1, 1],
[1, 0],
[0, 0],
],
],
]);
const got = linearRingssCenter(
squareMultiPoly.flatCoordinates,
0,
@@ -19,14 +24,26 @@ describe('ol.geom.flat.center', function() {
expect(got).to.eql([0.5, 0.5]);
});
it('calculates the centers of two squares', function() {
it('calculates the centers of two squares', function () {
const squareMultiPoly = new MultiPolygon([
[
[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]
[
[0, 0],
[0, 1],
[1, 1],
[1, 0],
[0, 0],
],
],
[
[[3, 0], [3, 1], [4, 1], [4, 0], [3, 0]]
]
[
[3, 0],
[3, 1],
[4, 1],
[4, 0],
[3, 0],
],
],
]);
const got = linearRingssCenter(
squareMultiPoly.flatCoordinates,
@@ -37,11 +54,25 @@ describe('ol.geom.flat.center', function() {
expect(got).to.eql([0.5, 0.5, 3.5, 0.5]);
});
it('does not care about holes', function() {
const polywithHole = new MultiPolygon([[
[[0, 0], [0, 5], [5, 5], [5, 0], [0, 0]],
[[1, 1], [1, 4], [4, 4], [4, 1], [1, 1]]
]]);
it('does not care about holes', function () {
const polywithHole = new MultiPolygon([
[
[
[0, 0],
[0, 5],
[5, 5],
[5, 0],
[0, 0],
],
[
[1, 1],
[1, 4],
[4, 4],
[4, 1],
[1, 1],
],
],
]);
const got = linearRingssCenter(
polywithHole.flatCoordinates,
0,
@@ -50,7 +81,5 @@ describe('ol.geom.flat.center', function() {
);
expect(got).to.eql([2.5, 2.5]);
});
});
});
+345 -98
View File
@@ -1,143 +1,390 @@
import {assignClosestPoint, maxSquaredDelta} from '../../../../../src/ol/geom/flat/closest.js';
describe('ol.geom.flat.closest', function() {
describe('with simple data', function() {
import {
assignClosestPoint,
maxSquaredDelta,
} from '../../../../../src/ol/geom/flat/closest.js';
describe('ol.geom.flat.closest', function () {
describe('with simple data', function () {
const flatCoordinates = [0, 0, 1, 0, 3, 0, 5, 0, 6, 0, 8, 0, 11, 0];
describe('ol.geom.flat.closest.maxSquaredDelta', function() {
it('returns the expected value in simple cases', function() {
expect(maxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0)).to.be(9);
describe('ol.geom.flat.closest.maxSquaredDelta', function () {
it('returns the expected value in simple cases', function () {
expect(
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
).to.be(9);
});
});
describe('ol.geom.flat.closest.assignClosestPoint', function() {
it('returns the expected value', function() {
const maxDelta = Math.sqrt(maxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0));
describe('ol.geom.flat.closest.assignClosestPoint', function () {
it('returns the expected value', function () {
const maxDelta = Math.sqrt(
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
);
expect(maxDelta).to.be(3);
const closestPoint = [NaN, NaN];
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 0, 0, closestPoint, Infinity)).to.be(0);
expect(
assignClosestPoint(
flatCoordinates,
0,
flatCoordinates.length,
2,
maxDelta,
false,
0,
0,
closestPoint,
Infinity
)
).to.be(0);
expect(closestPoint).to.eql([0, 0]);
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 4, 1, closestPoint, Infinity)).to.be(1);
expect(
assignClosestPoint(
flatCoordinates,
0,
flatCoordinates.length,
2,
maxDelta,
false,
4,
1,
closestPoint,
Infinity
)
).to.be(1);
expect(closestPoint).to.eql([4, 0]);
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 5, 2, closestPoint, Infinity)).to.be(4);
expect(
assignClosestPoint(
flatCoordinates,
0,
flatCoordinates.length,
2,
maxDelta,
false,
5,
2,
closestPoint,
Infinity
)
).to.be(4);
expect(closestPoint).to.eql([5, 0]);
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 10, 100, closestPoint, Infinity)).to.be(10000);
expect(
assignClosestPoint(
flatCoordinates,
0,
flatCoordinates.length,
2,
maxDelta,
false,
10,
100,
closestPoint,
Infinity
)
).to.be(10000);
expect(closestPoint).to.eql([10, 0]);
});
});
});
describe('with real data', function() {
describe('with real data', function () {
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,
292.41, 159.37, 296.91, 155.64, 314.95, 151.37, 319.75, 145.16,
330.33, 137.57, 341.48, 139.96, 369.98, 137.89, 387.39, 142.51,
391.28, 139.39, 409.52, 141.14, 414.82, 139.75, 427.72, 127.30,
439.60, 119.74, 474.93, 107.87, 486.51, 106.75, 489.20, 109.45,
493.79, 108.63, 504.74, 119.66, 512.96, 122.35, 518.63, 120.89,
524.09, 126.88, 529.57, 127.86, 534.21, 140.93, 539.27, 147.24,
567.69, 148.91, 575.25, 157.26, 580.62, 158.15, 601.53, 156.85,
617.74, 159.86, 622.00, 167.04, 629.55, 194.60, 638.90, 195.61,
641.26, 200.81, 651.77, 204.56, 671.55, 222.55, 683.68, 217.45,
695.25, 219.15, 700.64, 217.98, 703.12, 214.36, 712.26, 215.87,
721.49, 212.81, 727.81, 213.36, 729.98, 208.73, 735.32, 208.20,
739.94, 204.77, 769.98, 208.42, 779.60, 216.87, 784.20, 218.16,
800.24, 214.62, 810.53, 219.73, 817.19, 226.82, 820.77, 236.17,
827.23, 236.16, 829.89, 239.89, 851.00, 248.94, 859.88, 255.49,
865.21, 268.53, 857.95, 280.30, 865.48, 291.45, 866.81, 298.66,
864.68, 302.71, 867.79, 306.17, 859.87, 311.37, 860.08, 314.35,
858.29, 314.94, 858.10, 327.60, 854.54, 335.40, 860.92, 343.00,
856.43, 350.15, 851.42, 352.96, 849.84, 359.59, 854.56, 365.53,
849.74, 370.38, 844.09, 371.89, 844.75, 380.44, 841.52, 383.67,
839.57, 390.40, 845.59, 399.05, 848.40, 407.55, 843.71, 411.30,
844.09, 419.88, 839.51, 432.76, 841.33, 441.04, 847.62, 449.22,
847.16, 458.44, 851.38, 462.79, 853.97, 471.15, 866.36, 480.77
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,
292.41,
159.37,
296.91,
155.64,
314.95,
151.37,
319.75,
145.16,
330.33,
137.57,
341.48,
139.96,
369.98,
137.89,
387.39,
142.51,
391.28,
139.39,
409.52,
141.14,
414.82,
139.75,
427.72,
127.3,
439.6,
119.74,
474.93,
107.87,
486.51,
106.75,
489.2,
109.45,
493.79,
108.63,
504.74,
119.66,
512.96,
122.35,
518.63,
120.89,
524.09,
126.88,
529.57,
127.86,
534.21,
140.93,
539.27,
147.24,
567.69,
148.91,
575.25,
157.26,
580.62,
158.15,
601.53,
156.85,
617.74,
159.86,
622.0,
167.04,
629.55,
194.6,
638.9,
195.61,
641.26,
200.81,
651.77,
204.56,
671.55,
222.55,
683.68,
217.45,
695.25,
219.15,
700.64,
217.98,
703.12,
214.36,
712.26,
215.87,
721.49,
212.81,
727.81,
213.36,
729.98,
208.73,
735.32,
208.2,
739.94,
204.77,
769.98,
208.42,
779.6,
216.87,
784.2,
218.16,
800.24,
214.62,
810.53,
219.73,
817.19,
226.82,
820.77,
236.17,
827.23,
236.16,
829.89,
239.89,
851.0,
248.94,
859.88,
255.49,
865.21,
268.53,
857.95,
280.3,
865.48,
291.45,
866.81,
298.66,
864.68,
302.71,
867.79,
306.17,
859.87,
311.37,
860.08,
314.35,
858.29,
314.94,
858.1,
327.6,
854.54,
335.4,
860.92,
343.0,
856.43,
350.15,
851.42,
352.96,
849.84,
359.59,
854.56,
365.53,
849.74,
370.38,
844.09,
371.89,
844.75,
380.44,
841.52,
383.67,
839.57,
390.4,
845.59,
399.05,
848.4,
407.55,
843.71,
411.3,
844.09,
419.88,
839.51,
432.76,
841.33,
441.04,
847.62,
449.22,
847.16,
458.44,
851.38,
462.79,
853.97,
471.15,
866.36,
480.77,
];
describe('ol.geom.closest.maxSquaredDelta', function() {
it('returns the expected value', function() {
expect(maxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0)).
to.roughlyEqual(1389.1058, 1e-9);
describe('ol.geom.closest.maxSquaredDelta', function () {
it('returns the expected value', function () {
expect(
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
).to.roughlyEqual(1389.1058, 1e-9);
});
});
describe('ol.geom.flat.closest.assignClosestPoint', function() {
it('returns the expected value', function() {
const maxDelta = Math.sqrt(maxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, 2, 0));
describe('ol.geom.flat.closest.assignClosestPoint', function () {
it('returns the expected value', function () {
const maxDelta = Math.sqrt(
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
);
expect(maxDelta).to.roughlyEqual(Math.sqrt(1389.1058), 1e-9);
const closestPoint = [NaN, NaN];
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 0, 0, closestPoint, Infinity)).
to.roughlyEqual(110902.405, 1e-9);
expect(
assignClosestPoint(
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(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 500, 500, closestPoint, Infinity)).
to.roughlyEqual(106407.905, 1e-9);
expect(
assignClosestPoint(
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(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, 2,
maxDelta, false, 1000, 500, closestPoint, Infinity)).
to.roughlyEqual(18229.4425, 1e-9);
expect(
assignClosestPoint(
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]);
});
});
});
describe('with multi-dimensional data', function() {
describe('with multi-dimensional data', function () {
const flatCoordinates = [0, 0, 10, -10, 2, 2, 30, -20];
const stride = 4;
describe('ol.geom.flat.closest.assignClosestPoint', function() {
it('interpolates M coordinates', function() {
const maxDelta = Math.sqrt(maxSquaredDelta(
flatCoordinates, 0, flatCoordinates.length, stride, 0));
describe('ol.geom.flat.closest.assignClosestPoint', function () {
it('interpolates M coordinates', function () {
const maxDelta = Math.sqrt(
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, stride, 0)
);
expect(maxDelta).to.roughlyEqual(Math.sqrt(8), 1e-9);
const closestPoint = [NaN, NaN];
expect(assignClosestPoint(
flatCoordinates, 0, flatCoordinates.length, stride,
maxDelta, false, 1, 1, closestPoint, Infinity)).
to.roughlyEqual(0, 1e-9);
expect(
assignClosestPoint(
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);
expect(closestPoint[2]).to.be(20);
expect(closestPoint[3]).to.be(-15);
});
});
});
});
+80 -24
View File
@@ -1,40 +1,96 @@
import {linearRingContainsXY} from '../../../../../src/ol/geom/flat/contains.js';
describe('ol.geom.flat.contains', function() {
describe('with simple data', function() {
describe('ol.geom.flat.contains', function () {
describe('with simple data', function () {
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];
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(linearRingContainsXY(
flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 0.5, 0.5)).to.be(true);
describe('ol.geom.flat.contains.linearRingContainsXY', function () {
it('returns true for point inside a simple polygon', function () {
expect(
linearRingContainsXY(
flatCoordinatesSimple,
0,
flatCoordinatesSimple.length,
2,
0.5,
0.5
)
).to.be(true);
});
it('returns false for point outside a simple polygon', function() {
expect(linearRingContainsXY(
flatCoordinatesSimple, 0, flatCoordinatesSimple.length, 2, 1.5, 1.5)).to.be(false);
it('returns false for point outside a simple polygon', function () {
expect(
linearRingContainsXY(
flatCoordinatesSimple,
0,
flatCoordinatesSimple.length,
2,
1.5,
1.5
)
).to.be(false);
});
it('returns true for point inside a non-simple polygon', function() {
expect(linearRingContainsXY(
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1, 1)).to.be(true);
it('returns true for point inside a non-simple polygon', function () {
expect(
linearRingContainsXY(
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(linearRingContainsXY(
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 1.5, 2.5)).to.be(true);
it('returns true for point inside an overlap of a non-simple polygon', function () {
expect(
linearRingContainsXY(
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(linearRingContainsXY(
flatCoordinatesNonSimple, 0, flatCoordinatesNonSimple.length, 2, 2.5, 1.5)).to.be(false);
it('returns false for a point inside a hole of a non-simple polygon', function () {
expect(
linearRingContainsXY(
flatCoordinatesNonSimple,
0,
flatCoordinatesNonSimple.length,
2,
2.5,
1.5
)
).to.be(false);
});
});
});
});
+34 -18
View File
@@ -1,38 +1,54 @@
import {deflateCoordinates, deflateCoordinatesArray} from '../../../../../src/ol/geom/flat/deflate.js';
describe('ol.geom.flat.deflate', function() {
describe('ol.geom.flat.deflate.deflateCoordinates', function() {
import {
deflateCoordinates,
deflateCoordinatesArray,
} from '../../../../../src/ol/geom/flat/deflate.js';
describe('ol.geom.flat.deflate', function () {
describe('ol.geom.flat.deflate.deflateCoordinates', function () {
let flatCoordinates;
beforeEach(function() {
beforeEach(function () {
flatCoordinates = [];
});
it('flattens coordinates', function() {
it('flattens coordinates', function () {
const offset = deflateCoordinates(
flatCoordinates, 0, [[1, 2], [3, 4]], 2);
flatCoordinates,
0,
[
[1, 2],
[3, 4],
],
2
);
expect(offset).to.be(4);
expect(flatCoordinates).to.eql([1, 2, 3, 4]);
});
});
describe('ol.geom.flat.deflate.deflateCoordinatesArray', function() {
describe('ol.geom.flat.deflate.deflateCoordinatesArray', function () {
let flatCoordinates;
beforeEach(function() {
beforeEach(function () {
flatCoordinates = [];
});
it('flattens arrays of coordinates', function() {
const ends = deflateCoordinatesArray(flatCoordinates, 0,
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], 2);
it('flattens arrays of coordinates', function () {
const ends = deflateCoordinatesArray(
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]);
});
});
});
+15 -17
View File
@@ -1,33 +1,31 @@
import {flipXY} from '../../../../../src/ol/geom/flat/flip.js';
describe('ol.geom.flat.flip', function() {
describe('ol.geom.flat.flip.flipXY', function() {
it('can flip XY coordinates', function() {
describe('ol.geom.flat.flip', function () {
describe('ol.geom.flat.flip.flipXY', function () {
it('can flip XY coordinates', function () {
const flatCoordinates = 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() {
it('can flip XY coordinates while preserving other dimensions', function () {
const flatCoordinates = 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() {
it('can flip XY coordinates in place', function () {
const flatCoordinates = [1, 2, 3, 4];
expect(flipXY(flatCoordinates, 0, 4, 2, flatCoordinates)).to.be(flatCoordinates);
expect(flipXY(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() {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
expect(flipXY(flatCoordinates, 0, 9, 3, flatCoordinates)).to.be(flatCoordinates);
expect(flatCoordinates).to.eql([2, 1, 3, 5, 4, 6, 8, 7, 9]);
});
it('can flip XY coordinates in place while preserving other dimensions', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
expect(flipXY(flatCoordinates, 0, 9, 3, flatCoordinates)).to.be(
flatCoordinates
);
expect(flatCoordinates).to.eql([2, 1, 3, 5, 4, 6, 8, 7, 9]);
});
});
});
+28 -16
View File
@@ -1,25 +1,37 @@
import {inflateCoordinates, inflateCoordinatesArray} from '../../../../../src/ol/geom/flat/inflate.js';
import {
inflateCoordinates,
inflateCoordinatesArray,
} from '../../../../../src/ol/geom/flat/inflate.js';
describe('ol.geom.flat.inflate', function() {
describe('ol.geom.flat.inflate.inflateCoordinates', function() {
it('inflates coordinates', function() {
describe('ol.geom.flat.inflate', function () {
describe('ol.geom.flat.inflate.inflateCoordinates', function () {
it('inflates coordinates', function () {
const coordinates = inflateCoordinates([1, 2, 3, 4], 0, 4, 2);
expect(coordinates).to.eql([[1, 2], [3, 4]]);
expect(coordinates).to.eql([
[1, 2],
[3, 4],
]);
});
});
describe('ol.geom.flat.inflate.inflateCoordinatesArray', function() {
it('inflates arrays of coordinates', function() {
describe('ol.geom.flat.inflate.inflateCoordinatesArray', function () {
it('inflates arrays of coordinates', function () {
const coordinatess = inflateCoordinatesArray(
[1, 2, 3, 4, 5, 6, 7, 8], 0, [4, 8], 2);
expect(coordinatess).to.eql([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
[1, 2, 3, 4, 5, 6, 7, 8],
0,
[4, 8],
2
);
expect(coordinatess).to.eql([
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]);
});
});
});
+41 -54
View File
@@ -1,80 +1,67 @@
import {interpolatePoint} from '../../../../../src/ol/geom/flat/interpolate.js';
describe('ol.geom.flat.interpolate', function() {
describe('ol.geom.flat.interpolate.interpolatePoint', function() {
it('returns the expected value for single points', function() {
describe('ol.geom.flat.interpolate', function () {
describe('ol.geom.flat.interpolate.interpolatePoint', function () {
it('returns the expected value for single points', function () {
const flatCoordinates = [0, 1];
const point =
interpolatePoint(flatCoordinates, 0, 2, 2, 0.5);
const point = interpolatePoint(flatCoordinates, 0, 2, 2, 0.5);
expect(point).to.eql([0, 1]);
});
it('returns the expected value for simple line segments', function() {
it('returns the expected value for simple line segments', function () {
const flatCoordinates = [0, 1, 2, 3];
const point =
interpolatePoint(flatCoordinates, 0, 4, 2, 0.5);
const point = interpolatePoint(flatCoordinates, 0, 4, 2, 0.5);
expect(point).to.eql([1, 2]);
});
it('returns the expected value when the mid point is an existing ' +
it(
'returns the expected value when the mid point is an existing ' +
'coordinate',
function() {
const flatCoordinates = [0, 1, 2, 3, 4, 5];
const point = interpolatePoint(
flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([2, 3]);
});
function () {
const flatCoordinates = [0, 1, 2, 3, 4, 5];
const point = interpolatePoint(flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([2, 3]);
}
);
it('also when vertices are repeated', function() {
it('also when vertices are repeated', function () {
const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5];
const point = interpolatePoint(
flatCoordinates, 0, 8, 2, 0.5);
const point = interpolatePoint(flatCoordinates, 0, 8, 2, 0.5);
expect(point).to.eql([2, 3]);
});
it('returns the expected value when the midpoint falls halfway between ' +
it(
'returns the expected value when the midpoint falls halfway between ' +
'two existing coordinates',
function() {
const flatCoordinates = [0, 1, 2, 3, 4, 5, 6, 7];
const point = interpolatePoint(
flatCoordinates, 0, 8, 2, 0.5);
expect(point).to.eql([3, 4]);
});
function () {
const flatCoordinates = [0, 1, 2, 3, 4, 5, 6, 7];
const point = interpolatePoint(flatCoordinates, 0, 8, 2, 0.5);
expect(point).to.eql([3, 4]);
}
);
it('also when vertices are repeated', function() {
it('also when vertices are repeated', function () {
const flatCoordinates = [0, 1, 2, 3, 2, 3, 4, 5, 6, 7];
const point = interpolatePoint(
flatCoordinates, 0, 10, 2, 0.5);
const point = interpolatePoint(flatCoordinates, 0, 10, 2, 0.5);
expect(point).to.eql([3, 4]);
});
it('returns the expected value when the coordinates are not evenly spaced',
function() {
const flatCoordinates = [0, 1, 2, 3, 6, 7];
const point = interpolatePoint(
flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([3, 4]);
});
it('returns the expected value when the coordinates are not evenly spaced', function () {
const flatCoordinates = [0, 1, 2, 3, 6, 7];
const point = interpolatePoint(flatCoordinates, 0, 6, 2, 0.5);
expect(point).to.eql([3, 4]);
});
it('also when vertices are repeated',
function() {
const flatCoordinates = [0, 1, 2, 3, 2, 3, 6, 7];
const point = interpolatePoint(
flatCoordinates, 0, 8, 2, 0.5);
expect(point).to.eql([3, 4]);
});
it('returns the expected value when using opt_dest',
function() {
const flatCoordinates = [0, 1, 2, 3, 6, 7];
const point = interpolatePoint(
flatCoordinates, 0, 6, 2, 0.5, [0, 0]);
expect(point).to.eql([3, 4]);
});
it('also when vertices are repeated', function () {
const flatCoordinates = [0, 1, 2, 3, 2, 3, 6, 7];
const point = interpolatePoint(flatCoordinates, 0, 8, 2, 0.5);
expect(point).to.eql([3, 4]);
});
it('returns the expected value when using opt_dest', function () {
const flatCoordinates = [0, 1, 2, 3, 6, 7];
const point = interpolatePoint(flatCoordinates, 0, 6, 2, 0.5, [0, 0]);
expect(point).to.eql([3, 4]);
});
});
});
+139 -55
View File
@@ -1,118 +1,202 @@
import {intersectsLinearRing, intersectsLineString, intersectsLinearRingArray} from '../../../../../src/ol/geom/flat/intersectsextent.js';
import {
intersectsLineString,
intersectsLinearRing,
intersectsLinearRingArray,
} from '../../../../../src/ol/geom/flat/intersectsextent.js';
describe('ol.geom.flat.intersectsextent', function() {
describe('ol.geom.flat.intersectsextent.intersectsLineString', function() {
describe('ol.geom.flat.intersectsextent', function () {
describe('ol.geom.flat.intersectsextent.intersectsLineString', function () {
let flatCoordinates;
beforeEach(function() {
beforeEach(function () {
flatCoordinates = [0, 0, 1, 1, 2, 2];
});
describe('linestring envelope does not intersect the extent', function() {
it('returns false', function() {
describe('linestring envelope does not intersect the extent', function () {
it('returns false', function () {
const extent = [3, 3, 4, 4];
const r = intersectsLineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(false);
});
});
describe('linestring envelope within the extent', function() {
it('returns true', function() {
describe('linestring envelope within the extent', function () {
it('returns true', function () {
const extent = [-1, -1, 3, 3];
const r = intersectsLineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
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() {
const extent = [-0.1, 0.1, 2.1, 0.1];
const r = intersectsLineString(
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 () {
const extent = [-0.1, 0.1, 2.1, 0.1];
const r = intersectsLineString(
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(true);
});
describe('a segment intersects the extent', function() {
it('returns true', function() {
});
describe('a segment intersects the extent', function () {
it('returns true', function () {
const extent = [-0.5, -0.5, 0.5, 0.5];
const r = intersectsLineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(true);
});
});
describe('no segments intersect the extent', function() {
it('returns false', function() {
describe('no segments intersect the extent', function () {
it('returns false', function () {
const extent = [0.5, 1.5, 1, 1.75];
const r = intersectsLineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(false);
});
it('returns false', function() {
it('returns false', function () {
const extent = [1, 0.25, 1.5, 0.5];
const r = intersectsLineString(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(false);
});
});
});
describe('ol.geom.flat.intersectsextent.intersectsLinearRing', function() {
describe('ol.geom.flat.intersectsextent.intersectsLinearRing', function () {
let flatCoordinates;
beforeEach(function() {
beforeEach(function () {
flatCoordinates = [0, 0, 1, 1, 2, 0, 1, -1, 0, 0];
});
describe('boundary intersects the extent', function() {
it('returns true', function() {
describe('boundary intersects the extent', function () {
it('returns true', function () {
const extent = [1.5, 0.0, 2.5, 1.0];
const r = intersectsLinearRing(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(true);
});
});
describe('boundary does not intersect the extent and ring does not ' +
describe(
'boundary does not intersect the extent and ring does not ' +
'contain a corner of the extent',
function() {
it('returns false', function() {
const extent = [2.0, 0.5, 3, 1.5];
const r = intersectsLinearRing(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
expect(r).to.be(false);
});
});
describe('ring contains the extent', function() {
it('returns true', function() {
function () {
it('returns false', function () {
const extent = [2.0, 0.5, 3, 1.5];
const r = intersectsLinearRing(
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(false);
});
}
);
describe('ring contains the extent', function () {
it('returns true', function () {
const extent = [0.75, -0.25, 1.25, 0.25];
const r = intersectsLinearRing(
flatCoordinates, 0, flatCoordinates.length, 2, extent);
flatCoordinates,
0,
flatCoordinates.length,
2,
extent
);
expect(r).to.be(true);
});
});
});
describe('ol.geom.flat.intersectsextent.intersectsLinearRingArray', function() {
describe('ol.geom.flat.intersectsextent.intersectsLinearRingArray', function () {
let flatCoordinates;
let ends;
beforeEach(function() {
flatCoordinates = [0, 0, 0, 10, 10, 10, 10, 0, 0, 0, /*hole*/2, 2, 8, 2, 8, 4, 5, 5, 8, 6, 8, 8, 2, 8, 2, 2];
beforeEach(function () {
flatCoordinates = [
0,
0,
0,
10,
10,
10,
10,
0,
0,
0,
/*hole*/ 2,
2,
8,
2,
8,
4,
5,
5,
8,
6,
8,
8,
2,
8,
2,
2,
];
ends = [10, flatCoordinates.length];
});
describe('ring with hole where hole contains the extent', function() {
it('returns true', function() {
describe('ring with hole where hole contains the extent', function () {
it('returns true', function () {
const extent = [3, 3, 3.5, 3.5];
const r = intersectsLinearRingArray(
flatCoordinates, 0, ends, 2, extent);
flatCoordinates,
0,
ends,
2,
extent
);
expect(r).to.be(false);
});
});
describe('ring with hole intersects the extent', function() {
it('returns true', function() {
describe('ring with hole intersects the extent', function () {
it('returns true', function () {
const extent = [3, 3, 6, 6];
const r = intersectsLinearRingArray(
flatCoordinates, 0, ends, 2, extent);
flatCoordinates,
0,
ends,
2,
extent
);
expect(r).to.be(true);
});
});
});
});
+17 -22
View File
@@ -1,15 +1,15 @@
import {lineStringLength, linearRingLength} from '../../../../../src/ol/geom/flat/length.js';
import {
lineStringLength,
linearRingLength,
} from '../../../../../src/ol/geom/flat/length.js';
describe('ol.geom.flat.length', function() {
describe('ol.geom.flat.length.lineStringLength', function() {
describe('stride = 2', function() {
describe('ol.geom.flat.length', function () {
describe('ol.geom.flat.length.lineStringLength', function () {
describe('stride = 2', function () {
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
const stride = 2;
it('calculates the total length of a lineString', function() {
it('calculates the total length of a lineString', function () {
const offset = 0;
const end = 8;
const expected = 3;
@@ -17,7 +17,7 @@ describe('ol.geom.flat.length', function() {
expect(got).to.be(expected);
});
it('calculates a partwise length of a lineString (offset)', function() {
it('calculates a partwise length of a lineString (offset)', function () {
const offset = 2;
const end = 8;
const expected = 2;
@@ -25,21 +25,20 @@ describe('ol.geom.flat.length', function() {
expect(got).to.be(expected);
});
it('calculates a partwise length of a lineString (end)', function() {
it('calculates a partwise length of a lineString (end)', function () {
const offset = 0;
const end = 4;
const expected = 1;
const got = lineStringLength(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
});
describe('stride = 3', function() {
describe('stride = 3', function () {
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() {
it('calculates the total length of a lineString', function () {
const offset = 0;
const end = 12;
const expected = 3;
@@ -47,7 +46,7 @@ describe('ol.geom.flat.length', function() {
expect(got).to.be(expected);
});
it('calculates a partwise length of a lineString (offset)', function() {
it('calculates a partwise length of a lineString (offset)', function () {
const offset = 3;
const end = 12;
const expected = 2;
@@ -55,20 +54,18 @@ describe('ol.geom.flat.length', function() {
expect(got).to.be(expected);
});
it('calculates a partwise length of a lineString (end)', function() {
it('calculates a partwise length of a lineString (end)', function () {
const offset = 0;
const end = 6;
const expected = 1;
const got = lineStringLength(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
});
});
describe('ol.geom.flat.length.linearRingLength', function() {
it('calculates the total length of a simple linearRing', function() {
describe('ol.geom.flat.length.linearRingLength', function () {
it('calculates the total length of a simple linearRing', function () {
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
const stride = 2;
const offset = 0;
@@ -78,7 +75,7 @@ describe('ol.geom.flat.length', function() {
expect(got).to.be(expected);
});
it('calculates the total length of a figure-8 linearRing', function() {
it('calculates the total length of a figure-8 linearRing', function () {
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1, 0, -1, -1, -1, -1, 0];
const stride = 2;
const offset = 0;
@@ -87,7 +84,5 @@ describe('ol.geom.flat.length', function() {
const got = linearRingLength(flatCoords, offset, end, stride);
expect(got).to.be(expected);
});
});
});
+281 -56
View File
@@ -1,101 +1,255 @@
import {linearRingIsClockwise, linearRingsAreOriented,
linearRingssAreOriented, orientLinearRings, orientLinearRingsArray} from '../../../../../src/ol/geom/flat/orient.js';
import {
linearRingIsClockwise,
linearRingsAreOriented,
linearRingssAreOriented,
orientLinearRings,
orientLinearRingsArray,
} from '../../../../../src/ol/geom/flat/orient.js';
describe('ol.geom.flat.orient', function() {
describe('ol.geom.flat.orient.linearRingIsClockwise', function() {
it('identifies clockwise rings', function() {
describe('ol.geom.flat.orient', function () {
describe('ol.geom.flat.orient.linearRingIsClockwise', function () {
it('identifies clockwise rings', function () {
const flatCoordinates = [0, 1, 1, 4, 4, 3, 3, 0];
const isClockwise = linearRingIsClockwise(
flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates,
0,
flatCoordinates.length,
2
);
expect(isClockwise).to.be(true);
});
it('identifies anti-clockwise rings', function() {
it('identifies anti-clockwise rings', function () {
const flatCoordinates = [2, 2, 3, 2, 3, 3, 2, 3];
const isClockwise = linearRingIsClockwise(
flatCoordinates, 0, flatCoordinates.length, 2);
flatCoordinates,
0,
flatCoordinates.length,
2
);
expect(isClockwise).to.be(false);
});
});
describe('ol.geom.flat.orient.linearRingsAreOriented', function() {
describe('ol.geom.flat.orient.linearRingsAreOriented', function () {
const oriented = linearRingsAreOriented;
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,
];
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,
];
const ends = [10, 20];
it('checks for left-hand orientation by default', function() {
it('checks for left-hand orientation by default', function () {
expect(oriented(rightCoords, 0, ends, 2)).to.be(false);
expect(oriented(leftCoords, 0, ends, 2)).to.be(true);
});
it('can check for right-hand orientation', function() {
it('can check for right-hand orientation', function () {
expect(oriented(rightCoords, 0, ends, 2, true)).to.be(true);
expect(oriented(leftCoords, 0, ends, 2, true)).to.be(false);
});
});
describe('ol.geom.flat.orient.linearRingssAreOriented', function() {
describe('ol.geom.flat.orient.linearRingssAreOriented', function () {
const oriented = linearRingssAreOriented;
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
-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,
];
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
-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,
];
const ends = [[10, 20], [30, 40]];
const ends = [
[10, 20],
[30, 40],
];
it('checks for left-hand orientation by default', function() {
it('checks for left-hand orientation by default', function () {
expect(oriented(rightCoords, 0, ends, 2)).to.be(false);
expect(oriented(leftCoords, 0, ends, 2)).to.be(true);
});
it('can check for right-hand orientation', function() {
it('can check for right-hand orientation', function () {
expect(oriented(rightCoords, 0, ends, 2, true)).to.be(true);
expect(oriented(leftCoords, 0, ends, 2, true)).to.be(false);
});
});
describe('ol.geom.flat.orient.orientLinearRings', function() {
describe('ol.geom.flat.orient.orientLinearRings', function () {
const orient = orientLinearRings;
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,
];
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,
];
const ends = [10, 20];
it('orients using the left-hand rule by default', function() {
it('orients using the left-hand rule by default', function () {
const rightClone = rightCoords.slice();
orient(rightClone, 0, ends, 2);
expect(rightClone).to.eql(leftCoords);
@@ -105,7 +259,7 @@ describe('ol.geom.flat.orient', function() {
expect(leftClone).to.eql(leftCoords);
});
it('can orient using the right-hand rule', function() {
it('can orient using the right-hand rule', function () {
const rightClone = rightCoords.slice();
orient(rightClone, 0, ends, 2, true);
expect(rightClone).to.eql(rightCoords);
@@ -114,29 +268,103 @@ describe('ol.geom.flat.orient', function() {
orient(leftClone, 0, ends, 2, true);
expect(leftClone).to.eql(rightCoords);
});
});
describe('ol.geom.flat.orient.orientLinearRingsArray', function() {
describe('ol.geom.flat.orient.orientLinearRingsArray', function () {
const orient = orientLinearRingsArray;
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
-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,
];
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
-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,
];
const ends = [[10, 20], [30, 40]];
const ends = [
[10, 20],
[30, 40],
];
it('orients using the left-hand rule by default', function() {
it('orients using the left-hand rule by default', function () {
const rightClone = rightCoords.slice();
orient(rightClone, 0, ends, 2);
expect(rightClone).to.eql(leftCoords);
@@ -146,7 +374,7 @@ describe('ol.geom.flat.orient', function() {
expect(leftClone).to.eql(leftCoords);
});
it('can orient using the right-hand rule', function() {
it('can orient using the right-hand rule', function () {
const rightClone = rightCoords.slice();
orient(rightClone, 0, ends, 2, true);
expect(rightClone).to.eql(rightCoords);
@@ -155,8 +383,5 @@ describe('ol.geom.flat.orient', function() {
orient(leftClone, 0, ends, 2, true);
expect(leftClone).to.eql(rightCoords);
});
});
});
+56 -35
View File
@@ -1,114 +1,135 @@
import {coordinates as reverseCoordinates} from '../../../../../src/ol/geom/flat/reverse.js';
describe('ol.geom.flat.reverse', function() {
describe('ol.geom.flat.reverse.coordinates', function() {
describe('with a stride of 2', function() {
it('can reverse empty flat coordinates', function() {
describe('ol.geom.flat.reverse', function () {
describe('ol.geom.flat.reverse.coordinates', function () {
describe('with a stride of 2', function () {
it('can reverse empty flat coordinates', function () {
const flatCoordinates = [];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.be.empty();
});
it('can reverse one flat coordinates', function() {
it('can reverse one flat coordinates', function () {
const flatCoordinates = [1, 2];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([1, 2]);
});
it('can reverse two flat coordinates', function() {
it('can reverse two flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([3, 4, 1, 2]);
});
it('can reverse three flat coordinates', function() {
it('can reverse three flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([5, 6, 3, 4, 1, 2]);
});
it('can reverse four flat coordinates', function() {
it('can reverse four flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
expect(flatCoordinates).to.eql([7, 8, 5, 6, 3, 4, 1, 2]);
});
});
describe('with a stride of 3', function() {
it('can reverse empty flat coordinates', function() {
describe('with a stride of 3', function () {
it('can reverse empty flat coordinates', function () {
const flatCoordinates = [];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.be.empty();
});
it('can reverse one flat coordinates', function() {
it('can reverse one flat coordinates', function () {
const flatCoordinates = [1, 2, 3];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([1, 2, 3]);
});
it('can reverse two flat coordinates', function() {
it('can reverse two flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([4, 5, 6, 1, 2, 3]);
});
it('can reverse three flat coordinates', function() {
it('can reverse three flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
reverseCoordinates(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() {
it('can reverse four flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
expect(flatCoordinates).to.eql([10, 11, 12, 7, 8, 9, 4, 5, 6, 1, 2, 3]);
});
});
describe('with a stride of 4', function() {
it('can reverse empty flat coordinates', function() {
describe('with a stride of 4', function () {
it('can reverse empty flat coordinates', function () {
const flatCoordinates = [];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.be.empty();
});
it('can reverse one flat coordinates', function() {
it('can reverse one flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql([1, 2, 3, 4]);
});
it('can reverse two flat coordinates', function() {
it('can reverse two flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8];
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
expect(flatCoordinates).to.eql([5, 6, 7, 8, 1, 2, 3, 4]);
});
it('can reverse three flat coordinates', function() {
it('can reverse three flat coordinates', function () {
const flatCoordinates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
reverseCoordinates(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() {
const flatCoordinates =
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
it('can reverse four flat coordinates', function () {
const flatCoordinates = [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
];
reverseCoordinates(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]);
expect(flatCoordinates).to.eql([
13,
14,
15,
16,
9,
10,
11,
12,
5,
6,
7,
8,
1,
2,
3,
4,
]);
});
});
});
});
+9 -11
View File
@@ -1,20 +1,18 @@
import {forEach as forEachSegment} from '../../../../../src/ol/geom/flat/segments.js';
describe('ol.geom.flat.segments', function() {
describe('ol.geom.flat.segments.forEach', function() {
describe('ol.geom.flat.segments', function () {
describe('ol.geom.flat.segments.forEach', function () {
let flatCoordinates, offset, end, stride;
beforeEach(function() {
beforeEach(function () {
flatCoordinates = [0, 0, 1, 1, 2, 2, 3, 3];
offset = 0;
end = 8;
stride = 2;
});
describe('callback returns undefined', function() {
it('executes the callback for each segment', function() {
describe('callback returns undefined', function () {
it('executes the callback for each segment', function () {
const args = [];
const spy = sinon.spy(function(point1, point2) {
const spy = sinon.spy(function (point1, point2) {
args.push([point1[0], point1[1], point2[0], point2[1]]);
});
const ret = forEachSegment(flatCoordinates, offset, end, stride, spy);
@@ -34,10 +32,10 @@ describe('ol.geom.flat.segments', function() {
expect(ret).to.be(false);
});
});
describe('callback returns true', function() {
it('executes the callback for the first segment', function() {
describe('callback returns true', function () {
it('executes the callback for the first segment', function () {
const args = [];
const spy = sinon.spy(function(point1, point2) {
const spy = sinon.spy(function (point1, point2) {
args.push([point1[0], point1[1], point2[0], point2[1]]);
return true;
});
File diff suppressed because it is too large Load Diff
+31 -20
View File
@@ -1,58 +1,69 @@
import {matchingChunk} from '../../../../../src/ol/geom/flat/straightchunk.js';
describe('ol.geom.flat.straightchunk', function() {
describe('ol.geom.flat.straightchunk.matchingChunk', function() {
describe('single segment with stride == 3', function() {
describe('ol.geom.flat.straightchunk', function () {
describe('ol.geom.flat.straightchunk.matchingChunk', function () {
describe('single segment with stride == 3', function () {
const flatCoords = [0, 0, 42, 1, 1, 42];
const stride = 3;
it('returns whole line with angle delta', function() {
it('returns whole line with angle delta', function () {
const got = matchingChunk(Math.PI / 4, flatCoords, 0, 6, stride);
expect(got).to.eql([0, 6]);
});
it('returns whole line with zero angle delta', function() {
it('returns whole line with zero angle delta', function () {
const got = matchingChunk(0, flatCoords, 0, 6, stride);
expect(got).to.eql([0, 6]);
});
});
describe('short line string', function() {
describe('short line string', function () {
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1];
const stride = 2;
it('returns whole line if straight enough', function() {
it('returns whole line if straight enough', function () {
const got = matchingChunk(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() {
it('returns first matching chunk if all chunk lengths are the same', function () {
const got = matchingChunk(Math.PI / 4, flatCoords, 0, 8, stride);
expect(got).to.eql([0, 4]);
});
});
describe('longer line string', function() {
const flatCoords = [0, 0, 1, 0, 1, 1, 0, 1, 0, -1, -1, -1, -1, 0, -1, 2, -2, 4];
describe('longer line string', function () {
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() {
it('returns stright chunk from within the linestring', function () {
const got = matchingChunk(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() {
it('returns long chunk at the end if angle and length within threshold', function () {
const got = matchingChunk(Math.PI / 4, flatCoords, 0, 18, stride);
expect(got).to.eql([10, 18]);
});
});
});
});
+165 -35
View File
@@ -1,8 +1,7 @@
import {drawTextOnPath} from '../../../../../src/ol/geom/flat/textpath.js';
import {lineStringLength} from '../../../../../src/ol/geom/flat/length.js';
describe('ol.geom.flat.drawTextOnPath', function() {
describe('ol.geom.flat.drawTextOnPath', function () {
const horizontal = [0, 0, 100, 0];
const vertical = [0, 0, 0, 100];
const diagonal = [0, 0, 100, 100];
@@ -14,103 +13,234 @@ describe('ol.geom.flat.drawTextOnPath', function() {
return 10 * text.length;
}
it('center-aligns text on a horizontal line', function() {
it('center-aligns text on a horizontal line', function () {
const startM = 50 - 15;
const instructions = drawTextOnPath(
horizontal, 0, horizontal.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
horizontal,
0,
horizontal.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.eql([[40, 0, 5, 0, 'foo']]);
});
it('left-aligns text on a horizontal line', function() {
it('left-aligns text on a horizontal line', function () {
const instructions = drawTextOnPath(
horizontal, 0, horizontal.length, 2, 'foo', 0, Infinity, 1, measureAndCacheTextWidth, '', {});
horizontal,
0,
horizontal.length,
2,
'foo',
0,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.eql([[5, 0, 5, 0, 'foo']]);
});
it('right-aligns text on a horizontal line', function() {
it('right-aligns text on a horizontal line', function () {
const startM = 100 - 30;
const instructions = drawTextOnPath(
horizontal, 0, horizontal.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
horizontal,
0,
horizontal.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.eql([[75, 0, 5, 0, 'foo']]);
});
it('draws text on a vertical line', function() {
it('draws text on a vertical line', function () {
const startM = 50 - 15;
const instructions = drawTextOnPath(
vertical, 0, vertical.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
const a = 90 * Math.PI / 180;
vertical,
0,
vertical.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
const a = (90 * Math.PI) / 180;
expect(instructions).to.eql([[0, 40, 5, a, 'foo']]);
});
it('draws text on a diagonal line', function() {
it('draws text on a diagonal line', function () {
const startM = Math.sqrt(2) * 50 - 15;
const instructions = drawTextOnPath(
diagonal, 0, diagonal.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.be(45 * Math.PI / 180);
diagonal,
0,
diagonal.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
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() {
it('draws reverse text on a diagonal line', function () {
const startM = Math.sqrt(2) * 50 - 15;
const instructions = drawTextOnPath(
reverse, 0, reverse.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.be(-45 * Math.PI / 180);
reverse,
0,
reverse.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.be((-45 * Math.PI) / 180);
expect(instructions.length).to.be(1);
});
it('renders long text with extrapolation', function() {
it('renders long text with extrapolation', function () {
const startM = 50 - 75;
const instructions = drawTextOnPath(
horizontal, 0, horizontal.length, 2, 'foo-foo-foo-foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
horizontal,
0,
horizontal.length,
2,
'foo-foo-foo-foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0]).to.eql([-20, 0, 5, 0, 'foo-foo-foo-foo']);
expect(instructions.length).to.be(1);
});
it('renders angled text', function() {
it('renders angled text', function () {
const length = lineStringLength(angled, 0, angled.length, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
angled, 0, angled.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.eql(45 * Math.PI / 180);
angled,
0,
angled.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.eql((45 * Math.PI) / 180);
expect(instructions[0][4]).to.be('f');
expect(instructions[1][3]).to.eql(45 * Math.PI / 180);
expect(instructions[1][3]).to.eql((45 * Math.PI) / 180);
expect(instructions[1][4]).to.be('o');
expect(instructions[2][3]).to.eql(-45 * Math.PI / 180);
expect(instructions[2][3]).to.eql((-45 * Math.PI) / 180);
expect(instructions[2][4]).to.be('o');
});
it('respects maxAngle', function() {
it('respects maxAngle', function () {
const length = lineStringLength(angled, 0, angled.length, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
angled, 0, angled.length, 2, 'foo', startM, Math.PI / 4, 1, measureAndCacheTextWidth, '', {});
angled,
0,
angled.length,
2,
'foo',
startM,
Math.PI / 4,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.be(null);
});
it('uses the smallest angle for maxAngleDelta', function() {
it('uses the smallest angle for maxAngleDelta', function () {
const length = lineStringLength(reverseangled, 0, reverseangled.length, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
reverseangled, 0, reverseangled.length, 2, 'foo', startM, Math.PI, 1, measureAndCacheTextWidth, '', {});
reverseangled,
0,
reverseangled.length,
2,
'foo',
startM,
Math.PI,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions).to.not.be(undefined);
});
it('respects the offset option', function() {
it('respects the offset option', function () {
const length = lineStringLength(angled, 2, angled.length, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
angled, 2, angled.length, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.be(-45 * Math.PI / 180);
angled,
2,
angled.length,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.be((-45 * Math.PI) / 180);
expect(instructions.length).to.be(1);
});
it('respects the end option', function() {
it('respects the end option', function () {
const length = lineStringLength(angled, 0, 4, 2);
const startM = length / 2 - 15;
const instructions = drawTextOnPath(
angled, 0, 4, 2, 'foo', startM, Infinity, 1, measureAndCacheTextWidth, '', {});
expect(instructions[0][3]).to.be(45 * Math.PI / 180);
angled,
0,
4,
2,
'foo',
startM,
Infinity,
1,
measureAndCacheTextWidth,
'',
{}
);
expect(instructions[0][3]).to.be((45 * Math.PI) / 180);
expect(instructions.length).to.be(1);
});
});
+29 -13
View File
@@ -1,31 +1,47 @@
import {lineStringIsClosed} from '../../../../../src/ol/geom/flat/topology.js';
describe('ol.geom.flat.topology', function() {
describe('ol.geom.flat.topology.lineStringIsClosed', function() {
it('identifies closed lines aka boundaries', function() {
describe('ol.geom.flat.topology', function () {
describe('ol.geom.flat.topology.lineStringIsClosed', function () {
it('identifies closed lines aka boundaries', function () {
const flatCoordinates = [0, 0, 3, 0, 0, 3, 0, 0];
const isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
const isClosed = lineStringIsClosed(
flatCoordinates,
0,
flatCoordinates.length,
2
);
expect(isClosed).to.be(true);
});
it('identifies regular linestrings', function() {
it('identifies regular linestrings', function () {
const flatCoordinates = [0, 0, 3, 0, 0, 3, 5, 2];
const isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
const isClosed = lineStringIsClosed(
flatCoordinates,
0,
flatCoordinates.length,
2
);
expect(isClosed).to.be(false);
});
it('identifies degenerate boundaries', function() {
it('identifies degenerate boundaries', function () {
let flatCoordinates = [0, 0, 3, 0, 0, 0];
let isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
let isClosed = lineStringIsClosed(
flatCoordinates,
0,
flatCoordinates.length,
2
);
expect(isClosed).to.be(false);
flatCoordinates = [0, 0, 1, 1, 3, 3, 5, 5, 0, 0];
isClosed = lineStringIsClosed(flatCoordinates, 0, flatCoordinates.length, 2);
isClosed = lineStringIsClosed(
flatCoordinates,
0,
flatCoordinates.length,
2
);
expect(isClosed).to.be(false);
});
});
});
+129 -46
View File
@@ -1,37 +1,48 @@
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
import {transformGeom2D} from '../../../../../src/ol/geom/SimpleGeometry.js';
import {rotate, translate} from '../../../../../src/ol/geom/flat/transform.js';
import {transformGeom2D} from '../../../../../src/ol/geom/SimpleGeometry.js';
describe('ol.geom.flat.transform', function() {
describe('ol.geom.flat.transform.transform2D', function() {
it('transforms a Simple Geometry to 2D', function() {
describe('ol.geom.flat.transform', function () {
describe('ol.geom.flat.transform.transform2D', function () {
it('transforms a Simple Geometry to 2D', function () {
const multiPolygonGeometry = new MultiPolygon([
[[[-80.736061, 28.788576000000006, 0],
[-80.763557, 28.821799999999996, 0],
[-80.817406, 28.895123999999996, 0],
[-80.891304, 29.013130000000004, 0],
[-80.916512, 29.071560000000005, 0],
[-80.899323, 29.061249000000004, 0],
[-80.862663, 28.991361999999995, 0],
[-80.736061, 28.788576000000006, 0]]], [[
[-82.102127, 26.585724, 0],
[-82.067139, 26.497208, 0],
[-82.097641, 26.493585999999993, 0],
[-82.135895, 26.642279000000002, 0],
[-82.183495, 26.683082999999996, 0],
[-82.128838, 26.693342, 0],
[-82.102127, 26.585724, 0]]]
[
[
[-80.736061, 28.788576000000006, 0],
[-80.763557, 28.821799999999996, 0],
[-80.817406, 28.895123999999996, 0],
[-80.891304, 29.013130000000004, 0],
[-80.916512, 29.071560000000005, 0],
[-80.899323, 29.061249000000004, 0],
[-80.862663, 28.991361999999995, 0],
[-80.736061, 28.788576000000006, 0],
],
],
[
[
[-82.102127, 26.585724, 0],
[-82.067139, 26.497208, 0],
[-82.097641, 26.493585999999993, 0],
[-82.135895, 26.642279000000002, 0],
[-82.183495, 26.683082999999996, 0],
[-82.128838, 26.693342, 0],
[-82.102127, 26.585724, 0],
],
],
]).transform('EPSG:4326', 'EPSG:3857');
const transform = [
0.0004088332670837288, 0,
0, -0.0004088332670837288,
4480.991370439071, 1529.5752568707105
0.0004088332670837288,
0,
0,
-0.0004088332670837288,
4480.991370439071,
1529.5752568707105,
];
const pixelCoordinates = transformGeom2D(multiPolygonGeometry, transform, []);
const pixelCoordinates = transformGeom2D(
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);
@@ -63,37 +74,111 @@ describe('ol.geom.flat.transform', function() {
expect(pixelCoordinates[28]).to.roughlyEqual(744.4323460835158, 1e-9);
expect(pixelCoordinates[29]).to.roughlyEqual(273.7179168205373, 1e-9);
});
});
describe('ol.geom.flat.transform.translate', function() {
it('translates the coordinates array', function() {
describe('ol.geom.flat.transform.translate', function () {
it('translates the coordinates array', function () {
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]]]]);
[
[
[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],
],
],
]);
const flatCoordinates = multiPolygon.getFlatCoordinates();
const deltaX = 1;
const deltaY = 2;
translate(flatCoordinates, 0,
flatCoordinates.length, multiPolygon.getStride(),
deltaX, deltaY, flatCoordinates);
translate(
flatCoordinates,
0,
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]);
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,
]);
});
});
describe('ol.geom.flat.transform.rotate', function() {
it('rotates the coordinates array', function() {
describe('ol.geom.flat.transform.rotate', function () {
it('rotates the coordinates array', function () {
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]]]]);
[
[
[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],
],
],
]);
const flatCoordinates = multiPolygon.getFlatCoordinates();
const angle = Math.PI / 2;
const anchor = [0, 1];
rotate(flatCoordinates, 0,
flatCoordinates.length, multiPolygon.getStride(),
angle, anchor, flatCoordinates);
rotate(
flatCoordinates,
0,
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);
@@ -125,7 +210,5 @@ describe('ol.geom.flat.transform', function() {
expect(flatCoordinates[28]).to.roughlyEqual(3, 1e-9);
expect(flatCoordinates[29]).to.roughlyEqual(3, 1e-9);
});
});
});
+124 -80
View File
@@ -4,60 +4,78 @@ import LineString from '../../../../src/ol/geom/LineString.js';
import Point from '../../../../src/ol/geom/Point.js';
import Polygon from '../../../../src/ol/geom/Polygon.js';
describe('ol.geom.GeometryCollection', function() {
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() {
describe('ol.geom.GeometryCollection', function () {
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 () {
let line, multi, point, poly;
beforeEach(function() {
beforeEach(function () {
point = new Point([10, 20]);
line = new LineString([[10, 20], [30, 40]]);
line = new LineString([
[10, 20],
[30, 40],
]);
poly = new Polygon([outer, inner1, inner2]);
multi = new GeometryCollection([point, line, poly]);
});
it('creates a geometry collection from an array of geometries', function() {
it('creates a geometry collection from an array of geometries', function () {
expect(multi).to.be.a(GeometryCollection);
expect(multi).to.be.a(Geometry);
});
it('fires a change event when one of its component changes',
function(done) {
multi.on('change', function() {
done();
});
point.setCoordinates([10, 10]);
}
);
it('fires a change event when one of its component changes', function (done) {
multi.on('change', function () {
done();
});
point.setCoordinates([10, 10]);
});
it('deregister old components', function() {
it('deregister old components', function () {
multi.setGeometries([poly]);
multi.on('change', function() {
multi.on('change', function () {
expect().fail();
});
point.setCoordinates([10, 10]);
});
it('register new components', function(done) {
it('register new components', function (done) {
const point2 = new Point([10, 20]);
multi.setGeometriesArray([point2]);
multi.on('change', function() {
multi.on('change', function () {
done();
});
point2.setCoordinates([10, 10]);
});
});
describe('#getGeometries', function() {
it('returns a collection of geometries', function() {
describe('#getGeometries', function () {
it('returns a collection of geometries', function () {
const point = new Point([10, 20]);
const line = new LineString([[10, 20], [30, 40]]);
const line = new LineString([
[10, 20],
[30, 40],
]);
const poly = new Polygon([outer, inner1, inner2]);
const multi = new GeometryCollection([point, line, poly]);
@@ -68,25 +86,29 @@ describe('ol.geom.GeometryCollection', function() {
expect(geometries[1]).to.be.a(LineString);
expect(geometries[2]).to.be.a(Polygon);
});
});
describe('#clone()', function() {
it('has a working clone method', function() {
describe('#clone()', function () {
it('has a working clone method', function () {
const point = new Point([10, 20]);
const line = new LineString([[10, 20], [30, 40]]);
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);
const geometries = clone.getGeometries();
expect(geometries[0].getCoordinates()).to.eql([10, 20]);
expect(geometries[1].getCoordinates()).to.eql([[10, 20], [30, 40]]);
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() {
it('does a deep clone', function () {
const point = new Point([30, 40]);
const originalGeometries = [point];
const multi = new GeometryCollection(originalGeometries);
@@ -96,17 +118,19 @@ describe('ol.geom.GeometryCollection', function() {
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());
expect(clonedGeometries[0].getCoordinates()).to.eql(
originalGeometries[0].getCoordinates()
);
});
});
describe('#getExtent()', function() {
it('returns the bounding extent', function() {
describe('#getExtent()', function () {
it('returns the bounding extent', function () {
const point = new Point([10, 2]);
const line = new LineString([[1, 20], [30, 40]]);
const line = new LineString([
[1, 20],
[30, 40],
]);
const multi = new GeometryCollection([point, line]);
const extent = multi.getExtent();
expect(extent[0]).to.be(1);
@@ -114,111 +138,133 @@ describe('ol.geom.GeometryCollection', function() {
expect(extent[1]).to.be(2);
expect(extent[3]).to.be(40);
});
});
describe('#intersectsExtent()', function() {
describe('#intersectsExtent()', function () {
let point, line, poly, multi;
beforeEach(function() {
beforeEach(function () {
point = new Point([5, 20]);
line = new LineString([[10, 20], [30, 40]]);
line = new LineString([
[10, 20],
[30, 40],
]);
poly = new Polygon([outer, inner1, inner2]);
multi = new GeometryCollection([point, line, poly]);
});
it('returns true for intersecting point', function() {
it('returns true for intersecting point', function () {
expect(multi.intersectsExtent([5, 20, 5, 20])).to.be(true);
});
it('returns true for intersecting part of lineString', function() {
it('returns true for intersecting part of lineString', function () {
expect(multi.intersectsExtent([25, 35, 30, 40])).to.be(true);
});
it('returns true for intersecting part of polygon', function() {
it('returns true for intersecting part of polygon', function () {
expect(multi.intersectsExtent([0, 0, 5, 5])).to.be(true);
});
it('returns false for non-matching extent within own extent', function() {
it('returns false for non-matching extent within own extent', function () {
const extent = [0, 35, 5, 40];
expect(poly.intersectsExtent(extent)).to.be(false);
});
});
describe('#setGeometries', function() {
describe('#setGeometries', function () {
let line, multi, point, poly;
beforeEach(function() {
beforeEach(function () {
point = new Point([10, 20]);
line = new LineString([[10, 20], [30, 40]]);
line = new LineString([
[10, 20],
[30, 40],
]);
poly = new Polygon([outer, inner1, inner2]);
multi = new GeometryCollection([point, line, poly]);
});
it('fires a change event', function() {
it('fires a change event', function () {
const listener = sinon.spy();
multi.on('change', listener);
multi.setGeometries([point, line, poly]);
expect(listener.calledOnce).to.be(true);
});
it('updates the extent', function() {
it('updates the extent', function () {
expect(multi.getExtent()).to.eql([0, 0, 30, 40]);
line.setCoordinates([[10, 20], [300, 400]]);
line.setCoordinates([
[10, 20],
[300, 400],
]);
expect(multi.getExtent()).to.eql([0, 0, 300, 400]);
});
});
describe('#scale()', function() {
it('scales a collection', function() {
describe('#scale()', function () {
it('scales a collection', function () {
const geom = new GeometryCollection([
new Point([-1, -2]),
new LineString([[0, 0], [1, 2]])
new LineString([
[0, 0],
[1, 2],
]),
]);
geom.scale(10);
const geometries = geom.getGeometries();
expect(geometries[0].getCoordinates()).to.eql([-10, -20]);
expect(geometries[1].getCoordinates()).to.eql([[0, 0], [10, 20]]);
expect(geometries[1].getCoordinates()).to.eql([
[0, 0],
[10, 20],
]);
});
it('accepts sx and sy', function() {
it('accepts sx and sy', function () {
const geom = new GeometryCollection([
new Point([-1, -2]),
new LineString([[0, 0], [1, 2]])
new LineString([
[0, 0],
[1, 2],
]),
]);
geom.scale(2, 3);
const geometries = geom.getGeometries();
expect(geometries[0].getCoordinates()).to.eql([-2, -6]);
expect(geometries[1].getCoordinates()).to.eql([[0, 0], [2, 6]]);
expect(geometries[1].getCoordinates()).to.eql([
[0, 0],
[2, 6],
]);
});
it('accepts an anchor', function() {
it('accepts an anchor', function () {
const geom = new GeometryCollection([
new Point([-1, -2]),
new LineString([[0, 0], [1, 2]])
new LineString([
[0, 0],
[1, 2],
]),
]);
geom.scale(10, 15, [-1, -2]);
const geometries = geom.getGeometries();
expect(geometries[0].getCoordinates()).to.eql([-1, -2]);
expect(geometries[1].getCoordinates()).to.eql([[9, 28], [19, 58]]);
expect(geometries[1].getCoordinates()).to.eql([
[9, 28],
[19, 58],
]);
});
});
describe('#transform()', function() {
describe('#transform()', function () {
let line, multi, point;
beforeEach(function() {
beforeEach(function () {
point = new Point([10, 20]);
line = new LineString([[10, 20], [30, 40]]);
line = new LineString([
[10, 20],
[30, 40],
]);
multi = new GeometryCollection([point, line]);
});
it('transforms all geometries', function() {
it('transforms all geometries', function () {
multi.transform('EPSG:4326', 'EPSG:3857');
const geometries = multi.getGeometries();
@@ -226,16 +272,14 @@ describe('ol.geom.GeometryCollection', function() {
expect(geometries[1]).to.be.a(LineString);
let coords = geometries[0].getCoordinates();
expect(coords[0]).to.roughlyEqual(1113194.90, 1e-2);
expect(coords[0]).to.roughlyEqual(1113194.9, 1e-2);
expect(coords[1]).to.roughlyEqual(2273030.92, 1e-2);
coords = geometries[1].getCoordinates();
expect(coords[0][0]).to.roughlyEqual(1113194.90, 1e-2);
expect(coords[0][0]).to.roughlyEqual(1113194.9, 1e-2);
expect(coords[0][1]).to.roughlyEqual(2273030.92, 1e-2);
expect(coords[1][0]).to.roughlyEqual(3339584.72, 1e-2);
expect(coords[1][1]).to.roughlyEqual(4865942.27, 1e-2);
});
});
});
+205 -182
View File
@@ -1,365 +1,394 @@
import {isEmpty} from '../../../../src/ol/extent.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import {isEmpty} from '../../../../src/ol/extent.js';
describe('ol.geom.LineString', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol.geom.LineString', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new LineString(null);
}).to.throwException();
});
describe('construct empty', function() {
describe('construct empty', function () {
let lineString;
beforeEach(function() {
beforeEach(function () {
lineString = new LineString([]);
});
it('defaults to layout XY', function() {
it('defaults to layout XY', function () {
expect(lineString.getLayout()).to.be('XY');
});
it('has empty coordinates', function() {
it('has empty coordinates', function () {
expect(lineString.getCoordinates()).to.be.empty();
});
it('has an empty extent', function() {
it('has an empty extent', function () {
expect(isEmpty(lineString.getExtent())).to.be(true);
});
it('has empty flat coordinates', function() {
it('has empty flat coordinates', function () {
expect(lineString.getFlatCoordinates()).to.be.empty();
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(lineString.getStride()).to.be(2);
});
it('can append coordinates', function() {
it('can append coordinates', function () {
lineString.appendCoordinate([1, 2]);
expect(lineString.getCoordinates()).to.eql([[1, 2]]);
lineString.appendCoordinate([3, 4]);
expect(lineString.getCoordinates()).to.eql([[1, 2], [3, 4]]);
expect(lineString.getCoordinates()).to.eql([
[1, 2],
[3, 4],
]);
});
});
describe('construct with 2D coordinates', function() {
describe('construct with 2D coordinates', function () {
let lineString;
beforeEach(function() {
lineString = new LineString([[1, 2], [3, 4]]);
beforeEach(function () {
lineString = new LineString([
[1, 2],
[3, 4],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(lineString.getLayout()).to.be('XY');
});
it('has the expected coordinates', function() {
expect(lineString.getCoordinates()).to.eql([[1, 2], [3, 4]]);
it('has the expected coordinates', function () {
expect(lineString.getCoordinates()).to.eql([
[1, 2],
[3, 4],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(lineString.getExtent()).to.eql([1, 2, 3, 4]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(lineString.getFlatCoordinates()).to.eql([1, 2, 3, 4]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(lineString.getStride()).to.be(2);
});
describe('#intersectsCoordinate', function() {
it('returns true for an intersecting coordinate', function() {
describe('#intersectsCoordinate', function () {
it('returns true for an intersecting coordinate', function () {
expect(lineString.intersectsCoordinate([1.5, 2.5])).to.be(true);
});
});
describe('#intersectsExtent', function() {
it('return false for non matching extent', function() {
describe('#intersectsExtent', function () {
it('return false for non matching extent', function () {
expect(lineString.intersectsExtent([1, 3, 1.9, 4])).to.be(false);
});
it('return true for extent on midpoint', function() {
it('return true for extent on midpoint', function () {
expect(lineString.intersectsExtent([2, 3, 4, 3])).to.be(true);
});
it('returns true for the geom\'s own extent', function() {
it("returns true for the geom's own extent", function () {
expect(lineString.intersectsExtent(lineString.getExtent())).to.be(true);
});
});
describe('#intersectsCoordinate', function() {
it('detects intersecting coordinates', function() {
describe('#intersectsCoordinate', function () {
it('detects intersecting coordinates', function () {
expect(lineString.intersectsCoordinate([1, 2])).to.be(true);
});
});
describe('#getClosestPoint', function() {
it('uses existing vertices', function() {
describe('#getClosestPoint', function () {
it('uses existing vertices', function () {
const closestPoint = lineString.getClosestPoint([0.9, 1.8]);
expect(closestPoint).to.eql([1, 2]);
});
});
describe('#getCoordinateAt', function() {
it('return the first point when fraction is 0', function() {
describe('#getCoordinateAt', function () {
it('return the first point when fraction is 0', function () {
expect(lineString.getCoordinateAt(0)).to.eql([1, 2]);
});
it('return the last point when fraction is 1', function() {
it('return the last point when fraction is 1', function () {
expect(lineString.getCoordinateAt(1)).to.eql([3, 4]);
});
it('return the mid point when fraction is 0.5', function() {
it('return the mid point when fraction is 0.5', function () {
expect(lineString.getCoordinateAt(0.5)).to.eql([2, 3]);
});
});
});
describe('construct with 3D coordinates', function() {
describe('construct with 3D coordinates', function () {
let lineString;
beforeEach(function() {
lineString = new LineString([[1, 2, 3], [4, 5, 6]]);
beforeEach(function () {
lineString = new LineString([
[1, 2, 3],
[4, 5, 6],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(lineString.getLayout()).to.be('XYZ');
});
it('has the expected coordinates', function() {
expect(lineString.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
it('has the expected coordinates', function () {
expect(lineString.getCoordinates()).to.eql([
[1, 2, 3],
[4, 5, 6],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(lineString.getExtent()).to.eql([1, 2, 4, 5]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(lineString.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(lineString.getStride()).to.be(3);
});
describe('#intersectsExtent', function() {
it('return false for non matching extent', function() {
describe('#intersectsExtent', function () {
it('return false for non matching extent', function () {
expect(lineString.intersectsExtent([1, 3, 1.9, 4])).to.be(false);
});
it('return true for extent on midpoint', function() {
it('return true for extent on midpoint', function () {
expect(lineString.intersectsExtent([2, 3, 4, 3])).to.be(true);
});
it('returns true for the geom\'s own extent', function() {
it("returns true for the geom's own extent", function () {
expect(lineString.intersectsExtent(lineString.getExtent())).to.be(true);
});
});
});
describe('construct with 3D coordinates and layout XYM', function() {
describe('construct with 3D coordinates and layout XYM', function () {
let lineString;
beforeEach(function() {
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() {
it('has the expected layout', function () {
expect(lineString.getLayout()).to.be('XYM');
});
it('has the expected coordinates', function() {
expect(lineString.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
it('has the expected coordinates', function () {
expect(lineString.getCoordinates()).to.eql([
[1, 2, 3],
[4, 5, 6],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(lineString.getExtent()).to.eql([1, 2, 4, 5]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(lineString.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(lineString.getStride()).to.be(3);
});
describe('#intersectsExtent', function() {
it('return false for non matching extent', function() {
describe('#intersectsExtent', function () {
it('return false for non matching extent', function () {
expect(lineString.intersectsExtent([1, 3, 1.9, 4])).to.be(false);
});
it('return true for extent on midpoint', function() {
it('return true for extent on midpoint', function () {
expect(lineString.intersectsExtent([2, 3, 4, 3])).to.be(true);
});
it('returns true for the geom\'s own extent', function() {
it("returns true for the geom's own extent", function () {
expect(lineString.intersectsExtent(lineString.getExtent())).to.be(true);
});
});
});
describe('construct with 4D coordinates', function() {
describe('construct with 4D coordinates', function () {
let lineString;
beforeEach(function() {
lineString = new LineString([[1, 2, 3, 4], [5, 6, 7, 8]]);
beforeEach(function () {
lineString = new LineString([
[1, 2, 3, 4],
[5, 6, 7, 8],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(lineString.getLayout()).to.be('XYZM');
});
it('has the expected coordinates', function() {
expect(lineString.getCoordinates()).to.eql([[1, 2, 3, 4], [5, 6, 7, 8]]);
it('has the expected coordinates', function () {
expect(lineString.getCoordinates()).to.eql([
[1, 2, 3, 4],
[5, 6, 7, 8],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(lineString.getExtent()).to.eql([1, 2, 5, 6]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(lineString.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6, 7, 8]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(lineString.getStride()).to.be(4);
});
describe('#intersectsExtent', function() {
it('return false for non matching extent', function() {
describe('#intersectsExtent', function () {
it('return false for non matching extent', function () {
expect(lineString.intersectsExtent([1, 3, 1.9, 4])).to.be(false);
});
it('return true for extent on midpoint', function() {
it('return true for extent on midpoint', function () {
expect(lineString.intersectsExtent([2, 3, 4, 3])).to.be(true);
});
it('returns true for the geom\'s own extent', function() {
it("returns true for the geom's own extent", function () {
expect(lineString.intersectsExtent(lineString.getExtent())).to.be(true);
});
});
});
describe('#scale()', function() {
it('scales a linestring', function() {
const geom = new LineString([[-10, -20], [10, 20]]);
describe('#scale()', function () {
it('scales a linestring', function () {
const geom = new LineString([
[-10, -20],
[10, 20],
]);
geom.scale(10);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-100, -200], [100, 200]]);
expect(coordinates).to.eql([
[-100, -200],
[100, 200],
]);
});
it('accepts sx and sy', function() {
const geom = new LineString([[-10, -20], [10, 20]]);
it('accepts sx and sy', function () {
const geom = new LineString([
[-10, -20],
[10, 20],
]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-20, -60], [20, 60]]);
expect(coordinates).to.eql([
[-20, -60],
[20, 60],
]);
});
it('accepts an anchor', function() {
const geom = new LineString([[-10, -20], [10, 20]]);
it('accepts an anchor', function () {
const geom = new LineString([
[-10, -20],
[10, 20],
]);
geom.scale(3, 2, [10, 20]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-50, -60], [10, 20]]);
expect(coordinates).to.eql([
[-50, -60],
[10, 20],
]);
});
});
describe('with a simple line string', function() {
describe('with a simple line string', function () {
let lineString;
beforeEach(function() {
lineString = new LineString(
[[0, 0], [1.5, 1], [3, 3], [5, 1], [6, 3.5], [7, 5]]);
beforeEach(function () {
lineString = new LineString([
[0, 0],
[1.5, 1],
[3, 3],
[5, 1],
[6, 3.5],
[7, 5],
]);
});
describe('#getFirstCoordinate', function() {
it('returns the expected result', function() {
describe('#getFirstCoordinate', function () {
it('returns the expected result', function () {
expect(lineString.getFirstCoordinate()).to.eql([0, 0]);
});
});
describe('#getFlatMidpoint', function() {
it('returns the expected result', function() {
describe('#getFlatMidpoint', function () {
it('returns the expected result', function () {
const midpoint = lineString.getFlatMidpoint();
expect(midpoint).to.be.an(Array);
expect(midpoint).to.have.length(2);
expect(midpoint[0]).to.roughlyEqual(4, 1e-1);
expect(midpoint[1]).to.roughlyEqual(2, 1e-1);
});
});
describe('#getLastCoordinate', function() {
it('returns the expected result', function() {
describe('#getLastCoordinate', function () {
it('returns the expected result', function () {
expect(lineString.getLastCoordinate()).to.eql([7, 5]);
});
});
describe('#simplify', function() {
it('returns a simplified geometry', function() {
describe('#simplify', function () {
it('returns a simplified geometry', function () {
const simplified = lineString.simplify(1);
expect(simplified).to.be.an(LineString);
expect(simplified.getCoordinates()).to.eql(
[[0, 0], [3, 3], [5, 1], [7, 5]]);
expect(simplified.getCoordinates()).to.eql([
[0, 0],
[3, 3],
[5, 1],
[7, 5],
]);
});
it('does not modify the original', function() {
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]]);
expect(lineString.getCoordinates()).to.eql([
[0, 0],
[1.5, 1],
[3, 3],
[5, 1],
[6, 3.5],
[7, 5],
]);
});
it('delegates to the internal method', function() {
it('delegates to the internal method', function () {
const simplified = lineString.simplify(2);
const internal = lineString.getSimplifiedGeometry(4);
expect(simplified.getCoordinates()).to.eql(internal.getCoordinates());
});
});
describe('#getSimplifiedGeometry', function() {
it('returns the expectedResult', function() {
describe('#getSimplifiedGeometry', function () {
it('returns the expectedResult', function () {
const simplifiedGeometry = lineString.getSimplifiedGeometry(1);
expect(simplifiedGeometry).to.be.an(LineString);
expect(simplifiedGeometry.getCoordinates()).to.eql(
[[0, 0], [3, 3], [5, 1], [7, 5]]);
expect(simplifiedGeometry.getCoordinates()).to.eql([
[0, 0],
[3, 3],
[5, 1],
[7, 5],
]);
});
it('remembers the minimum squared tolerance', function() {
it('remembers the minimum squared tolerance', function () {
sinon.spy(lineString, 'getSimplifiedGeometryInternal');
const simplifiedGeometry1 = lineString.getSimplifiedGeometry(0.05);
expect(lineString.getSimplifiedGeometryInternal.callCount).to.be(1);
@@ -368,39 +397,38 @@ describe('ol.geom.LineString', function() {
expect(lineString.getSimplifiedGeometryInternal.callCount).to.be(1);
expect(simplifiedGeometry2).to.be(lineString);
});
});
describe('#getCoordinateAt', function() {
it('return the first point when fraction is 0', function() {
describe('#getCoordinateAt', function () {
it('return the first point when fraction is 0', function () {
expect(lineString.getCoordinateAt(0)).to.eql([0, 0]);
});
it('return the last point when fraction is 1', function() {
it('return the last point when fraction is 1', function () {
expect(lineString.getCoordinateAt(1)).to.eql([7, 5]);
});
it('return the mid point when fraction is 0.5', function() {
it('return the mid point when fraction is 0.5', function () {
const midpoint = lineString.getFlatMidpoint();
expect(lineString.getCoordinateAt(0.5)).to.eql(midpoint);
});
});
});
describe('with a simple XYM coordinates', function() {
describe('with a simple XYM coordinates', function () {
let lineString;
beforeEach(function() {
beforeEach(function () {
lineString = new LineString(
[[1, 2, 3], [4, 5, 6]], 'XYM');
[
[1, 2, 3],
[4, 5, 6],
],
'XYM'
);
});
describe('#getCoordinateAtM', function() {
it('returns the expected value', function() {
describe('#getCoordinateAtM', function () {
it('returns the expected value', function () {
expect(lineString.getCoordinateAtM(2, false)).to.be(null);
expect(lineString.getCoordinateAtM(2, true)).to.eql([1, 2, 2]);
expect(lineString.getCoordinateAtM(3, false)).to.eql([1, 2, 3]);
@@ -414,15 +442,12 @@ describe('ol.geom.LineString', function() {
expect(lineString.getCoordinateAtM(7, false)).to.eql(null);
expect(lineString.getCoordinateAtM(7, true)).to.eql([4, 5, 7]);
});
});
});
describe('with several XYZM coordinates', function() {
describe('with several XYZM coordinates', function () {
let lineString;
beforeEach(function() {
beforeEach(function () {
lineString = new LineString([
[0, 0, 0, 0],
[1, -1, 2, 1],
@@ -434,29 +459,29 @@ describe('ol.geom.LineString', function() {
[15, -15, 30, 15],
[16, -16, 32, 16],
[18, -18, 36, 18],
[22, -22, 44, 22]
[22, -22, 44, 22],
]);
});
describe('#getCoordinateAtM', function() {
it('returns the expected value', function() {
describe('#getCoordinateAtM', function () {
it('returns the expected value', function () {
expect(lineString.getLayout()).to.be('XYZM');
let m;
for (m = 0; m <= 22; m += 0.5) {
expect(lineString.getCoordinateAtM(m, true)).to.eql(
[m, -m, 2 * m, m]);
expect(lineString.getCoordinateAtM(m, true)).to.eql([
m,
-m,
2 * m,
m,
]);
}
});
});
});
describe('#containsXY()', function() {
describe('#containsXY()', function () {
let lineString;
beforeEach(function() {
beforeEach(function () {
lineString = new LineString([
[0, 0, 0, 0],
[1, -1, 2, 1],
@@ -468,22 +493,20 @@ describe('ol.geom.LineString', function() {
[15, -15, 30, 15],
[16, -16, 32, 16],
[18, -18, 36, 18],
[22, -22, 44, 22]
[22, -22, 44, 22],
]);
});
it('does contain XY', function() {
it('does contain XY', function () {
expect(lineString.containsXY(1, -1)).to.be(true);
expect(lineString.containsXY(16, -16)).to.be(true);
expect(lineString.containsXY(3, -3)).to.be(true);
});
it('does not contain XY', function() {
it('does not contain XY', function () {
expect(lineString.containsXY(1, 3)).to.be(false);
expect(lineString.containsXY(2, 2)).to.be(false);
expect(lineString.containsXY(2, 3)).to.be(false);
});
});
});
+486 -208
View File
@@ -1,353 +1,626 @@
import {isEmpty} from '../../../../src/ol/extent.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import MultiLineString from '../../../../src/ol/geom/MultiLineString.js';
import {isEmpty} from '../../../../src/ol/extent.js';
describe('ol.geom.MultiLineString', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol.geom.MultiLineString', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new MultiLineString(null);
}).to.throwException();
});
describe('construct empty', function() {
describe('construct empty', function () {
let multiLineString;
beforeEach(function() {
beforeEach(function () {
multiLineString = new MultiLineString([]);
});
it('defaults to layout XY', function() {
it('defaults to layout XY', function () {
expect(multiLineString.getLayout()).to.be('XY');
});
it('has empty coordinates', function() {
it('has empty coordinates', function () {
expect(multiLineString.getCoordinates()).to.be.empty();
});
it('has an empty extent', function() {
it('has an empty extent', function () {
expect(isEmpty(multiLineString.getExtent())).to.be(true);
});
it('has empty flat coordinates', function() {
it('has empty flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.be.empty();
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(2);
});
it('can append line strings', function() {
it('can append line strings', function () {
multiLineString.appendLineString(
new LineString([[1, 2], [3, 4]]));
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]]]);
new LineString([
[1, 2],
[3, 4],
])
);
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2],
[3, 4],
],
]);
multiLineString.appendLineString(
new LineString([[5, 6], [7, 8]]));
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
new LineString([
[5, 6],
[7, 8],
])
);
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]);
});
});
describe('construct with 2D coordinates', function() {
describe('construct with 2D coordinates', function () {
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
beforeEach(function () {
multiLineString = new MultiLineString([
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiLineString.getLayout()).to.be('XY');
});
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]);
it('has the expected coordinates', function () {
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiLineString.getExtent()).to.eql([1, 2, 7, 8]);
});
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8]);
it('has the expected flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(2);
});
describe('#getFlatMidpoints', function() {
it('returns the expected result', function() {
describe('#getFlatMidpoints', function () {
it('returns the expected result', function () {
expect(multiLineString.getFlatMidpoints()).to.eql([2, 3, 6, 7]);
});
});
describe('#intersectsExtent()', function() {
it('returns true for intersecting part of lineString', function() {
describe('#intersectsExtent()', function () {
it('returns true for intersecting part of lineString', function () {
expect(multiLineString.intersectsExtent([1, 2, 2, 3])).to.be(true);
});
it('returns false for non-matching extent within own extent', function() {
it('returns false for non-matching extent within own extent', function () {
expect(multiLineString.intersectsExtent([1, 7, 2, 8])).to.be(false);
});
});
});
describe('construct with 3D coordinates', function() {
describe('construct with 3D coordinates', function () {
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
beforeEach(function () {
multiLineString = new MultiLineString([
[
[1, 2, 3],
[4, 5, 6],
],
[
[7, 8, 9],
[10, 11, 12],
],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiLineString.getLayout()).to.be('XYZ');
});
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
it('has the expected coordinates', function () {
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2, 3],
[4, 5, 6],
],
[
[7, 8, 9],
[10, 11, 12],
],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiLineString.getExtent()).to.eql([1, 2, 10, 11]);
});
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
it('has the expected flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(3);
});
});
describe('construct with 3D coordinates and layout XYM', function() {
describe('construct with 3D coordinates and layout XYM', function () {
let multiLineString;
beforeEach(function() {
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() {
it('has the expected layout', function () {
expect(multiLineString.getLayout()).to.be('XYM');
});
it('has the expected coordinates', function() {
expect(multiLineString.getCoordinates()).to.eql(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]);
it('has the expected coordinates', function () {
expect(multiLineString.getCoordinates()).to.eql([
[
[1, 2, 3],
[4, 5, 6],
],
[
[7, 8, 9],
[10, 11, 12],
],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiLineString.getExtent()).to.eql([1, 2, 10, 11]);
});
it('has the expected flat coordinates', function() {
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
it('has the expected flat coordinates', function () {
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(3);
});
it('can return individual line strings', function() {
it('can return individual line strings', function () {
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]]);
expect(lineString0.getCoordinates()).to.eql([
[1, 2, 3],
[4, 5, 6],
]);
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]]);
expect(lineString1.getCoordinates()).to.eql([
[7, 8, 9],
[10, 11, 12],
]);
});
describe('#getCoordinateAtM', function() {
describe('with extrapolation and interpolation', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, true, true)).to.eql(
[1, 2, 0]);
expect(multiLineString.getCoordinateAtM(3, true, true)).to.eql(
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, true, true)).to.eql(
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, true, true)).to.eql(
[4, 5, 6]);
expect(multiLineString.getCoordinateAtM(7.5, true, true)).to.eql(
[5.5, 6.5, 7.5]);
expect(multiLineString.getCoordinateAtM(9, true, true)).to.eql(
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, true, true)).to.eql(
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, true, true)).to.eql(
[10, 11, 12]);
expect(multiLineString.getCoordinateAtM(15, true, true)).to.eql(
[10, 11, 15]);
describe('#getCoordinateAtM', function () {
describe('with extrapolation and interpolation', function () {
it('returns the expected value', function () {
expect(multiLineString.getCoordinateAtM(0, true, true)).to.eql([
1,
2,
0,
]);
expect(multiLineString.getCoordinateAtM(3, true, true)).to.eql([
1,
2,
3,
]);
expect(multiLineString.getCoordinateAtM(4.5, true, true)).to.eql([
2.5,
3.5,
4.5,
]);
expect(multiLineString.getCoordinateAtM(6, true, true)).to.eql([
4,
5,
6,
]);
expect(multiLineString.getCoordinateAtM(7.5, true, true)).to.eql([
5.5,
6.5,
7.5,
]);
expect(multiLineString.getCoordinateAtM(9, true, true)).to.eql([
7,
8,
9,
]);
expect(multiLineString.getCoordinateAtM(10.5, true, true)).to.eql([
8.5,
9.5,
10.5,
]);
expect(multiLineString.getCoordinateAtM(12, true, true)).to.eql([
10,
11,
12,
]);
expect(multiLineString.getCoordinateAtM(15, true, true)).to.eql([
10,
11,
15,
]);
});
});
describe('with extrapolation and no interpolation', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, true, false)).to.eql(
[1, 2, 0]);
expect(multiLineString.getCoordinateAtM(3, true, false)).to.eql(
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, true, false)).to.eql(
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, true, false)).to.eql(
[4, 5, 6]);
describe('with extrapolation and no interpolation', function () {
it('returns the expected value', function () {
expect(multiLineString.getCoordinateAtM(0, true, false)).to.eql([
1,
2,
0,
]);
expect(multiLineString.getCoordinateAtM(3, true, false)).to.eql([
1,
2,
3,
]);
expect(multiLineString.getCoordinateAtM(4.5, true, false)).to.eql([
2.5,
3.5,
4.5,
]);
expect(multiLineString.getCoordinateAtM(6, true, false)).to.eql([
4,
5,
6,
]);
expect(multiLineString.getCoordinateAtM(7.5, true, false)).to.be(
null);
expect(multiLineString.getCoordinateAtM(9, true, false)).to.eql(
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, true, false)).to.eql(
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, true, false)).to.eql(
[10, 11, 12]);
expect(multiLineString.getCoordinateAtM(15, true, false)).to.eql(
[10, 11, 15]);
null
);
expect(multiLineString.getCoordinateAtM(9, true, false)).to.eql([
7,
8,
9,
]);
expect(multiLineString.getCoordinateAtM(10.5, true, false)).to.eql([
8.5,
9.5,
10.5,
]);
expect(multiLineString.getCoordinateAtM(12, true, false)).to.eql([
10,
11,
12,
]);
expect(multiLineString.getCoordinateAtM(15, true, false)).to.eql([
10,
11,
15,
]);
});
});
describe('with no extrapolation and interpolation', function() {
it('returns the expected value', function() {
expect(multiLineString.getCoordinateAtM(0, false, true)).to.eql(
null);
expect(multiLineString.getCoordinateAtM(3, false, true)).to.eql(
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, false, true)).to.eql(
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, false, true)).to.eql(
[4, 5, 6]);
expect(multiLineString.getCoordinateAtM(7.5, false, true)).to.eql(
[5.5, 6.5, 7.5]);
expect(multiLineString.getCoordinateAtM(9, false, true)).to.eql(
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, false, true)).to.eql(
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, false, true)).to.eql(
[10, 11, 12]);
describe('with no extrapolation and interpolation', function () {
it('returns the expected value', function () {
expect(multiLineString.getCoordinateAtM(0, false, true)).to.eql(null);
expect(multiLineString.getCoordinateAtM(3, false, true)).to.eql([
1,
2,
3,
]);
expect(multiLineString.getCoordinateAtM(4.5, false, true)).to.eql([
2.5,
3.5,
4.5,
]);
expect(multiLineString.getCoordinateAtM(6, false, true)).to.eql([
4,
5,
6,
]);
expect(multiLineString.getCoordinateAtM(7.5, false, true)).to.eql([
5.5,
6.5,
7.5,
]);
expect(multiLineString.getCoordinateAtM(9, false, true)).to.eql([
7,
8,
9,
]);
expect(multiLineString.getCoordinateAtM(10.5, false, true)).to.eql([
8.5,
9.5,
10.5,
]);
expect(multiLineString.getCoordinateAtM(12, false, true)).to.eql([
10,
11,
12,
]);
expect(multiLineString.getCoordinateAtM(15, false, true)).to.eql(
null);
null
);
});
});
describe('with no extrapolation or interpolation', function() {
it('returns the expected value', function() {
describe('with no extrapolation or interpolation', function () {
it('returns the expected value', function () {
expect(multiLineString.getCoordinateAtM(0, false, false)).to.eql(
null);
expect(multiLineString.getCoordinateAtM(3, false, false)).to.eql(
[1, 2, 3]);
expect(multiLineString.getCoordinateAtM(4.5, false, false)).to.eql(
[2.5, 3.5, 4.5]);
expect(multiLineString.getCoordinateAtM(6, false, false)).to.eql(
[4, 5, 6]);
null
);
expect(multiLineString.getCoordinateAtM(3, false, false)).to.eql([
1,
2,
3,
]);
expect(multiLineString.getCoordinateAtM(4.5, false, false)).to.eql([
2.5,
3.5,
4.5,
]);
expect(multiLineString.getCoordinateAtM(6, false, false)).to.eql([
4,
5,
6,
]);
expect(multiLineString.getCoordinateAtM(7.5, false, false)).to.eql(
null);
expect(multiLineString.getCoordinateAtM(9, false, false)).to.eql(
[7, 8, 9]);
expect(multiLineString.getCoordinateAtM(10.5, false, false)).to.eql(
[8.5, 9.5, 10.5]);
expect(multiLineString.getCoordinateAtM(12, false, false)).to.eql(
[10, 11, 12]);
null
);
expect(multiLineString.getCoordinateAtM(9, false, false)).to.eql([
7,
8,
9,
]);
expect(multiLineString.getCoordinateAtM(10.5, false, false)).to.eql([
8.5,
9.5,
10.5,
]);
expect(multiLineString.getCoordinateAtM(12, false, false)).to.eql([
10,
11,
12,
]);
expect(multiLineString.getCoordinateAtM(15, false, false)).to.eql(
null);
null
);
});
});
});
});
describe('construct with 4D coordinates', function() {
describe('construct with 4D coordinates', function () {
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]);
beforeEach(function () {
multiLineString = new MultiLineString([
[
[1, 2, 3, 4],
[5, 6, 7, 8],
],
[
[9, 10, 11, 12],
[13, 14, 15, 16],
],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiLineString.getLayout()).to.be('XYZM');
});
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]]]);
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],
],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiLineString.getExtent()).to.eql([1, 2, 13, 14]);
});
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]);
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,
]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiLineString.getStride()).to.be(4);
});
});
describe('#scale()', function() {
it('scales a multi-linestring', function() {
const geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
describe('#scale()', function () {
it('scales a multi-linestring', function () {
const geom = new MultiLineString([
[
[-10, -20],
[10, 20],
],
[
[5, -10],
[-5, 10],
],
]);
geom.scale(10);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-100, -200], [100, 200]], [[50, -100], [-50, 100]]]);
expect(coordinates).to.eql([
[
[-100, -200],
[100, 200],
],
[
[50, -100],
[-50, 100],
],
]);
});
it('accepts sx and sy', function() {
const geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
it('accepts sx and sy', function () {
const geom = new MultiLineString([
[
[-10, -20],
[10, 20],
],
[
[5, -10],
[-5, 10],
],
]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-20, -60], [20, 60]], [[10, -30], [-10, 30]]]);
expect(coordinates).to.eql([
[
[-20, -60],
[20, 60],
],
[
[10, -30],
[-10, 30],
],
]);
});
it('accepts an anchor', function() {
const geom = new MultiLineString([[[-10, -20], [10, 20]], [[5, -10], [-5, 10]]]);
it('accepts an anchor', function () {
const geom = new MultiLineString([
[
[-10, -20],
[10, 20],
],
[
[5, -10],
[-5, 10],
],
]);
geom.scale(3, 2, [10, 20]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-50, -60], [10, 20]], [[-5, -40], [-35, 0]]]);
expect(coordinates).to.eql([
[
[-50, -60],
[10, 20],
],
[
[-5, -40],
[-35, 0],
],
]);
});
});
describe('#setLineStrings', function() {
it('sets the line strings', function() {
const lineString1 = new LineString([[1, 2], [3, 4]]);
const lineString2 = new LineString([[5, 6], [7, 8]]);
describe('#setLineStrings', function () {
it('sets the line strings', function () {
const lineString1 = new LineString([
[1, 2],
[3, 4],
]);
const lineString2 = new LineString([
[5, 6],
[7, 8],
]);
const multiLineString = new MultiLineString([lineString1, lineString2]);
expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8]);
expect(multiLineString.getFlatCoordinates()).to.eql([
1,
2,
3,
4,
5,
6,
7,
8,
]);
expect(multiLineString.getEnds()).to.eql([4, 8]);
const coordinates = multiLineString.getCoordinates();
expect(coordinates[0]).to.eql(lineString1.getCoordinates());
@@ -355,15 +628,22 @@ describe('ol.geom.MultiLineString', function() {
});
});
describe('#containsXY()', function() {
describe('#containsXY()', function () {
let multiLineString;
beforeEach(function() {
multiLineString = new MultiLineString(
[[[1, 2, 3], [4, 5, 6]], [[-1, -1, 9], [2, 2, 12]]]);
beforeEach(function () {
multiLineString = new MultiLineString([
[
[1, 2, 3],
[4, 5, 6],
],
[
[-1, -1, 9],
[2, 2, 12],
],
]);
});
it('does contain XY', function() {
it('does contain XY', function () {
expect(multiLineString.containsXY(1, 2)).to.be(true);
expect(multiLineString.containsXY(4, 5)).to.be(true);
expect(multiLineString.containsXY(3, 4)).to.be(true);
@@ -373,12 +653,10 @@ describe('ol.geom.MultiLineString', function() {
expect(multiLineString.containsXY(0, 0)).to.be(true);
});
it('does not contain XY', function() {
it('does not contain XY', function () {
expect(multiLineString.containsXY(1, 3)).to.be(false);
expect(multiLineString.containsXY(2, 11)).to.be(false);
expect(multiLineString.containsXY(-2, 3)).to.be(false);
});
});
});
+144 -108
View File
@@ -1,151 +1,163 @@
import {isEmpty} from '../../../../src/ol/extent.js';
import MultiPoint from '../../../../src/ol/geom/MultiPoint.js';
import Point from '../../../../src/ol/geom/Point.js';
import {isEmpty} from '../../../../src/ol/extent.js';
describe('ol.geom.MultiPoint', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol.geom.MultiPoint', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new MultiPoint(null);
}).to.throwException();
});
describe('construct empty', function() {
describe('construct empty', function () {
let multiPoint;
beforeEach(function() {
beforeEach(function () {
multiPoint = new MultiPoint([]);
});
it('defaults to layout XY', function() {
it('defaults to layout XY', function () {
expect(multiPoint.getLayout()).to.be('XY');
});
it('has empty coordinates', function() {
it('has empty coordinates', function () {
expect(multiPoint.getCoordinates()).to.be.empty();
});
it('has an empty extent', function() {
it('has an empty extent', function () {
expect(isEmpty(multiPoint.getExtent())).to.be(true);
});
it('has empty flat coordinates', function() {
it('has empty flat coordinates', function () {
expect(multiPoint.getFlatCoordinates()).to.be.empty();
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiPoint.getStride()).to.be(2);
});
it('can append points', function() {
it('can append points', function () {
multiPoint.appendPoint(new Point([1, 2]));
expect(multiPoint.getCoordinates()).to.eql([[1, 2]]);
multiPoint.appendPoint(new Point([3, 4]));
expect(multiPoint.getCoordinates()).to.eql([[1, 2], [3, 4]]);
expect(multiPoint.getCoordinates()).to.eql([
[1, 2],
[3, 4],
]);
});
});
describe('construct with 2D coordinates', function() {
describe('construct with 2D coordinates', function () {
let multiPoint;
beforeEach(function() {
multiPoint = new MultiPoint([[1, 2], [3, 4]]);
beforeEach(function () {
multiPoint = new MultiPoint([
[1, 2],
[3, 4],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiPoint.getLayout()).to.be('XY');
});
it('has the expected coordinates', function() {
expect(multiPoint.getCoordinates()).to.eql([[1, 2], [3, 4]]);
it('has the expected coordinates', function () {
expect(multiPoint.getCoordinates()).to.eql([
[1, 2],
[3, 4],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiPoint.getExtent()).to.eql([1, 2, 3, 4]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(multiPoint.getFlatCoordinates()).to.eql([1, 2, 3, 4]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(multiPoint.getStride()).to.be(2);
});
describe('#intersectsExtent()', function() {
it('returns true for extent covering a point', function() {
describe('#intersectsExtent()', function () {
it('returns true for extent covering a point', function () {
expect(multiPoint.intersectsExtent([1, 2, 2, 2])).to.be(true);
});
it('returns false for non-matching extent within own extent', function() {
it('returns false for non-matching extent within own extent', function () {
expect(multiPoint.intersectsExtent([2, 3, 2, 4])).to.be(false);
});
});
});
describe('construct with 3D coordinates', function() {
describe('construct with 3D coordinates', function () {
let multiPoint;
beforeEach(function() {
multiPoint = new MultiPoint([[1, 2, 3], [4, 5, 6]]);
beforeEach(function () {
multiPoint = new MultiPoint([
[1, 2, 3],
[4, 5, 6],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiPoint.getLayout()).to.be('XYZ');
});
it('has the expected coordinates', function() {
expect(multiPoint.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
it('has the expected coordinates', function () {
expect(multiPoint.getCoordinates()).to.eql([
[1, 2, 3],
[4, 5, 6],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiPoint.getExtent()).to.eql([1, 2, 4, 5]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(multiPoint.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(multiPoint.getStride()).to.be(3);
});
});
describe('construct with 3D coordinates and layout XYM', function() {
describe('construct with 3D coordinates and layout XYM', function () {
let multiPoint;
beforeEach(function() {
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() {
it('has the expected layout', function () {
expect(multiPoint.getLayout()).to.be('XYM');
});
it('has the expected coordinates', function() {
expect(multiPoint.getCoordinates()).to.eql([[1, 2, 3], [4, 5, 6]]);
it('has the expected coordinates', function () {
expect(multiPoint.getCoordinates()).to.eql([
[1, 2, 3],
[4, 5, 6],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiPoint.getExtent()).to.eql([1, 2, 4, 5]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(multiPoint.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(multiPoint.getStride()).to.be(3);
});
it('can return individual points', function() {
it('can return individual points', function () {
const point0 = multiPoint.getPoint(0);
expect(point0.getLayout()).to.be('XYM');
expect(point0.getCoordinates()).to.eql([1, 2, 3]);
@@ -154,7 +166,7 @@ describe('ol.geom.MultiPoint', function() {
expect(point1.getCoordinates()).to.eql([4, 5, 6]);
});
it('can return all points', function() {
it('can return all points', function () {
const points = multiPoint.getPoints();
expect(points).to.have.length(2);
expect(points[0]).to.be.an(Point);
@@ -164,81 +176,100 @@ describe('ol.geom.MultiPoint', function() {
expect(points[1].getLayout()).to.be('XYM');
expect(points[1].getCoordinates()).to.eql([4, 5, 6]);
});
});
describe('construct with 4D coordinates', function() {
describe('construct with 4D coordinates', function () {
let multiPoint;
beforeEach(function() {
multiPoint = new MultiPoint([[1, 2, 3, 4], [5, 6, 7, 8]]);
beforeEach(function () {
multiPoint = new MultiPoint([
[1, 2, 3, 4],
[5, 6, 7, 8],
]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(multiPoint.getLayout()).to.be('XYZM');
});
it('has the expected coordinates', function() {
expect(multiPoint.getCoordinates()).to.eql([[1, 2, 3, 4], [5, 6, 7, 8]]);
it('has the expected coordinates', function () {
expect(multiPoint.getCoordinates()).to.eql([
[1, 2, 3, 4],
[5, 6, 7, 8],
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(multiPoint.getExtent()).to.eql([1, 2, 5, 6]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(multiPoint.getFlatCoordinates()).to.eql([1, 2, 3, 4, 5, 6, 7, 8]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(multiPoint.getStride()).to.be(4);
});
describe('#getClosestPoint', function() {
it('preserves extra dimensions', function() {
describe('#getClosestPoint', function () {
it('preserves extra dimensions', function () {
const closestPoint = multiPoint.getClosestPoint([6, 6]);
expect(closestPoint).to.eql([5, 6, 7, 8]);
});
});
});
describe('#scale()', function() {
it('scales a multi-point', function() {
const geom = new MultiPoint([[-10, -20], [10, 20]]);
describe('#scale()', function () {
it('scales a multi-point', function () {
const geom = new MultiPoint([
[-10, -20],
[10, 20],
]);
geom.scale(10);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-100, -200], [100, 200]]);
expect(coordinates).to.eql([
[-100, -200],
[100, 200],
]);
});
it('accepts sx and sy', function() {
const geom = new MultiPoint([[-10, -20], [10, 20]]);
it('accepts sx and sy', function () {
const geom = new MultiPoint([
[-10, -20],
[10, 20],
]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-20, -60], [20, 60]]);
expect(coordinates).to.eql([
[-20, -60],
[20, 60],
]);
});
it('accepts an anchor', function() {
const geom = new MultiPoint([[-10, -20], [10, 20]]);
it('accepts an anchor', function () {
const geom = new MultiPoint([
[-10, -20],
[10, 20],
]);
geom.scale(3, 2, [-10, -20]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[-10, -20], [50, 60]]);
expect(coordinates).to.eql([
[-10, -20],
[50, 60],
]);
});
});
describe('#applyTransform()', function() {
describe('#applyTransform()', function () {
let multi, transform;
beforeEach(function() {
multi = new MultiPoint([[1, 2], [3, 4]]);
beforeEach(function () {
multi = new MultiPoint([
[1, 2],
[3, 4],
]);
transform = sinon.spy();
});
it('calls a transform function', function() {
it('calls a transform function', function () {
multi.applyTransform(transform);
expect(transform.calledOnce).to.be(true);
const args = transform.firstCall.args;
@@ -249,8 +280,8 @@ describe('ol.geom.MultiPoint', function() {
expect(args[2]).to.be(2); // dimension
});
it('allows for modification of coordinates', function() {
const mod = function(input, output, dimension) {
it('allows for modification of coordinates', function () {
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];
@@ -258,21 +289,24 @@ describe('ol.geom.MultiPoint', function() {
}
};
multi.applyTransform(mod);
expect(multi.getCoordinates()).to.eql([[2, 1], [4, 3]]);
expect(multi.getCoordinates()).to.eql([
[2, 1],
[4, 3],
]);
});
it('returns undefined', function() {
it('returns undefined', function () {
const got = multi.applyTransform(transform);
expect(got).to.be(undefined);
});
});
describe('#transform()', function() {
it('transforms a geometry given CRS identifiers', function() {
const multi = new MultiPoint([[-111, 45], [111, -45]]).transform(
'EPSG:4326', 'EPSG:3857');
describe('#transform()', function () {
it('transforms a geometry given CRS identifiers', function () {
const multi = new MultiPoint([
[-111, 45],
[111, -45],
]).transform('EPSG:4326', 'EPSG:3857');
expect(multi).to.be.a(MultiPoint);
@@ -284,20 +318,24 @@ describe('ol.geom.MultiPoint', function() {
expect(coords[1][0]).to.roughlyEqual(12356463.47, 1e-2);
expect(coords[1][1]).to.roughlyEqual(-5621521.48, 1e-2);
});
});
describe('#containsXY()', function() {
it('does contain XY', function() {
const multi = new MultiPoint([[1, 2], [10, 20]]);
describe('#containsXY()', function () {
it('does contain XY', function () {
const multi = new MultiPoint([
[1, 2],
[10, 20],
]);
expect(multi.containsXY(1, 2)).to.be(true);
expect(multi.containsXY(10, 20)).to.be(true);
});
it('does not contain XY', function() {
const multi = new MultiPoint([[1, 2], [10, 20]]);
it('does not contain XY', function () {
const multi = new MultiPoint([
[1, 2],
[10, 20],
]);
expect(multi.containsXY(1, 3)).to.be(false);
expect(multi.containsXY(2, 2)).to.be(false);
@@ -307,7 +345,5 @@ describe('ol.geom.MultiPoint', function() {
expect(multi.containsXY(20, 20)).to.be(false);
expect(multi.containsXY(20, 30)).to.be(false);
});
});
});
+378 -138
View File
@@ -1,216 +1,456 @@
import MultiPolygon from '../../../../src/ol/geom/MultiPolygon.js';
import Polygon from '../../../../src/ol/geom/Polygon.js';
describe('ol.geom.MultiPolygon', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol.geom.MultiPolygon', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new MultiPolygon(null);
}).to.throwException();
});
describe('with a null MultiPolygon', function() {
it('can append polygons', function() {
describe('with a null MultiPolygon', function () {
it('can append polygons', function () {
const multiPolygon = new MultiPolygon([
new Polygon([[[0, 0], [0, 2], [1, 1], [2, 0]]])]);
expect(multiPolygon.getCoordinates()).to.eql(
[[[[0, 0], [0, 2], [1, 1], [2, 0]]]]);
multiPolygon.appendPolygon(
new Polygon([[[3, 0], [4, 1], [5, 2], [5, 0]]]));
new Polygon([
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
]),
]);
expect(multiPolygon.getCoordinates()).to.eql([
[[[0, 0], [0, 2], [1, 1], [2, 0]]],
[[[3, 0], [4, 1], [5, 2], [5, 0]]]
[
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
],
]);
multiPolygon.appendPolygon(
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],
],
],
]);
expect(multiPolygon.getPolygons().length).to.eql(2);
});
});
describe('with an empty MultiPolygon', function() {
describe('with an empty MultiPolygon', function () {
let multiPolygon;
beforeEach(function() {
beforeEach(function () {
multiPolygon = new MultiPolygon([]);
});
it('can append polygons', function() {
it('can append polygons', function () {
multiPolygon.appendPolygon(
new Polygon([[[0, 0], [0, 2], [1, 1], [2, 0]]]));
expect(multiPolygon.getCoordinates()).to.eql(
[[[[0, 0], [0, 2], [1, 1], [2, 0]]]]);
multiPolygon.appendPolygon(
new Polygon([[[3, 0], [4, 1], [5, 2], [5, 0]]]));
new Polygon([
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
])
);
expect(multiPolygon.getCoordinates()).to.eql([
[[[0, 0], [0, 2], [1, 1], [2, 0]]],
[[[3, 0], [4, 1], [5, 2], [5, 0]]]
[
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
],
]);
multiPolygon.appendPolygon(
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],
],
],
]);
expect(multiPolygon.getPolygons().length).to.eql(2);
});
});
describe('#scale()', function() {
it('scales a multi-polygon', function() {
const geom = new MultiPolygon([[
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
]]);
describe('#scale()', function () {
it('scales a multi-polygon', function () {
const geom = new MultiPolygon([
[
[
[-1, -2],
[1, -2],
[1, 2],
[-1, 2],
[-1, -2],
],
],
]);
geom.scale(10);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[[-10, -20], [10, -20], [10, 20], [-10, 20], [-10, -20]]]]);
});
it('accepts sx and sy', function() {
const geom = new MultiPolygon([[
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
]]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[[-2, -6], [2, -6], [2, 6], [-2, 6], [-2, -6]]]]);
});
it('accepts an anchor', function() {
const geom = new MultiPolygon([[
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
]]);
geom.scale(3, 2, [-1, -2]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[[-1, -2], [5, -2], [5, 6], [-1, 6], [-1, -2]]]]);
});
});
describe('with a simple MultiPolygon', function() {
let multiPolygon;
beforeEach(function() {
multiPolygon = new MultiPolygon([
[[[0, 0], [0, 2], [1, 1], [2, 0]]],
[[[3, 0], [4, 1], [5, 2], [5, 0]]]
expect(coordinates).to.eql([
[
[
[-10, -20],
[10, -20],
[10, 20],
[-10, 20],
[-10, -20],
],
],
]);
});
it('can return individual polygons', function() {
const polygon0 = multiPolygon.getPolygon(0);
expect(polygon0).to.be.an(Polygon);
expect(polygon0.getCoordinates()).to.eql(
[[[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]]]);
it('accepts sx and sy', function () {
const geom = new MultiPolygon([
[
[
[-1, -2],
[1, -2],
[1, 2],
[-1, 2],
[-1, -2],
],
],
]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([
[
[
[-2, -6],
[2, -6],
[2, 6],
[-2, 6],
[-2, -6],
],
],
]);
});
it('can return all polygons', function() {
it('accepts an anchor', function () {
const geom = new MultiPolygon([
[
[
[-1, -2],
[1, -2],
[1, 2],
[-1, 2],
[-1, -2],
],
],
]);
geom.scale(3, 2, [-1, -2]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([
[
[
[-1, -2],
[5, -2],
[5, 6],
[-1, 6],
[-1, -2],
],
],
]);
});
});
describe('with a simple MultiPolygon', function () {
let multiPolygon;
beforeEach(function () {
multiPolygon = new MultiPolygon([
[
[
[0, 0],
[0, 2],
[1, 1],
[2, 0],
],
],
[
[
[3, 0],
[4, 1],
[5, 2],
[5, 0],
],
],
]);
});
it('can return individual polygons', function () {
const polygon0 = multiPolygon.getPolygon(0);
expect(polygon0).to.be.an(Polygon);
expect(polygon0.getCoordinates()).to.eql([
[
[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],
],
]);
});
it('can return all polygons', function () {
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]]]);
expect(polygons[0].getCoordinates()).to.eql([
[
[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]]]);
expect(polygons[1].getCoordinates()).to.eql([
[
[3, 0],
[4, 1],
[5, 2],
[5, 0],
],
]);
});
describe('#clone()', function() {
it('has the expected endss_', function() {
describe('#clone()', function () {
it('has the expected endss_', function () {
const clone = multiPolygon.clone();
expect(multiPolygon.endss_).to.eql(clone.endss_);
});
});
describe('#getCoordinates()', function() {
describe('#getCoordinates()', function () {
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],
]);
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]]);
expect(left.getCoordinates()).to.eql([[cw, ccw], [cw2, ccw2]]);
it('returns coordinates as they were constructed', function () {
expect(right.getCoordinates()).to.eql([
[ccw, cw],
[ccw2, cw2],
]);
expect(left.getCoordinates()).to.eql([
[cw, ccw],
[cw2, ccw2],
]);
});
it('can return coordinates with right-hand orientation', function() {
expect(right.getCoordinates(true)).to.eql([[ccw, cw], [ccw2, cw2]]);
expect(left.getCoordinates(true)).to.eql([[ccw, cw], [ccw2, cw2]]);
it('can return coordinates with right-hand orientation', function () {
expect(right.getCoordinates(true)).to.eql([
[ccw, cw],
[ccw2, cw2],
]);
expect(left.getCoordinates(true)).to.eql([
[ccw, cw],
[ccw2, cw2],
]);
});
it('can return coordinates with left-hand orientation', function() {
expect(right.getCoordinates(false)).to.eql([[cw, ccw], [cw2, ccw2]]);
expect(left.getCoordinates(false)).to.eql([[cw, ccw], [cw2, ccw2]]);
});
});
describe('#getExtent()', function() {
it('returns expected result', function() {
expect(multiPolygon.getExtent()).to.eql([0, 0, 5, 2]);
});
});
describe('#getSimplifiedGeometry', function() {
it('returns the expected result', function() {
const simplifiedGeometry = multiPolygon.getSimplifiedGeometry(1);
expect(simplifiedGeometry).to.be.an(MultiPolygon);
expect(simplifiedGeometry.getCoordinates()).to.eql([
[[[0, 0], [0, 2], [2, 0]]],
[[[3, 0], [5, 2], [5, 0]]]
it('can return coordinates with left-hand orientation', function () {
expect(right.getCoordinates(false)).to.eql([
[cw, ccw],
[cw2, ccw2],
]);
expect(left.getCoordinates(false)).to.eql([
[cw, ccw],
[cw2, ccw2],
]);
});
});
describe('#intersectsExtent()', function() {
describe('#getExtent()', function () {
it('returns expected result', function () {
expect(multiPolygon.getExtent()).to.eql([0, 0, 5, 2]);
});
});
it('returns true for extent of of each polygon', function() {
describe('#getSimplifiedGeometry', function () {
it('returns the expected result', function () {
const simplifiedGeometry = multiPolygon.getSimplifiedGeometry(1);
expect(simplifiedGeometry).to.be.an(MultiPolygon);
expect(simplifiedGeometry.getCoordinates()).to.eql([
[
[
[0, 0],
[0, 2],
[2, 0],
],
],
[
[
[3, 0],
[5, 2],
[5, 0],
],
],
]);
});
});
describe('#intersectsExtent()', function () {
it('returns true for extent of of each polygon', function () {
const polygons = multiPolygon.getPolygons();
for (let i = 0; i < polygons.length; i++) {
expect(multiPolygon.intersectsExtent(
polygons[i].getExtent())).to.be(true);
expect(multiPolygon.intersectsExtent(polygons[i].getExtent())).to.be(
true
);
}
});
it('returns false for non-matching extent within own extent', function() {
it('returns false for non-matching extent within own extent', function () {
expect(multiPolygon.intersectsExtent([2.1, 0, 2.9, 2])).to.be(false);
});
});
});
describe('#getArea', function() {
it('works with a clockwise and a counterclockwise Polygon', function() {
describe('#getArea', function () {
it('works with a clockwise and a counterclockwise Polygon', function () {
const multiPolygon = new MultiPolygon([
[[[1, 3], [1, 2], [0, 2], [1, 3]]], // clockwise polygon with area 0.5
[[[2, 1], [2, 0.5], [3, 1], [2, 1]]] // counterclockwise polygon with area 0.25
[
[
[1, 3],
[1, 2],
[0, 2],
[1, 3],
],
], // clockwise polygon with area 0.5
[
[
[2, 1],
[2, 0.5],
[3, 1],
[2, 1],
],
], // counterclockwise polygon with area 0.25
]);
expect(multiPolygon.getArea()).to.be(0.75);
});
});
describe('#getInteriorPoints', function() {
it('returns XYM multipoint with intersection width as M', function() {
describe('#getInteriorPoints', function () {
it('returns XYM multipoint with intersection width as M', function () {
const geom = new MultiPolygon([
[[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]],
[[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]
[
[
[0, 0],
[0, 1],
[1, 1],
[1, 0],
[0, 0],
],
],
[
[
[1, 1],
[1, 2],
[2, 2],
[2, 1],
[1, 1],
],
],
]);
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]]);
expect(interiorPoints.getCoordinates()).to.eql([
[0.5, 0.5, 1],
[1.5, 1.5, 1],
]);
});
});
});
+57 -76
View File
@@ -1,163 +1,153 @@
import Point from '../../../../src/ol/geom/Point.js';
import {get as getProjection, getTransformFromProjections} from '../../../../src/ol/proj.js';
import {
get as getProjection,
getTransformFromProjections,
} from '../../../../src/ol/proj.js';
describe('ol.geom.Point', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol.geom.Point', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new Point(null);
}).to.throwException();
});
describe('construct with 2D coordinates', function() {
describe('construct with 2D coordinates', function () {
let point;
beforeEach(function() {
beforeEach(function () {
point = new Point([1, 2]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(point.getLayout()).to.be('XY');
});
it('has the expected coordinates', function() {
it('has the expected coordinates', function () {
expect(point.getCoordinates()).to.eql([1, 2]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(point.getExtent()).to.eql([1, 2, 1, 2]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(point.getFlatCoordinates()).to.eql([1, 2]);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(point.getStride()).to.be(2);
});
it('does not intersect non matching extent', function() {
it('does not intersect non matching extent', function () {
expect(point.intersectsExtent([0, 0, 10, 0.5])).to.be(false);
});
it('does intersect it\'s extent', function() {
it("does intersect it's extent", function () {
expect(point.intersectsExtent(point.getExtent())).to.be(true);
});
});
describe('construct with 3D coordinates and layout XYM', function() {
describe('construct with 3D coordinates and layout XYM', function () {
let point;
beforeEach(function() {
beforeEach(function () {
point = new Point([1, 2, 3], 'XYM');
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(point.getLayout()).to.be('XYM');
});
it('has the expected coordinates', function() {
it('has the expected coordinates', function () {
expect(point.getCoordinates()).to.eql([1, 2, 3]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(point.getExtent()).to.eql([1, 2, 1, 2]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(point.getFlatCoordinates()).to.eql([1, 2, 3]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(point.getStride()).to.be(3);
});
it('does not intersect non matching extent', function() {
it('does not intersect non matching extent', function () {
expect(point.intersectsExtent([0, 0, 10, 0.5])).to.be(false);
});
it('does intersect it\'s extent', function() {
it("does intersect it's extent", function () {
expect(point.intersectsExtent(point.getExtent())).to.be(true);
});
});
describe('construct with 4D coordinates', function() {
describe('construct with 4D coordinates', function () {
let point;
beforeEach(function() {
beforeEach(function () {
point = new Point([1, 2, 3, 4]);
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(point.getLayout()).to.be('XYZM');
});
it('has the expected coordinates', function() {
it('has the expected coordinates', function () {
expect(point.getCoordinates()).to.eql([1, 2, 3, 4]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(point.getExtent()).to.eql([1, 2, 1, 2]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(point.getFlatCoordinates()).to.eql([1, 2, 3, 4]);
});
it('has the expected stride', function() {
it('has the expected stride', function () {
expect(point.getStride()).to.be(4);
});
it('does not intersect non matching extent', function() {
it('does not intersect non matching extent', function () {
expect(point.intersectsExtent([0, 0, 10, 0.5])).to.be(false);
});
it('does intersect it\'s extent', function() {
it("does intersect it's extent", function () {
expect(point.intersectsExtent(point.getExtent())).to.be(true);
});
describe('#getClosestPoint', function() {
it('preseves extra dimensions', function() {
describe('#getClosestPoint', function () {
it('preseves extra dimensions', function () {
const closestPoint = point.getClosestPoint([0, 0]);
expect(closestPoint).to.eql([1, 2, 3, 4]);
});
});
});
describe('#scale()', function() {
it('scales a point', function() {
describe('#scale()', function () {
it('scales a point', function () {
const geom = new Point([1, 2]);
geom.scale(10e6);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([1, 2]);
});
it('accepts sx and sy', function() {
it('accepts sx and sy', function () {
const geom = new Point([1, 2]);
geom.scale(1e6, -42);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([1, 2]);
});
it('accepts an anchor', function() {
it('accepts an anchor', function () {
const geom = new Point([1, 2]);
geom.scale(10, 15, [0, 0]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([10, 30]);
});
});
describe('#simplifyTransformed()', function() {
it('returns the same result if called twice with the same arguments', function() {
describe('#simplifyTransformed()', function () {
it('returns the same result if called twice with the same arguments', function () {
const geom = new Point([1, 2]);
const source = getProjection('EPSG:4326');
const dest = getProjection('EPSG:3857');
@@ -168,7 +158,7 @@ describe('ol.geom.Point', function() {
expect(second).to.be(first);
});
it('returns a different result if called with a different tolerance', function() {
it('returns a different result if called with a different tolerance', function () {
const geom = new Point([1, 2]);
const source = getProjection('EPSG:4326');
const dest = getProjection('EPSG:3857');
@@ -179,7 +169,7 @@ describe('ol.geom.Point', function() {
expect(second).not.to.be(first);
});
it('returns a different result if called after geometry modification', function() {
it('returns a different result if called after geometry modification', function () {
const geom = new Point([1, 2]);
const source = getProjection('EPSG:4326');
const dest = getProjection('EPSG:3857');
@@ -191,18 +181,16 @@ describe('ol.geom.Point', function() {
const second = geom.simplifyTransformed(squaredTolerance * 2, transform);
expect(second).not.to.be(first);
});
});
describe('#applyTransform()', function() {
describe('#applyTransform()', function () {
let point, transform;
beforeEach(function() {
beforeEach(function () {
point = new Point([1, 2]);
transform = sinon.spy();
});
it('calls a transform function', function() {
it('calls a transform function', function () {
point.applyTransform(transform);
expect(transform.calledOnce).to.be(true);
const args = transform.firstCall.args;
@@ -213,8 +201,8 @@ describe('ol.geom.Point', function() {
expect(args[2]).to.be(2); // dimension
});
it('allows for modification of coordinates', function() {
const mod = function(input, output, dimension) {
it('allows for modification of coordinates', function () {
const mod = function (input, output, dimension) {
const copy = input.slice();
output[1] = copy[0];
output[0] = copy[1];
@@ -223,18 +211,15 @@ describe('ol.geom.Point', function() {
expect(point.getCoordinates()).to.eql([2, 1]);
});
it('returns undefined', function() {
it('returns undefined', function () {
const got = point.applyTransform(transform);
expect(got).to.be(undefined);
});
});
describe('#transform()', function() {
it('transforms a geometry given CRS identifiers', function() {
const point = new Point([-111, 45]).transform(
'EPSG:4326', 'EPSG:3857');
describe('#transform()', function () {
it('transforms a geometry given CRS identifiers', function () {
const point = new Point([-111, 45]).transform('EPSG:4326', 'EPSG:3857');
expect(point).to.be.a(Point);
@@ -244,7 +229,7 @@ describe('ol.geom.Point', function() {
expect(coords[1]).to.roughlyEqual(5621521.48, 1e-2);
});
it('modifies the original', function() {
it('modifies the original', function () {
const point = new Point([-111, 45]);
point.transform('EPSG:4326', 'EPSG:3857');
const coords = point.getCoordinates();
@@ -252,25 +237,21 @@ describe('ol.geom.Point', function() {
expect(coords[0]).to.roughlyEqual(-12356463.47, 1e-2);
expect(coords[1]).to.roughlyEqual(5621521.48, 1e-2);
});
});
describe('#containsXY()', function() {
it('does contain XY', function() {
describe('#containsXY()', function () {
it('does contain XY', function () {
const point = new Point([1, 2]);
expect(point.containsXY(1, 2)).to.be(true);
});
it('does not contain XY', function() {
it('does not contain XY', function () {
const point = new Point([1, 2]);
expect(point.containsXY(1, 3)).to.be(false);
expect(point.containsXY(2, 2)).to.be(false);
expect(point.containsXY(2, 3)).to.be(false);
});
});
});
+376 -211
View File
@@ -1,64 +1,97 @@
import {isEmpty, boundingExtent} from '../../../../src/ol/extent.js';
import Circle from '../../../../src/ol/geom/Circle.js';
import LinearRing from '../../../../src/ol/geom/LinearRing.js';
import Polygon, {fromCircle, fromExtent} from '../../../../src/ol/geom/Polygon.js';
import Polygon, {
fromCircle,
fromExtent,
} from '../../../../src/ol/geom/Polygon.js';
import {boundingExtent, isEmpty} from '../../../../src/ol/extent.js';
describe('ol/geom/Polygon', function() {
it('cannot be constructed with a null geometry', function() {
expect(function() {
describe('ol/geom/Polygon', function () {
it('cannot be constructed with a null geometry', function () {
expect(function () {
return new Polygon(null);
}).to.throwException();
});
describe('construct empty', function() {
describe('construct empty', function () {
let polygon;
beforeEach(function() {
beforeEach(function () {
polygon = new Polygon([]);
});
it('defaults to layout XY', function() {
it('defaults to layout XY', function () {
expect(polygon.getLayout()).to.be('XY');
});
it('has empty coordinates', function() {
it('has empty coordinates', function () {
expect(polygon.getCoordinates()).to.be.empty();
});
it('has an empty extent', function() {
it('has an empty extent', function () {
expect(isEmpty(polygon.getExtent())).to.be(true);
});
it('has empty flat coordinates', function() {
it('has empty flat coordinates', function () {
expect(polygon.getFlatCoordinates()).to.be.empty();
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(polygon.getStride()).to.be(2);
});
it('can append linear rings', function() {
it('can append linear rings', function () {
polygon.appendLinearRing(
new LinearRing([[1, 2], [3, 4], [5, 6]]));
expect(polygon.getCoordinates()).to.eql(
[[[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],
],
]);
polygon.appendLinearRing(
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]]]);
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],
],
]);
});
});
describe('construct with 2D coordinates', function() {
describe('construct with 2D coordinates', function () {
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]];
beforeEach(function () {
outerRing = [
[0, 1],
[1, 4],
[4, 3],
[3, 0],
];
innerRing = [
[2, 2],
[3, 2],
[3, 3],
[2, 3],
];
polygon = new Polygon([outerRing, innerRing]);
flatCoordinates = [0, 1, 1, 4, 4, 3, 3, 0, 2, 2, 3, 2, 3, 3, 2, 3];
outsideOuter = [0, 4];
@@ -66,32 +99,32 @@ describe('ol/geom/Polygon', function() {
insideInner = [2.5, 3.5];
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(polygon.getLayout()).to.be('XY');
});
it('has the expected coordinates', function() {
it('has the expected coordinates', function () {
expect(polygon.getCoordinates()).to.eql([outerRing, innerRing]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(polygon.getExtent()).to.eql([0, 0, 4, 4]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(polygon.getStride()).to.be(2);
});
it('can return individual rings', function() {
it('can return individual rings', function () {
expect(polygon.getLinearRing(0).getCoordinates()).to.eql(outerRing);
expect(polygon.getLinearRing(1).getCoordinates()).to.eql(innerRing);
});
it('has the expected rings', function() {
it('has the expected rings', function () {
const linearRings = polygon.getLinearRings();
expect(linearRings).to.be.an(Array);
expect(linearRings).to.have.length(2);
@@ -101,7 +134,7 @@ describe('ol/geom/Polygon', function() {
expect(linearRings[1].getCoordinates()).to.eql(innerRing);
});
it('does not reverse any rings', function() {
it('does not reverse any rings', function () {
outerRing.reverse();
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
@@ -110,74 +143,88 @@ describe('ol/geom/Polygon', function() {
expect(coordinates[1]).to.eql(innerRing);
});
it('does not contain outside coordinates', function() {
it('does not contain outside coordinates', function () {
expect(polygon.intersectsCoordinate(outsideOuter)).to.be(false);
});
it('does contain inside coordinates', function() {
it('does contain inside coordinates', function () {
expect(polygon.intersectsCoordinate(inside)).to.be(true);
});
it('does not contain inside inner coordinates', function() {
it('does not contain inside inner coordinates', function () {
expect(polygon.intersectsCoordinate(insideInner)).to.be(false);
});
describe('#getCoordinates()', function() {
const cw = [[-180, -90], [-180, 90], [180, 90], [180, -90], [-180, -90]];
const ccw = [[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]];
describe('#getCoordinates()', function () {
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() {
it('returns coordinates as they were constructed', function () {
expect(right.getCoordinates()).to.eql([ccw, cw]);
expect(left.getCoordinates()).to.eql([cw, ccw]);
});
it('can return coordinates with right-hand orientation', function() {
it('can return coordinates with right-hand orientation', function () {
expect(right.getCoordinates(true)).to.eql([ccw, cw]);
expect(left.getCoordinates(true)).to.eql([ccw, cw]);
});
it('can return coordinates with left-hand orientation', function() {
it('can return coordinates with left-hand orientation', function () {
expect(right.getCoordinates(false)).to.eql([cw, ccw]);
expect(left.getCoordinates(false)).to.eql([cw, ccw]);
});
});
describe('#getOrientedFlatCoordinates', function() {
it('reverses the outer ring if necessary', function() {
describe('#getOrientedFlatCoordinates', function () {
it('reverses the outer ring if necessary', function () {
outerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses inner rings if necessary', function() {
it('reverses inner rings if necessary', function () {
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses all rings if necessary', function() {
it('reverses all rings if necessary', function () {
outerRing.reverse();
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
});
});
describe('construct with 3D coordinates', function() {
describe('construct with 3D coordinates', function () {
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]];
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]);
flatCoordinates = [0, 0, 1, 4, 4, 2, 4, 0, 3, 2, 1, 4, 3, 1, 5, 3, 2, 6];
outsideOuter = [1, 3];
@@ -185,203 +232,251 @@ describe('ol/geom/Polygon', function() {
insideInner = [2.9, 1.1];
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(polygon.getLayout()).to.be('XYZ');
});
it('has the expected coordinates', function() {
it('has the expected coordinates', function () {
expect(polygon.getCoordinates()).to.eql([outerRing, innerRing]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(polygon.getExtent()).to.eql([0, 0, 4, 4]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(polygon.getStride()).to.be(3);
});
it('does not contain outside coordinates', function() {
it('does not contain outside coordinates', function () {
expect(polygon.intersectsCoordinate(outsideOuter)).to.be(false);
});
it('does contain inside coordinates', function() {
it('does contain inside coordinates', function () {
expect(polygon.intersectsCoordinate(inside)).to.be(true);
});
it('does not contain inside inner coordinates', function() {
it('does not contain inside inner coordinates', function () {
expect(polygon.intersectsCoordinate(insideInner)).to.be(false);
});
describe('#intersectsExtent', function() {
it('does not intersect outside extent', function() {
expect(polygon.intersectsExtent(
boundingExtent([outsideOuter]))).to.be(false);
describe('#intersectsExtent', function () {
it('does not intersect outside extent', function () {
expect(polygon.intersectsExtent(boundingExtent([outsideOuter]))).to.be(
false
);
});
it('does intersect inside extent', function() {
expect(polygon.intersectsExtent(
boundingExtent([inside]))).to.be(true);
it('does intersect inside extent', function () {
expect(polygon.intersectsExtent(boundingExtent([inside]))).to.be(true);
});
it('does intersect boundary extent', function() {
it('does intersect boundary extent', function () {
const firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
const firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
expect(polygon.intersectsExtent(boundingExtent([[firstMidX,
firstMidY]]))).to.be(true);
expect(
polygon.intersectsExtent(boundingExtent([[firstMidX, firstMidY]]))
).to.be(true);
});
it('does not intersect extent fully contained by inner ring', function() {
expect(polygon.intersectsExtent(
boundingExtent([insideInner]))).to.be(false);
it('does not intersect extent fully contained by inner ring', function () {
expect(polygon.intersectsExtent(boundingExtent([insideInner]))).to.be(
false
);
});
});
describe('#getOrientedFlatCoordinates', function() {
it('reverses the outer ring if necessary', function() {
describe('#getOrientedFlatCoordinates', function () {
it('reverses the outer ring if necessary', function () {
outerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses inner rings if necessary', function() {
it('reverses inner rings if necessary', function () {
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses all rings if necessary', function() {
it('reverses all rings if necessary', function () {
outerRing.reverse();
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
});
});
describe('construct with 3D coordinates and layout XYM', function() {
describe('construct with 3D coordinates and layout XYM', function () {
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');
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');
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];
insideInner = [2.9, 1.1];
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(polygon.getLayout()).to.be('XYM');
});
it('has the expected coordinates', function() {
it('has the expected coordinates', function () {
expect(polygon.getCoordinates()).to.eql([outerRing, innerRing]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(polygon.getExtent()).to.eql([0, 0, 4, 4]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(polygon.getStride()).to.be(3);
});
it('does not contain outside coordinates', function() {
it('does not contain outside coordinates', function () {
expect(polygon.intersectsCoordinate(outsideOuter)).to.be(false);
});
it('does contain inside coordinates', function() {
it('does contain inside coordinates', function () {
expect(polygon.intersectsCoordinate(inside)).to.be(true);
});
it('does not contain inside inner coordinates', function() {
it('does not contain inside inner coordinates', function () {
expect(polygon.intersectsCoordinate(insideInner)).to.be(false);
});
describe('#intersectsExtent', function() {
it('does not intersect outside extent', function() {
expect(polygon.intersectsExtent(
boundingExtent([outsideOuter]))).to.be(false);
describe('#intersectsExtent', function () {
it('does not intersect outside extent', function () {
expect(polygon.intersectsExtent(boundingExtent([outsideOuter]))).to.be(
false
);
});
it('does intersect inside extent', function() {
expect(polygon.intersectsExtent(
boundingExtent([inside]))).to.be(true);
it('does intersect inside extent', function () {
expect(polygon.intersectsExtent(boundingExtent([inside]))).to.be(true);
});
it('does intersect boundary extent', function() {
it('does intersect boundary extent', function () {
const firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
const firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
expect(polygon.intersectsExtent(boundingExtent([[firstMidX,
firstMidY]]))).to.be(true);
expect(
polygon.intersectsExtent(boundingExtent([[firstMidX, firstMidY]]))
).to.be(true);
});
it('does not intersect extent fully contained by inner ring', function() {
expect(polygon.intersectsExtent(
boundingExtent([insideInner]))).to.be(false);
it('does not intersect extent fully contained by inner ring', function () {
expect(polygon.intersectsExtent(boundingExtent([insideInner]))).to.be(
false
);
});
});
describe('#getOrientedFlatCoordinates', function() {
it('reverses the outer ring if necessary', function() {
describe('#getOrientedFlatCoordinates', function () {
it('reverses the outer ring if necessary', function () {
outerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses inner rings if necessary', function() {
it('reverses inner rings if necessary', function () {
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses all rings if necessary', function() {
it('reverses all rings if necessary', function () {
outerRing.reverse();
innerRing.reverse();
polygon = new Polygon([outerRing, innerRing]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
});
});
describe('construct with 4D coordinates', function() {
describe('construct with 4D coordinates', function () {
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 =
[[2, 4, 7, 8], [4, 4, 9, 10], [4, 5, 11, 12], [2, 5, 13, 14]];
innerRing2 = [[3, 2, 15, 16], [4, 3, 17, 18], [2, 3, 19, 20]];
beforeEach(function () {
outerRing = [
[0, 6, 1, 2],
[6, 6, 3, 4],
[3, 0, 5, 6],
];
innerRing1 = [
[2, 4, 7, 8],
[4, 4, 9, 10],
[4, 5, 11, 12],
[2, 5, 13, 14],
];
innerRing2 = [
[3, 2, 15, 16],
[4, 3, 17, 18],
[2, 3, 19, 20],
];
polygon = new Polygon([outerRing, innerRing1, innerRing2]);
flatCoordinates = [
0, 6, 1, 2, 6, 6, 3, 4, 3, 0, 5, 6,
2, 4, 7, 8, 4, 4, 9, 10, 4, 5, 11, 12, 2, 5, 13, 14,
3, 2, 15, 16, 4, 3, 17, 18, 2, 3, 19, 20
0,
6,
1,
2,
6,
6,
3,
4,
3,
0,
5,
6,
2,
4,
7,
8,
4,
4,
9,
10,
4,
5,
11,
12,
2,
5,
13,
14,
3,
2,
15,
16,
4,
3,
17,
18,
2,
3,
19,
20,
];
outsideOuter = [1, 1];
inside = [3, 1];
@@ -389,161 +484,235 @@ describe('ol/geom/Polygon', function() {
insideInner2 = [3, 2.5];
});
it('has the expected layout', function() {
it('has the expected layout', function () {
expect(polygon.getLayout()).to.be('XYZM');
});
it('has the expected coordinates', function() {
expect(polygon.getCoordinates()).to.eql(
[outerRing, innerRing1, innerRing2]);
it('has the expected coordinates', function () {
expect(polygon.getCoordinates()).to.eql([
outerRing,
innerRing1,
innerRing2,
]);
});
it('has the expected extent', function() {
it('has the expected extent', function () {
expect(polygon.getExtent()).to.eql([0, 0, 6, 6]);
});
it('has the expected flat coordinates', function() {
it('has the expected flat coordinates', function () {
expect(polygon.getFlatCoordinates()).to.eql(flatCoordinates);
});
it('has stride the expected stride', function() {
it('has stride the expected stride', function () {
expect(polygon.getStride()).to.be(4);
});
it('does not contain outside coordinates', function() {
it('does not contain outside coordinates', function () {
expect(polygon.intersectsCoordinate(outsideOuter)).to.be(false);
});
it('does contain inside coordinates', function() {
it('does contain inside coordinates', function () {
expect(polygon.intersectsCoordinate(inside)).to.be(true);
});
it('does not contain inside inner coordinates', function() {
it('does not contain inside inner coordinates', function () {
expect(polygon.intersectsCoordinate(insideInner1)).to.be(false);
expect(polygon.intersectsCoordinate(insideInner2)).to.be(false);
});
describe('#intersectsExtent', function() {
it('does not intersect outside extent', function() {
expect(polygon.intersectsExtent(
boundingExtent([outsideOuter]))).to.be(false);
describe('#intersectsExtent', function () {
it('does not intersect outside extent', function () {
expect(polygon.intersectsExtent(boundingExtent([outsideOuter]))).to.be(
false
);
});
it('does intersect inside extent', function() {
expect(polygon.intersectsExtent(
boundingExtent([inside]))).to.be(true);
it('does intersect inside extent', function () {
expect(polygon.intersectsExtent(boundingExtent([inside]))).to.be(true);
});
it('does intersect boundary extent', function() {
it('does intersect boundary extent', function () {
const firstMidX = (outerRing[0][0] + outerRing[1][0]) / 2;
const firstMidY = (outerRing[0][1] + outerRing[1][1]) / 2;
expect(polygon.intersectsExtent(boundingExtent([[firstMidX,
firstMidY]]))).to.be(true);
expect(
polygon.intersectsExtent(boundingExtent([[firstMidX, firstMidY]]))
).to.be(true);
});
it('does not intersect extent fully contained by inner ring', function() {
expect(polygon.intersectsExtent(
boundingExtent([insideInner1]))).to.be(false);
expect(polygon.intersectsExtent(
boundingExtent([insideInner2]))).to.be(false);
it('does not intersect extent fully contained by inner ring', function () {
expect(polygon.intersectsExtent(boundingExtent([insideInner1]))).to.be(
false
);
expect(polygon.intersectsExtent(boundingExtent([insideInner2]))).to.be(
false
);
});
});
describe('#getOrientedFlatCoordinates', function() {
it('reverses the outer ring if necessary', function() {
describe('#getOrientedFlatCoordinates', function () {
it('reverses the outer ring if necessary', function () {
outerRing.reverse();
polygon = new Polygon([outerRing, innerRing1, innerRing2]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses inner rings if necessary', function() {
it('reverses inner rings if necessary', function () {
innerRing1.reverse();
innerRing2.reverse();
polygon = new Polygon([outerRing, innerRing1, innerRing2]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
it('reverses all rings if necessary', function() {
it('reverses all rings if necessary', function () {
outerRing.reverse();
innerRing1.reverse();
innerRing2.reverse();
polygon = new Polygon([outerRing, innerRing1, innerRing2]);
expect(polygon.getOrientedFlatCoordinates()).to.eql(flatCoordinates);
});
});
});
describe('with a simple polygon', function() {
describe('with a simple polygon', function () {
let polygon;
beforeEach(function() {
polygon = new Polygon(
[[[3, 0], [1, 3], [0, 6], [2, 6], [3, 7], [4, 6], [6, 6], [4, 3]]]);
beforeEach(function () {
polygon = new Polygon([
[
[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() {
describe('#getSimplifiedGeometry', function () {
it('returns the expected result', function () {
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]]]);
expect(simplifiedGeometry.getCoordinates()).to.eql([
[
[3, 0],
[0, 3],
[0, 6],
[6, 6],
[3, 3],
],
]);
});
});
});
describe('#scale()', function() {
it('scales a polygon', function() {
describe('#scale()', function () {
it('scales a polygon', function () {
const geom = new Polygon([
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
[
[-1, -2],
[1, -2],
[1, 2],
[-1, 2],
[-1, -2],
],
]);
geom.scale(10);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-10, -20], [10, -20], [10, 20], [-10, 20], [-10, -20]]]);
expect(coordinates).to.eql([
[
[-10, -20],
[10, -20],
[10, 20],
[-10, 20],
[-10, -20],
],
]);
});
it('accepts sx and sy', function() {
it('accepts sx and sy', function () {
const geom = new Polygon([
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
[
[-1, -2],
[1, -2],
[1, 2],
[-1, 2],
[-1, -2],
],
]);
geom.scale(2, 3);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-2, -6], [2, -6], [2, 6], [-2, 6], [-2, -6]]]);
expect(coordinates).to.eql([
[
[-2, -6],
[2, -6],
[2, 6],
[-2, 6],
[-2, -6],
],
]);
});
it('accepts an anchor', function() {
it('accepts an anchor', function () {
const geom = new Polygon([
[[-1, -2], [1, -2], [1, 2], [-1, 2], [-1, -2]]
[
[-1, -2],
[1, -2],
[1, 2],
[-1, 2],
[-1, -2],
],
]);
geom.scale(3, 2, [-1, -2]);
const coordinates = geom.getCoordinates();
expect(coordinates).to.eql([[[-1, -2], [5, -2], [5, 6], [-1, 6], [-1, -2]]]);
expect(coordinates).to.eql([
[
[-1, -2],
[5, -2],
[5, 6],
[-1, 6],
[-1, -2],
],
]);
});
});
describe('#getInteriorPoint', function() {
it('returns XYM point with intersection width as M', function() {
const geom = new Polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]);
describe('#getInteriorPoint', function () {
it('returns XYM point with intersection width as M', function () {
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() {
it('returns XYM point for donut polygons', function () {
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]]
[
[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],
],
]);
const interiorPoint = geom.getInteriorPoint();
expect(interiorPoint.getType()).to.be('Point');
@@ -552,22 +721,19 @@ describe('ol/geom/Polygon', function() {
});
});
describe('fromExtent()', function() {
it('creates the correct polygon', function() {
describe('fromExtent()', function () {
it('creates the correct polygon', function () {
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]);
expect(flatCoordinates).to.eql([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]);
expect(orientedFlatCoordinates).to.eql([1, 2, 1, 5, 3, 5, 3, 2, 1, 2]);
});
});
describe('fromCircle()', function() {
it('creates a regular polygon', function() {
describe('fromCircle()', function () {
it('creates a regular polygon', function () {
const circle = new Circle([0, 0, 0], 1, 'XYZ');
const polygon = fromCircle(circle);
const coordinates = polygon.getLinearRing(0).getCoordinates();
@@ -588,7 +754,7 @@ describe('ol/geom/Polygon', function() {
expect(coordinates[24][1]).to.roughlyEqual(-1, 1e-9);
});
it('creates a regular polygon with custom sides and angle', function() {
it('creates a regular polygon with custom sides and angle', function () {
const circle = new Circle([0, 0], 1);
const polygon = fromCircle(circle, 4, Math.PI / 2);
const coordinates = polygon.getLinearRing(0).getCoordinates();
@@ -605,5 +771,4 @@ describe('ol/geom/Polygon', function() {
expect(coordinates[0][3]).to.eql(1);
});
});
});