changeset 4640:fb09a43b062e

Decouple the tracing of the iso areas from the octree data structure.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 11 Oct 2019 20:09:37 +0200
parents 4380f5483c03
children 5ef04ae34872 486495590483
files pkg/controllers/diff.go pkg/imports/isr.go pkg/imports/sr.go pkg/octree/areas.go
diffstat 4 files changed, 10 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/diff.go	Fri Oct 11 20:00:06 2019 +0200
+++ b/pkg/controllers/diff.go	Fri Oct 11 20:09:37 2019 +0200
@@ -296,7 +296,7 @@
 
 	heights = common.DedupFloat64s(heights)
 
-	areas := tree.TraceAreas(heights, isoCellSize)
+	areas := octree.TraceAreas(heights, isoCellSize, tree.Min, tree.Max, tree.Value)
 
 	var size int
 
--- a/pkg/imports/isr.go	Fri Oct 11 20:00:06 2019 +0200
+++ b/pkg/imports/isr.go	Fri Oct 11 20:09:37 2019 +0200
@@ -184,7 +184,7 @@
 		}
 
 		// Calculate and store the iso areas.
-		areas := tree.TraceAreas(hs, isoCellSize)
+		areas := octree.TraceAreas(hs, isoCellSize, tree.Min, tree.Max, tree.Value)
 		for i, a := range areas {
 			if len(a) == 0 {
 				continue
--- a/pkg/imports/sr.go	Fri Oct 11 20:00:06 2019 +0200
+++ b/pkg/imports/sr.go	Fri Oct 11 20:09:37 2019 +0200
@@ -881,7 +881,7 @@
 			time.Since(total))
 	}()
 
-	areas := tree.TraceAreas(heights, isoCellSize)
+	areas := octree.TraceAreas(heights, isoCellSize, tree.Min, tree.Max, tree.Value)
 
 	return storeAreas(
 		ctx, tx, feedback,
--- a/pkg/octree/areas.go	Fri Oct 11 20:00:06 2019 +0200
+++ b/pkg/octree/areas.go	Fri Oct 11 20:09:37 2019 +0200
@@ -26,11 +26,12 @@
 	"gemma.intevation.de/gemma/pkg/wkb"
 )
 
-func (tree *Tree) TraceAreas(
+func TraceAreas(
 	heights []float64,
 	cellSize float64,
+	min, max Vertex,
+	eval func(float64, float64) (float64, bool),
 ) []wkb.MultiPolygonGeom {
-	min, max := tree.Min, tree.Max
 
 	width := max.X - min.X
 	height := max.Y - min.Y
@@ -73,19 +74,19 @@
 				var n int
 				var sum float64
 
-				if v, ok := tree.Value(px-quat, y1); ok {
+				if v, ok := eval(px-quat, y1); ok {
 					sum = v
 					n = 1
 				}
-				if v, ok := tree.Value(px-quat, y2); ok {
+				if v, ok := eval(px-quat, y2); ok {
 					sum += v
 					n++
 				}
-				if v, ok := tree.Value(px+quat, y1); ok {
+				if v, ok := eval(px+quat, y1); ok {
 					sum += v
 					n++
 				}
-				if v, ok := tree.Value(px+quat, y2); ok {
+				if v, ok := eval(px+quat, y2); ok {
 					sum += v
 					n++
 				}