changeset 679:899116318d58 octree

Merged default into octree branch.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 19 Sep 2018 17:35:00 +0200
parents 7bb961d750b6 (current diff) 3605af94d1ee (diff)
children c79c7be29a7a
files
diffstat 3 files changed, 30 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/application/lib/geo.js	Wed Sep 19 17:34:19 2018 +0200
+++ b/client/src/application/lib/geo.js	Wed Sep 19 17:35:00 2018 +0200
@@ -61,6 +61,11 @@
  * c) calculating the total length of the given profile
  * d) transposes the datapoints given to the first point of the first section
  *
+ * The calculation of total equals the sum of partial distances between points
+ * The x-value of a point is determined according to its reference point
+ * in case of the first segment, it is the first element of the line string
+ * in case of consecutive segments it is the last point of the previous segment
+ *
  * @param {object} feature
  */
 const transform = feature => {
@@ -73,8 +78,9 @@
   for (let section of sections) {
     let sectionCoordinates = [];
     let previousPoint = generatePoint(section[0]);
+    let currentPoint = null;
     for (let coords of section) {
-      const currentPoint = generatePoint(coords);
+      currentPoint = generatePoint(coords);
       let x = distanceBetween(firstPoint, currentPoint);
       let y = coords[2];
       sectionCoordinates.push({
@@ -87,6 +93,7 @@
       if (y > maxAlt) maxAlt = y;
     }
     coordinates.push(sectionCoordinates);
+    firstPoint = currentPoint;
   }
   return { coordinates, totalLength, minAlt, maxAlt };
 };
--- a/client/tests/unit/geo/geo.spec.js	Wed Sep 19 17:34:19 2018 +0200
+++ b/client/tests/unit/geo/geo.spec.js	Wed Sep 19 17:35:00 2018 +0200
@@ -330,9 +330,20 @@
     o = o.concat(y);
     return o;
   }, []);
+  const growing = values => {
+    let first = values[0].x;
+    for (let v of values) {
+      if (first > v.x) return false;
+    }
+    return true;
+  };
   const minAlt = Math.min(...alts);
   const maxAlt = Math.max(...alts);
   expect(result.points.length).toBe(3);
+  expect(growing(result.points[0])).toBe(true);
+  expect(growing(result.points[1])).toBe(true);
+  expect(growing([...result.points[0], ...result.points[1]])).toBe(true);
+  expect(growing([...result.points[1], ...result.points[2]])).toBe(false); // because of corrupt testdata
   expect(result.totalLength).toBe(160.06814078495722);
   expect(result.minAlt).toBe(minAlt);
   expect(result.maxAlt).toBe(maxAlt);
--- a/pkg/models/cross.go	Wed Sep 19 17:34:19 2018 +0200
+++ b/pkg/models/cross.go	Wed Sep 19 17:35:00 2018 +0200
@@ -260,15 +260,16 @@
 	return math.Sqrt(dLat*dLat+x*x) * EarthRadius
 }
 
-func (cz GeoJSONCoordinateZ) quant() GeoJSONCoordinateZ {
-	const (
-		xyScale = 1e6
-		zScale  = 1e5
-	)
-	return GeoJSONCoordinateZ{
-		Lon: math.Round(cz.Lon*xyScale) / xyScale,
-		Lat: math.Round(cz.Lat*xyScale) / xyScale,
-		Z:   math.Round(cz.Z*zScale) / zScale,
+type point struct {
+	x float64
+	y float64
+}
+
+func (cz GeoJSONCoordinateZ) quant() point {
+	const xyScale = 1e6
+	return point{
+		math.Round(cz.Lon*xyScale) / xyScale,
+		math.Round(cz.Lat*xyScale) / xyScale,
 	}
 }
 
@@ -292,7 +293,7 @@
 		order  int
 	}
 
-	heads := make(map[GeoJSONCoordinateZ]*value)
+	heads := make(map[point]*value)
 
 	for i, coords := range ml {
 		key := coords[len(coords)-1].quant()