Mercurial > gemma
annotate client/tests/unit/geo/geo.spec.js @ 3313:b01c2f474770
client: identify: changed order of state mutations
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Fri, 17 May 2019 14:07:16 +0200 |
parents | 0c5cbbafbd94 |
children |
rev | line source |
---|---|
1364
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
1 /* This is Free Software under GNU Affero General Public License v >= 3.0 |
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
2 * without warranty, see README.md and license for details. |
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
3 * |
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
4 * SPDX-License-Identifier: AGPL-3.0-or-later |
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
5 * License-Filename: LICENSES/AGPL-3.0.txt |
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
6 * |
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
7 * Copyright (C) 2018 by via donau |
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
8 * – Österreichische Wasserstraßen-Gesellschaft mbH |
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
9 * Software engineering by Intevation GmbH |
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
10 * |
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
11 * Author(s): |
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
12 * Thomas Junk <thomas.junk@intevation.de> |
0c5cbbafbd94
add headers license for some client files
Fadi Abbud <fadi.abbud@intevation.de>
parents:
696
diff
changeset
|
13 */ |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
14 import { prepareProfile } from "../../../src/application/lib/geo"; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
15 |
696
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
16 const geoJSON = JSON.parse(`{ |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
17 "type": "Feature", |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
18 "geometry": { |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
19 "type": "MultiLineString", |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
20 "coordinates": [ |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
21 [ |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
22 [17.216391563415527, 48.0245195664277, 123], |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
23 [17.216777801513672, 48.024720482272315, 124] |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
24 ], |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
25 [ |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
26 [17.218494415283203, 48.02540933065123, 125], |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
27 [17.219438552856445, 48.02586855778941, 126], |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
28 [17.220726013183594, 48.02647128719908, 127], |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
29 [17.221627235412598, 48.026987906797494, 128], |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
30 [17.222957611083984, 48.02759062311748, 129], |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
31 [17.223901748657227, 48.0280785311666, 130], |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
32 [17.224159240722656, 48.02819333238926, 131] |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
33 ], |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
34 [ |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
35 [17.225961685180664, 48.02891083423718, 132], |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
36 [17.227892875671383, 48.02997271864036, 133] |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
37 ] |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
38 ] |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
39 }, |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
40 "properties": {} |
1db1ae344087
refac: test adjusted. testdata as JSON string
Thomas Junk <thomas.junk@intevation.de>
parents:
692
diff
changeset
|
41 }`); |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
42 |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
43 test("prepare diagram", () => { |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
44 const coordinates = geoJSON.geometry.coordinates; |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
45 const firstSegment = coordinates[0]; |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
46 const lastSegment = coordinates[coordinates.length - 1]; |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
47 const startPoint = firstSegment[0]; |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
48 const endPoint = lastSegment[lastSegment.length - 1]; |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
49 const result = prepareProfile({ geoJSON, startPoint, endPoint }); |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
50 const alts = result.points.reduce((o, n) => { |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
51 let y = n.map(e => { |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
52 return e.y; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
53 }); |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
54 o = o.concat(y); |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
55 return o; |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
56 }, []); |
677
3605af94d1ee
fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents:
666
diff
changeset
|
57 const growing = values => { |
3605af94d1ee
fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents:
666
diff
changeset
|
58 let first = values[0].x; |
3605af94d1ee
fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents:
666
diff
changeset
|
59 for (let v of values) { |
3605af94d1ee
fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents:
666
diff
changeset
|
60 if (first > v.x) return false; |
3605af94d1ee
fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents:
666
diff
changeset
|
61 } |
3605af94d1ee
fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents:
666
diff
changeset
|
62 return true; |
3605af94d1ee
fix: prepare profile calculation algorithm fixed
Thomas Junk <thomas.junk@intevation.de>
parents:
666
diff
changeset
|
63 }; |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
64 const minAlt = Math.min(...alts); |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
65 const maxAlt = Math.max(...alts); |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
66 expect(result.minAlt).toBe(minAlt); |
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
67 expect(result.maxAlt).toBe(maxAlt); |
692
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
68 expect(growing(result.points[0])).toBe(true); |
87ea9d267c2b
refac: transformation formula for diagram adjusted
Thomas Junk <thomas.junk@intevation.de>
parents:
677
diff
changeset
|
69 expect(result.lengthPolyLine == 1051.5361933142963).toBe(true); |
666
4c36b0e39d78
feat: prepareProfile converts geoJSON to diagram data.
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
70 }); |