Add node tests
This commit is contained in:
28
test/node/ol/geom/flat/area.test.js
Normal file
28
test/node/ol/geom/flat/area.test.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {linearRing, linearRings} from '../../../../../src/ol/geom/flat/area.js';
|
||||
|
||||
describe('ol/geom/flat/area.js', function () {
|
||||
describe('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 () {
|
||||
const area = linearRing([0, 0, 0, 1, 1, 1, 1, 0], 0, 8, 2);
|
||||
expect(area).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('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
|
||||
);
|
||||
expect(area).to.be(8);
|
||||
});
|
||||
});
|
||||
});
|
||||
86
test/node/ol/geom/flat/center.test.js
Normal file
86
test/node/ol/geom/flat/center.test.js
Normal file
@@ -0,0 +1,86 @@
|
||||
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
|
||||
import expect from '../../../expect.js';
|
||||
import {linearRingss as linearRingssCenter} from '../../../../../src/ol/geom/flat/center.js';
|
||||
|
||||
describe('ol/geom/flat/center.js', function () {
|
||||
describe('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,
|
||||
squareMultiPoly.endss_,
|
||||
2
|
||||
);
|
||||
expect(got).to.eql([0.5, 0.5]);
|
||||
});
|
||||
|
||||
it('calculates the centers of two squares', function () {
|
||||
const squareMultiPoly = new MultiPolygon([
|
||||
[
|
||||
[
|
||||
[0, 0],
|
||||
[0, 1],
|
||||
[1, 1],
|
||||
[1, 0],
|
||||
[0, 0],
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
[3, 0],
|
||||
[3, 1],
|
||||
[4, 1],
|
||||
[4, 0],
|
||||
[3, 0],
|
||||
],
|
||||
],
|
||||
]);
|
||||
const got = linearRingssCenter(
|
||||
squareMultiPoly.flatCoordinates,
|
||||
0,
|
||||
squareMultiPoly.endss_,
|
||||
2
|
||||
);
|
||||
expect(got).to.eql([0.5, 0.5, 3.5, 0.5]);
|
||||
});
|
||||
|
||||
it('does not care about holes', function () {
|
||||
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,
|
||||
polywithHole.endss_,
|
||||
2
|
||||
);
|
||||
expect(got).to.eql([2.5, 2.5]);
|
||||
});
|
||||
});
|
||||
});
|
||||
391
test/node/ol/geom/flat/closest.test.js
Normal file
391
test/node/ol/geom/flat/closest.test.js
Normal file
@@ -0,0 +1,391 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
assignClosestPoint,
|
||||
maxSquaredDelta,
|
||||
} from '../../../../../src/ol/geom/flat/closest.js';
|
||||
|
||||
describe('ol/geom/flat/closest.js', function () {
|
||||
describe('with simple data', function () {
|
||||
const flatCoordinates = [0, 0, 1, 0, 3, 0, 5, 0, 6, 0, 8, 0, 11, 0];
|
||||
|
||||
describe('maxSquaredDelta', function () {
|
||||
it('returns the expected value in simple cases', function () {
|
||||
expect(
|
||||
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
|
||||
).to.be(9);
|
||||
});
|
||||
});
|
||||
|
||||
describe('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(closestPoint).to.eql([0, 0]);
|
||||
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(closestPoint).to.eql([5, 0]);
|
||||
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 () {
|
||||
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.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('maxSquaredDelta', function () {
|
||||
it('returns the expected value', function () {
|
||||
expect(
|
||||
maxSquaredDelta(flatCoordinates, 0, flatCoordinates.length, 2, 0)
|
||||
).to.roughlyEqual(1389.1058, 1e-9);
|
||||
});
|
||||
});
|
||||
|
||||
describe('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(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(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(closestPoint).to.eql([866.36, 480.77]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with multi-dimensional data', function () {
|
||||
const flatCoordinates = [0, 0, 10, -10, 2, 2, 30, -20];
|
||||
const stride = 4;
|
||||
|
||||
describe('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(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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
97
test/node/ol/geom/flat/contains.test.js
Normal file
97
test/node/ol/geom/flat/contains.test.js
Normal file
@@ -0,0 +1,97 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {linearRingContainsXY} from '../../../../../src/ol/geom/flat/contains.js';
|
||||
|
||||
describe('ol/geom/flat/contains.js', 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,
|
||||
];
|
||||
|
||||
describe('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 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 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
55
test/node/ol/geom/flat/deflate.test.js
Normal file
55
test/node/ol/geom/flat/deflate.test.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
deflateCoordinates,
|
||||
deflateCoordinatesArray,
|
||||
} from '../../../../../src/ol/geom/flat/deflate.js';
|
||||
|
||||
describe('ol/geom/flat/deflate.js', function () {
|
||||
describe('deflateCoordinates', function () {
|
||||
let flatCoordinates;
|
||||
beforeEach(function () {
|
||||
flatCoordinates = [];
|
||||
});
|
||||
|
||||
it('flattens coordinates', function () {
|
||||
const offset = deflateCoordinates(
|
||||
flatCoordinates,
|
||||
0,
|
||||
[
|
||||
[1, 2],
|
||||
[3, 4],
|
||||
],
|
||||
2
|
||||
);
|
||||
expect(offset).to.be(4);
|
||||
expect(flatCoordinates).to.eql([1, 2, 3, 4]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deflateCoordinatesArray', function () {
|
||||
let flatCoordinates;
|
||||
beforeEach(function () {
|
||||
flatCoordinates = [];
|
||||
});
|
||||
|
||||
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]);
|
||||
});
|
||||
});
|
||||
});
|
||||
32
test/node/ol/geom/flat/flip.test.js
Normal file
32
test/node/ol/geom/flat/flip.test.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {flipXY} from '../../../../../src/ol/geom/flat/flip.js';
|
||||
|
||||
describe('ol/geom/flat/flip.js', function () {
|
||||
describe('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 () {
|
||||
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 () {
|
||||
const flatCoordinates = [1, 2, 3, 4];
|
||||
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]);
|
||||
});
|
||||
});
|
||||
});
|
||||
38
test/node/ol/geom/flat/inflate.test.js
Normal file
38
test/node/ol/geom/flat/inflate.test.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
inflateCoordinates,
|
||||
inflateCoordinatesArray,
|
||||
} from '../../../../../src/ol/geom/flat/inflate.js';
|
||||
|
||||
describe('ol/geom/flat/inflate.js', function () {
|
||||
describe('inflateCoordinates', function () {
|
||||
it('inflates coordinates', function () {
|
||||
const coordinates = inflateCoordinates([1, 2, 3, 4], 0, 4, 2);
|
||||
expect(coordinates).to.eql([
|
||||
[1, 2],
|
||||
[3, 4],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('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],
|
||||
],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
68
test/node/ol/geom/flat/interpolate.test.js
Normal file
68
test/node/ol/geom/flat/interpolate.test.js
Normal file
@@ -0,0 +1,68 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {interpolatePoint} from '../../../../../src/ol/geom/flat/interpolate.js';
|
||||
|
||||
describe('ol/geom/flat/interpolate.js', function () {
|
||||
describe('interpolatePoint', function () {
|
||||
it('returns the expected value for single points', function () {
|
||||
const flatCoordinates = [0, 1];
|
||||
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 () {
|
||||
const flatCoordinates = [0, 1, 2, 3];
|
||||
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 ' +
|
||||
'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]);
|
||||
}
|
||||
);
|
||||
|
||||
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);
|
||||
expect(point).to.eql([2, 3]);
|
||||
});
|
||||
|
||||
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]);
|
||||
}
|
||||
);
|
||||
|
||||
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);
|
||||
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]);
|
||||
});
|
||||
});
|
||||
});
|
||||
203
test/node/ol/geom/flat/intersectsextent.test.js
Normal file
203
test/node/ol/geom/flat/intersectsextent.test.js
Normal file
@@ -0,0 +1,203 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
intersectsLineString,
|
||||
intersectsLinearRing,
|
||||
intersectsLinearRingArray,
|
||||
} from '../../../../../src/ol/geom/flat/intersectsextent.js';
|
||||
|
||||
describe('ol/geom/flat/intersectsextent.js', function () {
|
||||
describe('intersectsLineString', function () {
|
||||
let flatCoordinates;
|
||||
beforeEach(function () {
|
||||
flatCoordinates = [0, 0, 1, 1, 2, 2];
|
||||
});
|
||||
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
|
||||
);
|
||||
expect(r).to.be(false);
|
||||
});
|
||||
});
|
||||
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
|
||||
);
|
||||
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 () {
|
||||
const extent = [-0.5, -0.5, 0.5, 0.5];
|
||||
const r = intersectsLineString(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2,
|
||||
extent
|
||||
);
|
||||
expect(r).to.be(true);
|
||||
});
|
||||
});
|
||||
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
|
||||
);
|
||||
expect(r).to.be(false);
|
||||
});
|
||||
it('returns false', function () {
|
||||
const extent = [1, 0.25, 1.5, 0.5];
|
||||
const r = intersectsLineString(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2,
|
||||
extent
|
||||
);
|
||||
expect(r).to.be(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('intersectsLinearRing', function () {
|
||||
let flatCoordinates;
|
||||
beforeEach(function () {
|
||||
flatCoordinates = [0, 0, 1, 1, 2, 0, 1, -1, 0, 0];
|
||||
});
|
||||
describe('boundary intersects the extent', function () {
|
||||
it('returns true', function () {
|
||||
const extent = [1.5, 0.0, 2.5, 1.0];
|
||||
const r = intersectsLinearRing(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2,
|
||||
extent
|
||||
);
|
||||
expect(r).to.be(true);
|
||||
});
|
||||
});
|
||||
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 () {
|
||||
const extent = [0.75, -0.25, 1.25, 0.25];
|
||||
const r = intersectsLinearRing(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2,
|
||||
extent
|
||||
);
|
||||
expect(r).to.be(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('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,
|
||||
];
|
||||
ends = [10, flatCoordinates.length];
|
||||
});
|
||||
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
|
||||
);
|
||||
expect(r).to.be(false);
|
||||
});
|
||||
});
|
||||
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
|
||||
);
|
||||
expect(r).to.be(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
89
test/node/ol/geom/flat/length.test.js
Normal file
89
test/node/ol/geom/flat/length.test.js
Normal file
@@ -0,0 +1,89 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
lineStringLength,
|
||||
linearRingLength,
|
||||
} from '../../../../../src/ol/geom/flat/length.js';
|
||||
|
||||
describe('ol/geom/flat/length.js', function () {
|
||||
describe('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 () {
|
||||
const offset = 0;
|
||||
const end = 8;
|
||||
const expected = 3;
|
||||
const got = lineStringLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
it('calculates a partwise length of a lineString (offset)', function () {
|
||||
const offset = 2;
|
||||
const end = 8;
|
||||
const expected = 2;
|
||||
const got = lineStringLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
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 () {
|
||||
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 () {
|
||||
const offset = 0;
|
||||
const end = 12;
|
||||
const expected = 3;
|
||||
const got = lineStringLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
it('calculates a partwise length of a lineString (offset)', function () {
|
||||
const offset = 3;
|
||||
const end = 12;
|
||||
const expected = 2;
|
||||
const got = lineStringLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
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('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;
|
||||
const end = 8;
|
||||
const expected = 4;
|
||||
const got = linearRingLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
|
||||
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;
|
||||
const end = 14;
|
||||
const expected = 8;
|
||||
const got = linearRingLength(flatCoords, offset, end, stride);
|
||||
expect(got).to.be(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
443
test/node/ol/geom/flat/orient.test.js
Normal file
443
test/node/ol/geom/flat/orient.test.js
Normal file
@@ -0,0 +1,443 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
linearRingIsClockwise,
|
||||
linearRingsAreOriented,
|
||||
linearRingssAreOriented,
|
||||
orientLinearRings,
|
||||
orientLinearRingsArray,
|
||||
} from '../../../../../src/ol/geom/flat/orient.js';
|
||||
|
||||
describe('ol/geom/flat/orient.js', function () {
|
||||
describe('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
|
||||
);
|
||||
expect(isClockwise).to.be(true);
|
||||
});
|
||||
|
||||
it('identifies anti-clockwise rings', function () {
|
||||
const flatCoordinates = [2, 2, 3, 2, 3, 3, 2, 3];
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2
|
||||
);
|
||||
expect(isClockwise).to.be(false);
|
||||
});
|
||||
|
||||
it('identifies clockwise with duplicated coordinates', function () {
|
||||
const flatCoordinates = [0, 1, 0, 1, 1, 4, 1, 4, 4, 3, 4, 3, 3, 0, 3, 0];
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2
|
||||
);
|
||||
expect(isClockwise).to.be(true);
|
||||
});
|
||||
|
||||
it('identifies anti-clockwise with duplicated coordinates', function () {
|
||||
const flatCoordinates = [2, 2, 2, 2, 3, 2, 3, 2, 3, 3, 3, 3, 2, 3, 2, 3];
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2
|
||||
);
|
||||
expect(isClockwise).to.be(false);
|
||||
});
|
||||
|
||||
it('identifies clockwise when last coordinate equals first', function () {
|
||||
const flatCoordinates = [0, 1, 1, 4, 4, 3, 3, 0, 0, 1];
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2
|
||||
);
|
||||
expect(isClockwise).to.be(true);
|
||||
});
|
||||
|
||||
it('identifies anti-clockwise when last coordinate equals first', function () {
|
||||
const flatCoordinates = [2, 2, 3, 2, 3, 3, 2, 3, 2, 2];
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2
|
||||
);
|
||||
expect(isClockwise).to.be(false);
|
||||
});
|
||||
|
||||
it('returns undefined when ring has too few vertices', function () {
|
||||
const flatCoordinates = [2, 2, 3, 2];
|
||||
const isClockwise = linearRingIsClockwise(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2
|
||||
);
|
||||
expect(isClockwise).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('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,
|
||||
];
|
||||
|
||||
const leftCoords = [
|
||||
-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 () {
|
||||
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 () {
|
||||
expect(oriented(rightCoords, 0, ends, 2, true)).to.be(true);
|
||||
expect(oriented(leftCoords, 0, ends, 2, true)).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('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,
|
||||
];
|
||||
|
||||
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],
|
||||
[30, 40],
|
||||
];
|
||||
|
||||
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 () {
|
||||
expect(oriented(rightCoords, 0, ends, 2, true)).to.be(true);
|
||||
expect(oriented(leftCoords, 0, ends, 2, true)).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('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,
|
||||
];
|
||||
|
||||
const leftCoords = [
|
||||
-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 () {
|
||||
const rightClone = rightCoords.slice();
|
||||
orient(rightClone, 0, ends, 2);
|
||||
expect(rightClone).to.eql(leftCoords);
|
||||
|
||||
const leftClone = leftCoords.slice();
|
||||
orient(leftClone, 0, ends, 2);
|
||||
expect(leftClone).to.eql(leftCoords);
|
||||
});
|
||||
|
||||
it('can orient using the right-hand rule', function () {
|
||||
const rightClone = rightCoords.slice();
|
||||
orient(rightClone, 0, ends, 2, true);
|
||||
expect(rightClone).to.eql(rightCoords);
|
||||
|
||||
const leftClone = leftCoords.slice();
|
||||
orient(leftClone, 0, ends, 2, true);
|
||||
expect(leftClone).to.eql(rightCoords);
|
||||
});
|
||||
});
|
||||
|
||||
describe('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,
|
||||
];
|
||||
|
||||
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],
|
||||
[30, 40],
|
||||
];
|
||||
|
||||
it('orients using the left-hand rule by default', function () {
|
||||
const rightClone = rightCoords.slice();
|
||||
orient(rightClone, 0, ends, 2);
|
||||
expect(rightClone).to.eql(leftCoords);
|
||||
|
||||
const leftClone = leftCoords.slice();
|
||||
orient(leftClone, 0, ends, 2);
|
||||
expect(leftClone).to.eql(leftCoords);
|
||||
});
|
||||
|
||||
it('can orient using the right-hand rule', function () {
|
||||
const rightClone = rightCoords.slice();
|
||||
orient(rightClone, 0, ends, 2, true);
|
||||
expect(rightClone).to.eql(rightCoords);
|
||||
|
||||
const leftClone = leftCoords.slice();
|
||||
orient(leftClone, 0, ends, 2, true);
|
||||
expect(leftClone).to.eql(rightCoords);
|
||||
});
|
||||
});
|
||||
});
|
||||
136
test/node/ol/geom/flat/reverse.test.js
Normal file
136
test/node/ol/geom/flat/reverse.test.js
Normal file
@@ -0,0 +1,136 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {coordinates as reverseCoordinates} from '../../../../../src/ol/geom/flat/reverse.js';
|
||||
|
||||
describe('ol/geom/flat/reverse.js', function () {
|
||||
describe('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 () {
|
||||
const flatCoordinates = [1, 2];
|
||||
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 2);
|
||||
expect(flatCoordinates).to.eql([1, 2]);
|
||||
});
|
||||
|
||||
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 () {
|
||||
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 () {
|
||||
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 () {
|
||||
const flatCoordinates = [];
|
||||
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 3);
|
||||
expect(flatCoordinates).to.be.empty();
|
||||
});
|
||||
|
||||
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 () {
|
||||
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 () {
|
||||
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 () {
|
||||
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 () {
|
||||
const flatCoordinates = [];
|
||||
reverseCoordinates(flatCoordinates, 0, flatCoordinates.length, 4);
|
||||
expect(flatCoordinates).to.be.empty();
|
||||
});
|
||||
|
||||
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 () {
|
||||
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 () {
|
||||
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,
|
||||
];
|
||||
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,
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
54
test/node/ol/geom/flat/segments.test.js
Normal file
54
test/node/ol/geom/flat/segments.test.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import expect from '../../../expect.js';
|
||||
import sinon from 'sinon';
|
||||
import {forEach as forEachSegment} from '../../../../../src/ol/geom/flat/segments.js';
|
||||
|
||||
describe('ol/geom/flat/segments.js', function () {
|
||||
describe('forEach', function () {
|
||||
let flatCoordinates, offset, end, stride;
|
||||
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 () {
|
||||
const args = [];
|
||||
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);
|
||||
expect(spy.callCount).to.be(3);
|
||||
expect(args[0][0]).to.be(0);
|
||||
expect(args[0][1]).to.be(0);
|
||||
expect(args[0][2]).to.be(1);
|
||||
expect(args[0][3]).to.be(1);
|
||||
expect(args[1][0]).to.be(1);
|
||||
expect(args[1][1]).to.be(1);
|
||||
expect(args[1][2]).to.be(2);
|
||||
expect(args[1][3]).to.be(2);
|
||||
expect(args[2][0]).to.be(2);
|
||||
expect(args[2][1]).to.be(2);
|
||||
expect(args[2][2]).to.be(3);
|
||||
expect(args[2][3]).to.be(3);
|
||||
expect(ret).to.be(false);
|
||||
});
|
||||
});
|
||||
describe('callback returns true', function () {
|
||||
it('executes the callback for the first segment', function () {
|
||||
const args = [];
|
||||
const spy = sinon.spy(function (point1, point2) {
|
||||
args.push([point1[0], point1[1], point2[0], point2[1]]);
|
||||
return true;
|
||||
});
|
||||
const ret = forEachSegment(flatCoordinates, offset, end, stride, spy);
|
||||
expect(spy.callCount).to.be(1);
|
||||
expect(args[0][0]).to.be(0);
|
||||
expect(args[0][1]).to.be(0);
|
||||
expect(args[0][2]).to.be(1);
|
||||
expect(args[0][3]).to.be(1);
|
||||
expect(ret).to.be(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
916
test/node/ol/geom/flat/simplify.test.js
Normal file
916
test/node/ol/geom/flat/simplify.test.js
Normal file
@@ -0,0 +1,916 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {
|
||||
douglasPeucker,
|
||||
quantize,
|
||||
radialDistance,
|
||||
simplifyLineString,
|
||||
} from '../../../../../src/ol/geom/flat/simplify.js';
|
||||
|
||||
describe('ol/geom/flat/simplify.js', 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.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,
|
||||
];
|
||||
|
||||
const simplifiedRadiallyFlatCoordinates = [
|
||||
224.55,
|
||||
250.15,
|
||||
226.91,
|
||||
244.19,
|
||||
233.31,
|
||||
241.45,
|
||||
234.98,
|
||||
236.06,
|
||||
244.21,
|
||||
232.76,
|
||||
262.59,
|
||||
215.31,
|
||||
267.76,
|
||||
213.81,
|
||||
273.57,
|
||||
201.84,
|
||||
273.12,
|
||||
192.16,
|
||||
277.62,
|
||||
189.03,
|
||||
280.36,
|
||||
181.41,
|
||||
286.51,
|
||||
177.74,
|
||||
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,
|
||||
409.52,
|
||||
141.14,
|
||||
414.82,
|
||||
139.75,
|
||||
427.72,
|
||||
127.3,
|
||||
439.6,
|
||||
119.74,
|
||||
474.93,
|
||||
107.87,
|
||||
486.51,
|
||||
106.75,
|
||||
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,
|
||||
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,
|
||||
800.24,
|
||||
214.62,
|
||||
810.53,
|
||||
219.73,
|
||||
817.19,
|
||||
226.82,
|
||||
820.77,
|
||||
236.17,
|
||||
827.23,
|
||||
236.16,
|
||||
851.0,
|
||||
248.94,
|
||||
859.88,
|
||||
255.49,
|
||||
865.21,
|
||||
268.53,
|
||||
857.95,
|
||||
280.3,
|
||||
865.48,
|
||||
291.45,
|
||||
866.81,
|
||||
298.66,
|
||||
867.79,
|
||||
306.17,
|
||||
859.87,
|
||||
311.37,
|
||||
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,
|
||||
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,
|
||||
];
|
||||
|
||||
const simplifiedFlatCoordinates = [
|
||||
224.55,
|
||||
250.15,
|
||||
267.76,
|
||||
213.81,
|
||||
296.91,
|
||||
155.64,
|
||||
330.33,
|
||||
137.57,
|
||||
409.52,
|
||||
141.14,
|
||||
439.6,
|
||||
119.74,
|
||||
486.51,
|
||||
106.75,
|
||||
529.57,
|
||||
127.86,
|
||||
539.27,
|
||||
147.24,
|
||||
617.74,
|
||||
159.86,
|
||||
629.55,
|
||||
194.6,
|
||||
671.55,
|
||||
222.55,
|
||||
727.81,
|
||||
213.36,
|
||||
739.94,
|
||||
204.77,
|
||||
769.98,
|
||||
208.42,
|
||||
779.6,
|
||||
216.87,
|
||||
800.24,
|
||||
214.62,
|
||||
820.77,
|
||||
236.17,
|
||||
859.88,
|
||||
255.49,
|
||||
865.21,
|
||||
268.53,
|
||||
857.95,
|
||||
280.3,
|
||||
867.79,
|
||||
306.17,
|
||||
859.87,
|
||||
311.37,
|
||||
854.54,
|
||||
335.4,
|
||||
860.92,
|
||||
343.0,
|
||||
849.84,
|
||||
359.59,
|
||||
854.56,
|
||||
365.53,
|
||||
844.09,
|
||||
371.89,
|
||||
839.57,
|
||||
390.4,
|
||||
848.4,
|
||||
407.55,
|
||||
839.51,
|
||||
432.76,
|
||||
853.97,
|
||||
471.15,
|
||||
866.36,
|
||||
480.77,
|
||||
];
|
||||
|
||||
const simplifiedHighQualityFlatCoordinates = [
|
||||
224.55,
|
||||
250.15,
|
||||
267.76,
|
||||
213.81,
|
||||
296.91,
|
||||
155.64,
|
||||
330.33,
|
||||
137.57,
|
||||
409.52,
|
||||
141.14,
|
||||
439.6,
|
||||
119.74,
|
||||
486.51,
|
||||
106.75,
|
||||
529.57,
|
||||
127.86,
|
||||
539.27,
|
||||
147.24,
|
||||
617.74,
|
||||
159.86,
|
||||
629.55,
|
||||
194.6,
|
||||
671.55,
|
||||
222.55,
|
||||
727.81,
|
||||
213.36,
|
||||
739.94,
|
||||
204.77,
|
||||
769.98,
|
||||
208.42,
|
||||
784.2,
|
||||
218.16,
|
||||
800.24,
|
||||
214.62,
|
||||
820.77,
|
||||
236.17,
|
||||
859.88,
|
||||
255.49,
|
||||
865.21,
|
||||
268.53,
|
||||
857.95,
|
||||
280.3,
|
||||
867.79,
|
||||
306.17,
|
||||
858.29,
|
||||
314.94,
|
||||
854.54,
|
||||
335.4,
|
||||
860.92,
|
||||
343.0,
|
||||
849.84,
|
||||
359.59,
|
||||
854.56,
|
||||
365.53,
|
||||
844.09,
|
||||
371.89,
|
||||
839.57,
|
||||
390.4,
|
||||
848.4,
|
||||
407.55,
|
||||
839.51,
|
||||
432.76,
|
||||
853.97,
|
||||
471.15,
|
||||
866.36,
|
||||
480.77,
|
||||
];
|
||||
|
||||
describe('simplifyLineString', function () {
|
||||
it('works with empty line strings', function () {
|
||||
expect(simplifyLineString([], 0, 0, 2, 1, true)).to.eql([]);
|
||||
expect(simplifyLineString([], 0, 0, 2, 1, false)).to.eql([]);
|
||||
});
|
||||
|
||||
it('works with a line string with a single point', function () {
|
||||
expect(simplifyLineString([1, 2], 0, 2, 2, 1, true)).to.eql([1, 2]);
|
||||
expect(simplifyLineString([1, 2], 0, 2, 2, 1, false)).to.eql([1, 2]);
|
||||
});
|
||||
|
||||
it('returns the expected result with low quality', function () {
|
||||
const result = simplifyLineString(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2,
|
||||
25,
|
||||
false
|
||||
);
|
||||
expect(result.length).to.be(simplifiedFlatCoordinates.length);
|
||||
expect(result).to.eql(simplifiedFlatCoordinates);
|
||||
});
|
||||
|
||||
it('returns the expected result with high quality', function () {
|
||||
const result = simplifyLineString(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2,
|
||||
25,
|
||||
true
|
||||
);
|
||||
expect(result.length).to.be(simplifiedHighQualityFlatCoordinates.length);
|
||||
expect(result).to.eql(simplifiedHighQualityFlatCoordinates);
|
||||
});
|
||||
});
|
||||
|
||||
describe('radialDistance', function () {
|
||||
let dest;
|
||||
beforeEach(function () {
|
||||
dest = [];
|
||||
});
|
||||
|
||||
it('works with empty line strings', function () {
|
||||
expect(radialDistance([], 0, 0, 2, 1, dest, 0)).to.be(0);
|
||||
expect(dest).to.eql([]);
|
||||
});
|
||||
|
||||
it('works with a line string with a single point', function () {
|
||||
expect(radialDistance([1, 2], 0, 2, 2, 1, dest, 0)).to.be(2);
|
||||
expect(dest).to.eql([1, 2]);
|
||||
});
|
||||
|
||||
it('works with a line string with two points', function () {
|
||||
expect(radialDistance([1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4);
|
||||
expect(dest).to.eql([1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
it('works when the points are widely spaced', function () {
|
||||
expect(
|
||||
radialDistance([0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)
|
||||
).to.be(8);
|
||||
expect(dest).to.eql([0, 0, 1, 0, 2, 0, 3, 0]);
|
||||
});
|
||||
|
||||
it('works when the spacing matches the tolerance', function () {
|
||||
expect(
|
||||
radialDistance([0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)
|
||||
).to.be(6);
|
||||
expect(dest).to.eql([0, 0, 2, 0, 3, 0]);
|
||||
});
|
||||
|
||||
it('works when the points are closely spaced', function () {
|
||||
expect(
|
||||
radialDistance([0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)
|
||||
).to.be(6);
|
||||
expect(dest).to.eql([0, 0, 2, 0, 3, 0]);
|
||||
});
|
||||
|
||||
it('works when the line oscillates with widely spaced points', function () {
|
||||
expect(
|
||||
radialDistance(
|
||||
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],
|
||||
0,
|
||||
12,
|
||||
2,
|
||||
1,
|
||||
dest,
|
||||
0
|
||||
)
|
||||
).to.be(12);
|
||||
expect(dest).to.eql([0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]);
|
||||
});
|
||||
|
||||
it('works when the line oscillates with closely spaced points', function () {
|
||||
expect(
|
||||
radialDistance(
|
||||
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],
|
||||
0,
|
||||
12,
|
||||
2,
|
||||
2,
|
||||
dest,
|
||||
0
|
||||
)
|
||||
).to.be(4);
|
||||
expect(dest).to.eql([0, 0, 1, 1]);
|
||||
});
|
||||
|
||||
it('works when the line oscillates within the tolerance', function () {
|
||||
expect(
|
||||
radialDistance(
|
||||
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],
|
||||
0,
|
||||
14,
|
||||
2,
|
||||
2,
|
||||
dest,
|
||||
0
|
||||
)
|
||||
).to.be(2);
|
||||
expect(dest).to.eql([0, 0]);
|
||||
});
|
||||
|
||||
it('works with real data', function () {
|
||||
expect(
|
||||
radialDistance(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2,
|
||||
25,
|
||||
dest,
|
||||
0
|
||||
)
|
||||
).to.be(simplifiedRadiallyFlatCoordinates.length);
|
||||
expect(dest).to.eql(simplifiedRadiallyFlatCoordinates);
|
||||
});
|
||||
});
|
||||
|
||||
describe('douglasPeucker', function () {
|
||||
let dest;
|
||||
beforeEach(function () {
|
||||
dest = [];
|
||||
});
|
||||
|
||||
it('works with empty line strings', function () {
|
||||
expect(douglasPeucker([], 0, 0, 2, 1, dest, 0)).to.be(0);
|
||||
expect(dest).to.eql([]);
|
||||
});
|
||||
|
||||
it('works with a line string with a single point', function () {
|
||||
expect(douglasPeucker([1, 2], 0, 2, 2, 1, dest, 0)).to.be(2);
|
||||
expect(dest).to.eql([1, 2]);
|
||||
});
|
||||
|
||||
it('works with a line string with two points', function () {
|
||||
expect(douglasPeucker([1, 2, 3, 4], 0, 4, 2, 1, dest, 0)).to.be(4);
|
||||
expect(dest).to.eql([1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
it('works when the points are widely spaced', function () {
|
||||
expect(
|
||||
douglasPeucker([0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 0.5, dest, 0)
|
||||
).to.be(4);
|
||||
expect(dest).to.eql([0, 0, 3, 0]);
|
||||
});
|
||||
|
||||
it('works when the spacing matches the tolerance', function () {
|
||||
expect(
|
||||
douglasPeucker([0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1, dest, 0)
|
||||
).to.be(4);
|
||||
expect(dest).to.eql([0, 0, 3, 0]);
|
||||
});
|
||||
|
||||
it('works when the points are closely spaced', function () {
|
||||
expect(
|
||||
douglasPeucker([0, 0, 1, 0, 2, 0, 3, 0], 0, 8, 2, 1.5, dest, 0)
|
||||
).to.be(4);
|
||||
expect(dest).to.eql([0, 0, 3, 0]);
|
||||
});
|
||||
|
||||
it('does not elimnate points outside the tolerance', function () {
|
||||
expect(douglasPeucker([0, 0, 1, 1, 2, 0], 0, 6, 2, 0.5, dest, 0)).to.be(
|
||||
6
|
||||
);
|
||||
expect(dest).to.eql([0, 0, 1, 1, 2, 0]);
|
||||
});
|
||||
|
||||
it('does eliminate points within the tolerance', function () {
|
||||
expect(douglasPeucker([0, 0, 1, 1, 2, 0], 0, 6, 2, 2, dest, 0)).to.be(4);
|
||||
expect(dest).to.eql([0, 0, 2, 0]);
|
||||
});
|
||||
|
||||
it('does not eliminate multiple points outside the tolerance', function () {
|
||||
expect(
|
||||
douglasPeucker([0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 0.5, dest, 0)
|
||||
).to.be(8);
|
||||
expect(dest).to.eql([0, 0, 1, 1, 1, -1, 2, 0]);
|
||||
});
|
||||
|
||||
it('does eliminate multiple points within the tolerance', function () {
|
||||
expect(
|
||||
douglasPeucker([0, 0, 1, 1, 1, -1, 2, 0], 0, 8, 2, 2, dest, 0)
|
||||
).to.be(4);
|
||||
expect(dest).to.eql([0, 0, 2, 0]);
|
||||
});
|
||||
|
||||
it('works when the line oscillates with widely spaced points', function () {
|
||||
expect(
|
||||
douglasPeucker(
|
||||
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],
|
||||
0,
|
||||
12,
|
||||
2,
|
||||
1,
|
||||
dest,
|
||||
0
|
||||
)
|
||||
).to.be(4);
|
||||
expect(dest).to.eql([0, 0, 1, 1]);
|
||||
});
|
||||
|
||||
it('works when the line oscillates with closely spaced points', function () {
|
||||
expect(
|
||||
douglasPeucker(
|
||||
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1],
|
||||
0,
|
||||
12,
|
||||
2,
|
||||
2,
|
||||
dest,
|
||||
0
|
||||
)
|
||||
).to.be(4);
|
||||
expect(dest).to.eql([0, 0, 1, 1]);
|
||||
});
|
||||
|
||||
it('works when the line oscillates within the tolerance', function () {
|
||||
expect(
|
||||
douglasPeucker(
|
||||
[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0],
|
||||
0,
|
||||
14,
|
||||
2,
|
||||
2,
|
||||
dest,
|
||||
0
|
||||
)
|
||||
).to.be(4);
|
||||
expect(dest).to.eql([0, 0, 0, 0]);
|
||||
});
|
||||
|
||||
it('works on small triangles', function () {
|
||||
expect(
|
||||
douglasPeucker([3, 0, 4, 1, 5, 2, 5, 0], 0, 8, 2, 1, dest, 0)
|
||||
).to.be(6);
|
||||
expect(dest).to.eql([3, 0, 5, 2, 5, 0]);
|
||||
});
|
||||
|
||||
it('is the same as high quality simplification', function () {
|
||||
expect(
|
||||
douglasPeucker(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2,
|
||||
25,
|
||||
dest,
|
||||
0
|
||||
)
|
||||
).to.be(simplifiedHighQualityFlatCoordinates.length);
|
||||
expect(dest).to.eql(simplifiedHighQualityFlatCoordinates);
|
||||
});
|
||||
});
|
||||
|
||||
describe('quantize', function () {
|
||||
it('handles empty coordinates', function () {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
expect(quantize([], 0, 0, 2, 2, simplifiedFlatCoordinates, 0)).to.be(0);
|
||||
expect(simplifiedFlatCoordinates).to.be.empty();
|
||||
});
|
||||
|
||||
it('expands points to a zero-length line', function () {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
expect(
|
||||
quantize([0, 0, 0, 0], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)
|
||||
).to.be(4);
|
||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, 0]);
|
||||
});
|
||||
|
||||
it('snaps near-by points to the same value', function () {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
expect(
|
||||
quantize([0.1, 0, 0, 0.1], 0, 4, 2, 2, simplifiedFlatCoordinates, 0)
|
||||
).to.be(4);
|
||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, 0]);
|
||||
});
|
||||
|
||||
it('eliminates duplicate snapped points', function () {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
expect(
|
||||
quantize(
|
||||
[0.1, 0, 2, 0, 2.1, 0, 2, 0.1, 1.9, 0, 2, -0.1],
|
||||
0,
|
||||
12,
|
||||
2,
|
||||
2,
|
||||
simplifiedFlatCoordinates,
|
||||
0
|
||||
)
|
||||
).to.be(4);
|
||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 2, 0]);
|
||||
});
|
||||
|
||||
it('eliminates horizontal colinear points', function () {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
expect(
|
||||
quantize(
|
||||
[0, 0, 2, 0, 4, 0, 6, 0],
|
||||
0,
|
||||
8,
|
||||
2,
|
||||
2,
|
||||
simplifiedFlatCoordinates,
|
||||
0
|
||||
)
|
||||
).to.be(4);
|
||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 6, 0]);
|
||||
});
|
||||
|
||||
it('eliminates vertical colinear points', function () {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
expect(
|
||||
quantize(
|
||||
[0, 0, 0, -2, 0, -4, 0, -6],
|
||||
0,
|
||||
8,
|
||||
2,
|
||||
2,
|
||||
simplifiedFlatCoordinates,
|
||||
0
|
||||
)
|
||||
).to.be(4);
|
||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 0, -6]);
|
||||
});
|
||||
|
||||
it('eliminates diagonal colinear points', function () {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
expect(
|
||||
quantize(
|
||||
[0, 0, 2, -2, 4, -4, 6, -6],
|
||||
0,
|
||||
8,
|
||||
2,
|
||||
2,
|
||||
simplifiedFlatCoordinates,
|
||||
0
|
||||
)
|
||||
).to.be(4);
|
||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 6, -6]);
|
||||
});
|
||||
|
||||
it('handles switchbacks', function () {
|
||||
const simplifiedFlatCoordinates = [];
|
||||
expect(
|
||||
quantize(
|
||||
[0, 0, 2, 0, 0, 0, 4, 0],
|
||||
0,
|
||||
8,
|
||||
2,
|
||||
2,
|
||||
simplifiedFlatCoordinates,
|
||||
0
|
||||
)
|
||||
).to.be(8);
|
||||
expect(simplifiedFlatCoordinates).to.eql([0, 0, 2, 0, 0, 0, 4, 0]);
|
||||
});
|
||||
});
|
||||
});
|
||||
70
test/node/ol/geom/flat/straightchunk.test.js
Normal file
70
test/node/ol/geom/flat/straightchunk.test.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {matchingChunk} from '../../../../../src/ol/geom/flat/straightchunk.js';
|
||||
|
||||
describe('ol/geom/flat/straightchunk.js', function () {
|
||||
describe('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 () {
|
||||
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 () {
|
||||
const got = matchingChunk(0, flatCoords, 0, 6, stride);
|
||||
expect(got).to.eql([0, 6]);
|
||||
});
|
||||
});
|
||||
|
||||
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 () {
|
||||
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 () {
|
||||
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,
|
||||
];
|
||||
const stride = 2;
|
||||
|
||||
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 () {
|
||||
const got = matchingChunk(Math.PI / 4, flatCoords, 0, 18, stride);
|
||||
expect(got).to.eql([10, 18]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
245
test/node/ol/geom/flat/textpath.test.js
Normal file
245
test/node/ol/geom/flat/textpath.test.js
Normal file
@@ -0,0 +1,245 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {drawTextOnPath} from '../../../../../src/ol/geom/flat/textpath.js';
|
||||
import {lineStringLength} from '../../../../../src/ol/geom/flat/length.js';
|
||||
|
||||
describe('ol/geom/flat/drawTextOnPath.js', function () {
|
||||
const horizontal = [0, 0, 100, 0];
|
||||
const vertical = [0, 0, 0, 100];
|
||||
const diagonal = [0, 0, 100, 100];
|
||||
const reverse = [100, 0, 0, 100];
|
||||
const angled = [0, 0, 100, 100, 200, 0];
|
||||
const reverseangled = [151, 17, 163, 22, 159, 30, 150, 30, 143, 24, 151, 17];
|
||||
|
||||
function measureAndCacheTextWidth(font, text, cache) {
|
||||
return 10 * text.length;
|
||||
}
|
||||
|
||||
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,
|
||||
'',
|
||||
{}
|
||||
);
|
||||
expect(instructions).to.eql([[50, 0, 15, 0, 'foo']]);
|
||||
});
|
||||
|
||||
it('left-aligns text on a horizontal line', function () {
|
||||
const instructions = drawTextOnPath(
|
||||
horizontal,
|
||||
0,
|
||||
horizontal.length,
|
||||
2,
|
||||
'foo',
|
||||
0,
|
||||
Infinity,
|
||||
1,
|
||||
measureAndCacheTextWidth,
|
||||
'',
|
||||
{}
|
||||
);
|
||||
expect(instructions).to.eql([[15, 0, 15, 0, 'foo']]);
|
||||
});
|
||||
|
||||
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,
|
||||
'',
|
||||
{}
|
||||
);
|
||||
expect(instructions).to.eql([[85, 0, 15, 0, 'foo']]);
|
||||
});
|
||||
|
||||
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;
|
||||
expect(instructions).to.eql([[0, 50, 15, a, 'foo']]);
|
||||
});
|
||||
|
||||
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);
|
||||
expect(instructions.length).to.be(1);
|
||||
});
|
||||
|
||||
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);
|
||||
expect(instructions.length).to.be(1);
|
||||
});
|
||||
|
||||
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,
|
||||
'',
|
||||
{}
|
||||
);
|
||||
expect(instructions[0]).to.eql([50, 0, 75, 0, 'foo-foo-foo-foo']);
|
||||
expect(instructions.length).to.be(1);
|
||||
});
|
||||
|
||||
it('renders angled text', function () {
|
||||
const length = lineStringLength(angled, 0, angled.length, 2);
|
||||
const startM = length / 2 - 20;
|
||||
const instructions = drawTextOnPath(
|
||||
angled,
|
||||
0,
|
||||
angled.length,
|
||||
2,
|
||||
'fooo',
|
||||
startM,
|
||||
Infinity,
|
||||
1,
|
||||
measureAndCacheTextWidth,
|
||||
'',
|
||||
{}
|
||||
);
|
||||
expect(instructions[0][3]).to.eql((45 * Math.PI) / 180);
|
||||
expect(instructions[0][4]).to.be('fo');
|
||||
expect(instructions[1][3]).to.eql((-45 * Math.PI) / 180);
|
||||
expect(instructions[1][4]).to.be('oo');
|
||||
});
|
||||
|
||||
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,
|
||||
'',
|
||||
{}
|
||||
);
|
||||
expect(instructions).to.be(null);
|
||||
});
|
||||
|
||||
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,
|
||||
'',
|
||||
{}
|
||||
);
|
||||
expect(instructions).to.not.be(undefined);
|
||||
});
|
||||
|
||||
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);
|
||||
expect(instructions.length).to.be(1);
|
||||
});
|
||||
|
||||
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);
|
||||
expect(instructions.length).to.be(1);
|
||||
});
|
||||
});
|
||||
48
test/node/ol/geom/flat/topologyflatgeom.test.js
Normal file
48
test/node/ol/geom/flat/topologyflatgeom.test.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import expect from '../../../expect.js';
|
||||
import {lineStringIsClosed} from '../../../../../src/ol/geom/flat/topology.js';
|
||||
|
||||
describe('ol/geom/flat/topology.js', function () {
|
||||
describe('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
|
||||
);
|
||||
expect(isClosed).to.be(true);
|
||||
});
|
||||
|
||||
it('identifies regular linestrings', function () {
|
||||
const flatCoordinates = [0, 0, 3, 0, 0, 3, 5, 2];
|
||||
const isClosed = lineStringIsClosed(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
2
|
||||
);
|
||||
expect(isClosed).to.be(false);
|
||||
});
|
||||
|
||||
it('identifies degenerate boundaries', function () {
|
||||
let flatCoordinates = [0, 0, 3, 0, 0, 0];
|
||||
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
|
||||
);
|
||||
expect(isClosed).to.be(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
215
test/node/ol/geom/flat/transform.test.js
Normal file
215
test/node/ol/geom/flat/transform.test.js
Normal file
@@ -0,0 +1,215 @@
|
||||
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
|
||||
import expect from '../../../expect.js';
|
||||
import {rotate, translate} from '../../../../../src/ol/geom/flat/transform.js';
|
||||
import {transformGeom2D} from '../../../../../src/ol/geom/SimpleGeometry.js';
|
||||
|
||||
describe('ol/geom/flat/transform.js', function () {
|
||||
describe('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],
|
||||
],
|
||||
],
|
||||
]).transform('EPSG:4326', 'EPSG:3857');
|
||||
const transform = [
|
||||
0.0004088332670837288,
|
||||
0,
|
||||
0,
|
||||
-0.0004088332670837288,
|
||||
4480.991370439071,
|
||||
1529.5752568707105,
|
||||
];
|
||||
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);
|
||||
expect(pixelCoordinates[3]).to.roughlyEqual(158.76358389011807, 1e-9);
|
||||
expect(pixelCoordinates[4]).to.roughlyEqual(802.9014262612932, 1e-9);
|
||||
expect(pixelCoordinates[5]).to.roughlyEqual(154.95335187132082, 1e-9);
|
||||
expect(pixelCoordinates[6]).to.roughlyEqual(799.5382461724039, 1e-9);
|
||||
expect(pixelCoordinates[7]).to.roughlyEqual(148.815592819916, 1e-9);
|
||||
expect(pixelCoordinates[8]).to.roughlyEqual(798.3910020835165, 1e-9);
|
||||
expect(pixelCoordinates[9]).to.roughlyEqual(145.77392230456553, 1e-9);
|
||||
expect(pixelCoordinates[10]).to.roughlyEqual(799.1732925724045, 1e-9);
|
||||
expect(pixelCoordinates[11]).to.roughlyEqual(146.31080369865776, 1e-9);
|
||||
expect(pixelCoordinates[12]).to.roughlyEqual(800.8417299057378, 1e-9);
|
||||
expect(pixelCoordinates[13]).to.roughlyEqual(149.94832216046188, 1e-9);
|
||||
expect(pixelCoordinates[14]).to.roughlyEqual(806.6035275946265, 1e-9);
|
||||
expect(pixelCoordinates[15]).to.roughlyEqual(160.48916296287916, 1e-9);
|
||||
expect(pixelCoordinates[16]).to.roughlyEqual(744.4323460835158, 1e-9);
|
||||
expect(pixelCoordinates[17]).to.roughlyEqual(273.7179168205373, 1e-9);
|
||||
expect(pixelCoordinates[18]).to.roughlyEqual(746.0246888390716, 1e-9);
|
||||
expect(pixelCoordinates[19]).to.roughlyEqual(278.22094795365365, 1e-9);
|
||||
expect(pixelCoordinates[20]).to.roughlyEqual(744.6365089279602, 1e-9);
|
||||
expect(pixelCoordinates[21]).to.roughlyEqual(278.40513424671826, 1e-9);
|
||||
expect(pixelCoordinates[22]).to.roughlyEqual(742.8955268835157, 1e-9);
|
||||
expect(pixelCoordinates[23]).to.roughlyEqual(270.83899948444764, 1e-9);
|
||||
expect(pixelCoordinates[24]).to.roughlyEqual(740.7291979946272, 1e-9);
|
||||
expect(pixelCoordinates[25]).to.roughlyEqual(268.76099731369345, 1e-9);
|
||||
expect(pixelCoordinates[26]).to.roughlyEqual(743.2166987946266, 1e-9);
|
||||
expect(pixelCoordinates[27]).to.roughlyEqual(268.23842607400616, 1e-9);
|
||||
expect(pixelCoordinates[28]).to.roughlyEqual(744.4323460835158, 1e-9);
|
||||
expect(pixelCoordinates[29]).to.roughlyEqual(273.7179168205373, 1e-9);
|
||||
});
|
||||
});
|
||||
|
||||
describe('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],
|
||||
],
|
||||
],
|
||||
]);
|
||||
const flatCoordinates = multiPolygon.getFlatCoordinates();
|
||||
const deltaX = 1;
|
||||
const deltaY = 2;
|
||||
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,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('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],
|
||||
],
|
||||
],
|
||||
]);
|
||||
const flatCoordinates = multiPolygon.getFlatCoordinates();
|
||||
const angle = Math.PI / 2;
|
||||
const anchor = [0, 1];
|
||||
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);
|
||||
expect(flatCoordinates[3]).to.roughlyEqual(0, 1e-9);
|
||||
expect(flatCoordinates[4]).to.roughlyEqual(1, 1e-9);
|
||||
expect(flatCoordinates[5]).to.roughlyEqual(2, 1e-9);
|
||||
expect(flatCoordinates[6]).to.roughlyEqual(Math.cos(angle), 1e-9);
|
||||
expect(flatCoordinates[7]).to.roughlyEqual(2, 1e-9);
|
||||
expect(flatCoordinates[8]).to.roughlyEqual(2, 1e-9);
|
||||
expect(flatCoordinates[9]).to.roughlyEqual(1, 1e-9);
|
||||
expect(flatCoordinates[10]).to.roughlyEqual(2, 1e-9);
|
||||
expect(flatCoordinates[11]).to.roughlyEqual(2, 1e-9);
|
||||
expect(flatCoordinates[12]).to.roughlyEqual(1, 1e-9);
|
||||
expect(flatCoordinates[13]).to.roughlyEqual(1, 1e-9);
|
||||
expect(flatCoordinates[14]).to.roughlyEqual(2, 1e-9);
|
||||
expect(flatCoordinates[15]).to.roughlyEqual(-1, 1e-9);
|
||||
expect(flatCoordinates[16]).to.roughlyEqual(3, 1e-9);
|
||||
expect(flatCoordinates[17]).to.roughlyEqual(3, 1e-9);
|
||||
expect(flatCoordinates[18]).to.roughlyEqual(-2, 1e-9);
|
||||
expect(flatCoordinates[19]).to.roughlyEqual(3, 1e-9);
|
||||
expect(flatCoordinates[20]).to.roughlyEqual(3, 1e-9);
|
||||
expect(flatCoordinates[21]).to.roughlyEqual(-2, 1e-9);
|
||||
expect(flatCoordinates[22]).to.roughlyEqual(4, 1e-9);
|
||||
expect(flatCoordinates[23]).to.roughlyEqual(3, 1e-9);
|
||||
expect(flatCoordinates[24]).to.roughlyEqual(-1, 1e-9);
|
||||
expect(flatCoordinates[25]).to.roughlyEqual(4, 1e-9);
|
||||
expect(flatCoordinates[26]).to.roughlyEqual(3, 1e-9);
|
||||
expect(flatCoordinates[27]).to.roughlyEqual(-1, 1e-9);
|
||||
expect(flatCoordinates[28]).to.roughlyEqual(3, 1e-9);
|
||||
expect(flatCoordinates[29]).to.roughlyEqual(3, 1e-9);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user