Skip to content

Commit 66604e5

Browse files
committed
Add/update tests
1 parent 43aba1d commit 66604e5

2 files changed

Lines changed: 72 additions & 14 deletions

File tree

test/jasmine/tests/geo_test.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,7 +2661,7 @@ describe('Test geo zoom/pan/drag interactions:', function () {
26612661

26622662
newPlot(fig)
26632663
.then(function () {
2664-
_assert('base', [[undefined, undefined], undefined], [[0.252, -19.8], 160], undefined);
2664+
_assert('base', [[undefined, undefined], undefined], [[-76.014, -19.8], 160], undefined);
26652665
return drag({
26662666
path: [
26672667
[250, 250],
@@ -2673,8 +2673,8 @@ describe('Test geo zoom/pan/drag interactions:', function () {
26732673
.then(function () {
26742674
_assert(
26752675
'after east-west drag',
2676-
[[-20.32, 21.226], 1],
2677-
[[20.32, -21.226], 160],
2676+
[[55.99, 21.103], 1],
2677+
[[-55.99, -21.103], 160],
26782678
[
26792679
'geo.projection.rotation.lon',
26802680
'geo.projection.rotation.lat',
@@ -2687,17 +2687,17 @@ describe('Test geo zoom/pan/drag interactions:', function () {
26872687
.then(function () {
26882688
_assert(
26892689
'after scroll',
2690-
[[-17.5597, 18.862], 1.1488],
2691-
[[17.5597, -18.862], 183.818],
2690+
[[58.694, 18.759], 1.1488],
2691+
[[-58.694, -18.759], 183.818],
26922692
['geo.projection.rotation.lon', 'geo.projection.rotation.lat', 'geo.projection.scale']
26932693
);
26942694
return Plotly.relayout(gd, 'geo.showocean', false);
26952695
})
26962696
.then(function () {
26972697
_assert(
26982698
'after some relayout call that causes a replot',
2699-
[[-17.5597, 18.862], 1.1488],
2700-
[[17.5597, -18.862], 183.818],
2699+
[[58.694, 18.759], 1.1488],
2700+
[[-58.694, -18.759], 183.818],
27012701
['geo.showocean']
27022702
);
27032703
return dblClick([350, 250]);
@@ -2707,7 +2707,7 @@ describe('Test geo zoom/pan/drag interactions:', function () {
27072707
_assert(
27082708
'after double click',
27092709
[[undefined, undefined], undefined],
2710-
[[0.252, -19.8], 160],
2710+
[[-76.014, -19.8], 160],
27112711
'dblclick'
27122712
);
27132713
})
@@ -3162,11 +3162,6 @@ describe('Test geo interactions update marker angles:', function () {
31623162
expect(newPath).toEqual(
31633163
'M0,0L18.27769005891461,8.119485581627321L19.559475756661865,-4.174554841483899Z'
31643164
);
3165-
3166-
expect(newPath).not.toEqual(initialPath);
3167-
expect(newPath).toEqual(
3168-
'M0,0L18.27769005891461,8.119485581627321L19.559475756661865,-4.174554841483899Z'
3169-
);
31703165
expect(initialPath).toEqual(
31713166
'M0,0L-1.5094067529528923,19.942960945008643L10.501042615957648,17.021401351764233Z'
31723167
);

test/jasmine/tests/lib_geo_location_utils_test.js

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { getFitboundsLonRange, unwrapLonRange, doesCrossAntiMeridian } = require('../../../src/lib/geo_location_utils');
1+
const { computeBbox, getFitboundsLonRange, unwrapLonRange, doesCrossAntiMeridian } = require('../../../src/lib/geo_location_utils');
22

33
describe('Test geo_location_utils.getFitboundsLonRange', () => {
44
it('returns the compact crossing range when point data straddles the antimeridian', () => {
@@ -38,6 +38,69 @@ describe('Test geo_location_utils.unwrapLonRange', () => {
3838
});
3939
});
4040

41+
describe('Test geo_location_utils.computeBbox', () => {
42+
const franceCCW = { type: 'Polygon', coordinates: [[[-5, 41], [10, 41], [10, 51], [-5, 51], [-5, 41]]] };
43+
const franceCW = { type: 'Polygon', coordinates: [[[-5, 41], [-5, 51], [10, 51], [10, 41], [-5, 41]]] };
44+
// Fiji-ish narrow band crossing the antimeridian.
45+
const fiji = { type: 'Polygon', coordinates: [[[176, -19], [180, -19], [-178, -19], [-178, -16], [180, -16], [176, -16], [176, -19]]] };
46+
// Russia-ish MultiPolygon with parts on both sides of ±180.
47+
const russia = {
48+
type: 'MultiPolygon',
49+
coordinates: [
50+
[[[30, 55], [170, 55], [170, 75], [30, 75], [30, 55]]],
51+
[[[-180, 65], [-170, 65], [-170, 72], [-180, 72], [-180, 65]]]
52+
]
53+
};
54+
55+
it('returns a degenerate bbox for a single Point', () => {
56+
expect(computeBbox({ type: 'Point', coordinates: [10, 45] })).toEqual([10, 45, 10, 45]);
57+
});
58+
59+
it('returns a normal bbox for a non-antimeridian polygon', () => {
60+
expect(computeBbox(franceCCW)).toEqual([-5, 41, 10, 51]);
61+
});
62+
63+
it('is winding-agnostic (CCW and CW polygons yield the same bbox)', () => {
64+
expect(computeBbox(franceCW)).toEqual(computeBbox(franceCCW));
65+
});
66+
67+
it('unwraps east past 180° for a polygon that crosses the antimeridian', () => {
68+
expect(computeBbox(fiji)).toEqual([176, -19, 182, -16]);
69+
});
70+
71+
it('unwraps east past 180° for a MultiPolygon that crosses the antimeridian', () => {
72+
expect(computeBbox(russia)).toEqual([30, 55, 190, 75]);
73+
});
74+
75+
it('handles a FeatureCollection mixing antimeridian and non-antimeridian features', () => {
76+
const fc = {
77+
type: 'FeatureCollection',
78+
features: [
79+
{ type: 'Feature', geometry: russia, properties: {} },
80+
{ type: 'Feature', geometry: franceCCW, properties: {} }
81+
]
82+
};
83+
expect(computeBbox(fc)).toEqual([-5, 41, 190, 75]);
84+
});
85+
86+
it('unwraps identically whether the input is a raw Geometry or wrapped in a Feature', () => {
87+
const raw = computeBbox(russia);
88+
const wrapped = computeBbox({ type: 'Feature', geometry: russia, properties: {} });
89+
expect(wrapped).toEqual(raw);
90+
});
91+
92+
it('returns null for inputs with no extractable coordinates', () => {
93+
expect(computeBbox({ type: 'Sphere' })).toBe(null);
94+
expect(computeBbox({ type: 'FeatureCollection', features: [] })).toBe(null);
95+
});
96+
97+
it('returns null for nullish or malformed inputs instead of throwing', () => {
98+
expect(computeBbox(null)).toBe(null);
99+
expect(computeBbox(undefined)).toBe(null);
100+
expect(computeBbox({})).toBe(null);
101+
});
102+
});
103+
41104
describe('Test geo_location_utils.doesCrossAntiMeridian', () => {
42105
it('returns the index of the first positive-to-negative longitude transition', () => {
43106
expect(doesCrossAntiMeridian([[170, 0], [179, 0], [-179, 0], [-170, 0]])).toBe(1);

0 commit comments

Comments
 (0)