Skip to content

Commit

Permalink
Normalize only once
Browse files Browse the repository at this point in the history
  • Loading branch information
1chandu committed Jun 10, 2019
1 parent 324eb50 commit 0ac90a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
12 changes: 6 additions & 6 deletions modules/geo-layers/src/h3-layers/h3-hexagon-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {ColumnLayer, PolygonLayer} from '@deck.gl/layers';
const UPDATE_THRESHOLD_KM = 10;

// normalize longitudes w.r.t center `refLng`, when not provided first vertex
export function normalizeLongitudes(vertices, refLng = null) {
refLng = refLng || vertices[0][0];
export function normalizeLongitudes(vertices, refLng) {
refLng = refLng === undefined ? vertices[0][0] : refLng;
for (const pt of vertices) {
const deltaLng = pt[0] - refLng;
if (deltaLng > 180) {
Expand Down Expand Up @@ -57,13 +57,13 @@ function h3ToPolygon(hexId, coverage = 1) {
const vertices = h3ToGeoBoundary(hexId, true);

if (coverage !== 1) {
// updates array object elements of vertices array.
// scale and normalize vertices w.r.t to center
scalePolygon(hexId, vertices, coverage);
} else {
// normalize w.r.t to start vertex
normalizeLongitudes(vertices);
}

// normalize with respect start vertex
normalizeLongitudes(vertices);

return vertices;
}

Expand Down
16 changes: 3 additions & 13 deletions test/modules/geo-layers/h3-layers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,44 +173,34 @@ test('H3HexagonLayer#normalizeLongitudes', t => {
const TEST_CASES = [
{
vertices: [[-180, 30], [90, 76], [180, -90], [-110, -21]],
expected: [[-180, 30], [-270, 76], [-180, -90], [-110, -21]],
info: 'Vertices should get normalized with first vertex longitude',
refLng: null
expected: [[-180, 30], [-270, 76], [-180, -90], [-110, -21]]
},
{
vertices: [[-180, 30], [90, 76], [180, -90], [-110, -21]],
expected: [[180, 30], [90, 76], [180, -90], [250, -21]],
refLng: 180,
info: 'Vertices should get normalized with reference longitude'
refLng: 180
},
{
hexId: '88283082e1fffff',
info: 'Vertices should get normalized with first vertex longitude',
refLng: null
hexId: '88283082e1fffff'
},
{
hexId: '88283082e1fffff',
info: 'Vertices should get normalized for longitude 1',
refLng: 1
},
{
hexId: '88283082e1fffff',
info: 'Vertices should get normalized for longitude 98',
refLng: 98
},
{
hexId: '88283082e1fffff',
info: 'Vertices should get normalized for longitude 170',
refLng: 170
},
{
hexId: '88283082e1fffff',
info: 'Vertices should get normalized with first vertex longitude',
refLng: -70
},
{
hexId: '88283082e1fffff',
info: 'Vertices should get normalized with first vertex longitude',
refLng: -150
}
];
Expand Down

0 comments on commit 0ac90a0

Please sign in to comment.