Merge lp:~costales/unav/0.63-round-dist into lp:unav

Proposed by costales
Status: Merged
Merged at revision: 122
Proposed branch: lp:~costales/unav/0.63-round-dist
Merge into: lp:unav
Diff against target: 111 lines (+59/-19)
2 files modified
nav/class/Maths.js (+58/-18)
po/unav.pot (+1/-1)
To merge this branch: bzr merge lp:~costales/unav/0.63-round-dist
Reviewer Review Type Date Requested Status
costales Approve
Review via email: mp+305187@code.launchpad.net

Description of the change

Better round distances

<17 = Same
17-70 = Round 5
71-150 = Round 10
151-350 = Round 20
351-500 = Round 50
501-1000 = Round 100

To post a comment you must log in.
lp:~costales/unav/0.63-round-dist updated
121. By costales

i18n

122. By costales

Round better

123. By costales

It wasn't perfect yet

Revision history for this message
costales (costales) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nav/class/Maths.js'
2--- nav/class/Maths.js 2016-08-22 17:27:55 +0000
3+++ nav/class/Maths.js 2016-09-09 08:19:06 +0000
4@@ -83,36 +83,76 @@
5
6 if (unit2convert == this.KM) {
7 if (m > 999) {
8- value = m * this.M2KM; // return km
9- unit = 'km';
10+ value = parseInt(m * this.M2KM); // km
11+ unit = 'km';
12+ }
13+ else if (m > 949) { // Avoid round of 1000 m
14+ value = 1;
15+ unit = 'km';
16+ }
17+ else if (m > 500) {
18+ value = Math.round(m / 100) * 100;
19+ unit = 'm';
20+ }
21+ else if (m > 350) {
22+ value = Math.round(m / 50) * 50;
23+ unit = 'm';
24+ }
25+ else if (m > 150) {
26+ value = Math.round(m / 20) * 20;
27+ unit = 'm';
28+ }
29+ else if (m > 70) {
30+ value = Math.round(m / 10) * 10;
31+ unit = 'm';
32+ }
33+ else if (m > 17) {
34+ value = Math.round(m / 5) * 5;
35+ unit = 'm';
36 }
37 else {
38- value = Math.round(m/10)*10; // return meters rounded in 10
39- unit = 'm';
40- }
41-
42- if (!value) {
43- value = m; // 0 after round? return meters
44+ value = parseInt(m);
45 unit = 'm';
46 }
47 }
48 else {
49- if (value > 999) {
50- value = m * this.M2MI; // return milles
51- unit = 'mi';
52+ var yards = m * this.M2YD;
53+
54+ if (yards > 1759) { // Avoid 0 mi
55+ value = parseInt(m * this.M2MI); // milles
56+ unit = 'mi';
57+ }
58+ else if (yards > 949) { // Avoid round 1000 yd
59+ value = 1;
60+ unit = 'mi';
61+ }
62+ else if (yards > 500) {
63+ value = Math.round(yards / 100) * 100;
64+ unit = 'yd';
65+ }
66+ else if (yards > 350) {
67+ value = Math.round(yards / 50) * 50;
68+ unit = 'yd';
69+ }
70+ else if (yards > 150) {
71+ value = Math.round(yards / 20) * 20;
72+ unit = 'yd';
73+ }
74+ else if (yards > 70) {
75+ value = Math.round(yards / 10) * 10;
76+ unit = 'yd';
77+ }
78+ else if (yards > 17) {
79+ value = Math.round(yards / 5) * 5;
80+ unit = 'yd';
81 }
82 else {
83- value = Math.round((m*this.M2YD)/10)*10; // return yards rounded in 10
84- unit = 'yd';
85- }
86-
87- if (!value) {
88- value = m * this.M2YD; // 0 after round? return yards
89+ value = parseInt(yards);
90 unit = 'yd';
91 }
92 }
93
94- return String(parseInt(value) + ' ' + unit);
95+ return (String(value) + ' ' + unit);
96 }
97
98 Maths.prototype.decode = function(encoded, lat1st) {
99
100=== modified file 'po/unav.pot'
101--- po/unav.pot 2016-09-06 20:16:18 +0000
102+++ po/unav.pot 2016-09-09 08:19:06 +0000
103@@ -8,7 +8,7 @@
104 msgstr ""
105 "Project-Id-Version: unav\n"
106 "Report-Msgid-Bugs-To: \n"
107-"POT-Creation-Date: 2016-09-06 22:16+0200\n"
108+"POT-Creation-Date: 2016-09-08 12:01+0200\n"
109 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
110 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
111 "Language-Team: LANGUAGE <LL@li.org>\n"

Subscribers

People subscribed via source and target branches