mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
Merge PR #1388 contribution for review
This commit is contained in:
commit
1031569f47
3 files changed
+22
-3
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
- Show a drawn line of 999.5 m or more as 1.0 km. The draw hint kept metres
|
||||||
|
below 1000, then rounded 999.6 m up to "1000 m"
|
||||||
|
(Rudy Celekli, @rudycelekli, #1388).
|
||||||
@@ -208,9 +208,10 @@ export function formatMeasure(session) {
|
|||||||
if (!session) return '';
|
if (!session) return '';
|
||||||
if (session.shape === 'line') {
|
if (session.shape === 'line') {
|
||||||
const m = pathLengthM(session.vertices);
|
const m = pathLengthM(session.vertices);
|
||||||
return m >= 1000
|
// Round before the kilometre cut. 999.6 m was printed as "1000 m".
|
||||||
? `${(m / 1000).toFixed(m >= 10000 ? 0 : 1)} km`
|
const whole = Math.round(m);
|
||||||
: `${Math.round(m)} m`;
|
if (whole < 1000) return `${whole} m`;
|
||||||
|
return `${(m / 1000).toFixed(m >= 10000 ? 0 : 1)} km`;
|
||||||
}
|
}
|
||||||
if (session.shape === 'area') {
|
if (session.shape === 'area') {
|
||||||
const m2 = ringAreaM2(session.vertices);
|
const m2 = ringAreaM2(session.vertices);
|
||||||
|
|||||||
@@ -330,3 +330,18 @@ test('longitude unwrapping is continuous and re-wraps to one canonical range', (
|
|||||||
assert.equal(wrapLongitude(180), -180);
|
assert.equal(wrapLongitude(180), -180);
|
||||||
assert.equal(unwrapLongitudes([]).length, 0);
|
assert.equal(unwrapLongitudes([]).length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a line that rounds up to a kilometre reads 1.0 km, not 1000 m', () => {
|
||||||
|
const metresPerDegree = (6371.0088 * 1000 * Math.PI) / 180;
|
||||||
|
const lat = 999.6 / metresPerDegree;
|
||||||
|
const line = createDrawSession('line');
|
||||||
|
addVertex(line, { lon: 0, lat: 0 });
|
||||||
|
addVertex(line, { lon: 0, lat });
|
||||||
|
const metres = pathLengthM(line.vertices);
|
||||||
|
assert.ok(
|
||||||
|
metres >= 999.5 && metres < 1000,
|
||||||
|
`length should round to 1000 m, got ${metres}`,
|
||||||
|
);
|
||||||
|
assert.equal(formatMeasure(line), '1.0 km');
|
||||||
|
assert.match(drawHint(line), /^1\.0 km · /);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user