changeset 5412:34bc6041e61e marking-single-beam

Added a type for class breaks.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 07 Jul 2021 10:58:14 +0200
parents 9822a840d668
children 99f32f0dc70c
files pkg/controllers/diff.go pkg/imports/isr.go pkg/imports/sr.go pkg/mesh/classbreaks.go pkg/mesh/raster.go
diffstat 5 files changed, 24 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/diff.go	Wed Jul 07 09:43:41 2021 +0200
+++ b/pkg/controllers/diff.go	Wed Jul 07 10:58:14 2021 +0200
@@ -251,7 +251,7 @@
 
 	log.Printf("info: z range: %.3f - %.3f\n", zMin, zMax)
 
-	var heights []float64
+	var heights mesh.ClassBreaks
 
 	heights, err = mesh.LoadClassBreaks(
 		ctx, tx,
@@ -261,7 +261,7 @@
 		err = nil
 		heights = mesh.SampleDiffHeights(zMin, zMax, contourStep)
 	} else {
-		heights = mesh.ExtrapolateClassBreaks(heights, zMin, zMax)
+		heights = heights.ExtrapolateClassBreaks(zMin, zMax)
 	}
 
 	heights = common.DedupFloat64s(heights)
--- a/pkg/imports/isr.go	Wed Jul 07 09:43:41 2021 +0200
+++ b/pkg/imports/isr.go	Wed Jul 07 10:58:14 2021 +0200
@@ -157,7 +157,7 @@
 func (isr *IsoRefresh) processBottleneck(
 	ctx context.Context,
 	conn *sql.Conn,
-	heights []float64,
+	heights mesh.ClassBreaks,
 	bn *bottleneckSoundingResults,
 ) error {
 	// Do one transaction per bottleneck.
@@ -179,7 +179,7 @@
 		if err != nil {
 			return err
 		}
-		hs := mesh.ExtrapolateClassBreaks(heights, tree.Min().Z, tree.Max().Z)
+		hs := heights.ExtrapolateClassBreaks(tree.Min().Z, tree.Max().Z)
 		hs = common.DedupFloat64s(hs)
 
 		// Delete the old iso areas.
--- a/pkg/imports/sr.go	Wed Jul 07 09:43:41 2021 +0200
+++ b/pkg/imports/sr.go	Wed Jul 07 10:58:14 2021 +0200
@@ -923,7 +923,7 @@
 			heights = append(heights, h)
 		}
 	} else {
-		heights = mesh.ExtrapolateClassBreaks(heights, minZ, maxZ)
+		heights = heights.ExtrapolateClassBreaks(minZ, maxZ)
 	}
 
 	/*
@@ -933,7 +933,7 @@
 		log.Printf("%.2f - %.2f\n", tree.Min.Z, tree.Max.Z)
 	*/
 
-	heights = common.DedupFloat64s(heights)
+	heights = heights.Dedup()
 
 	return generateIsoAreas(ctx, tx, feedback, tree, heights, id)
 }
@@ -943,7 +943,7 @@
 	tx *sql.Tx,
 	feedback Feedback,
 	tree *mesh.STRTree,
-	heights []float64,
+	heights mesh.ClassBreaks,
 	id int64,
 ) error {
 	feedback.Info("Generate iso areas")
@@ -975,7 +975,7 @@
 	feedback Feedback,
 	areas []wkb.MultiPolygonGeom,
 	epsg uint32,
-	heights []float64,
+	heights mesh.ClassBreaks,
 	id int64,
 ) error {
 	feedback.Info("Store iso areas.")
--- a/pkg/mesh/classbreaks.go	Wed Jul 07 09:43:41 2021 +0200
+++ b/pkg/mesh/classbreaks.go	Wed Jul 07 10:58:14 2021 +0200
@@ -21,6 +21,8 @@
 	"sort"
 	"strconv"
 	"strings"
+
+	"gemma.intevation.de/gemma/pkg/common"
 )
 
 const (
@@ -29,8 +31,10 @@
 WHERE config_key = $1`
 )
 
-func SampleDiffHeights(min, max, step float64) []float64 {
-	var heights []float64
+type ClassBreaks []float64
+
+func SampleDiffHeights(min, max, step float64) ClassBreaks {
+	var heights ClassBreaks
 	switch {
 	case min >= 0: // All values positive.
 		for v := 0.0; v <= max; v += step {
@@ -58,10 +62,10 @@
 	return heights
 }
 
-func ParseClassBreaks(config string) ([]float64, error) {
+func ParseClassBreaks(config string) (ClassBreaks, error) {
 
 	parts := strings.Split(config, ",")
-	classes := make([]float64, 0, len(parts))
+	classes := make(ClassBreaks, 0, len(parts))
 	for _, part := range parts {
 		if idx := strings.IndexRune(part, ':'); idx >= 0 {
 			part = part[:idx]
@@ -80,7 +84,7 @@
 	return classes, nil
 }
 
-func LoadClassBreaks(ctx context.Context, tx *sql.Tx, key string) ([]float64, error) {
+func LoadClassBreaks(ctx context.Context, tx *sql.Tx, key string) (ClassBreaks, error) {
 
 	var config sql.NullString
 
@@ -102,12 +106,12 @@
 	return math.Round(v*10000) / 10000
 }
 
-func ExtrapolateClassBreaks(cbs []float64, min, max float64) []float64 {
+func (cbs ClassBreaks) ExtrapolateClassBreaks(min, max float64) ClassBreaks {
 	if min > max {
 		min, max = max, min
 	}
 
-	n := make([]float64, len(cbs))
+	n := make(ClassBreaks, len(cbs))
 	copy(n, cbs)
 	sort.Float64s(n)
 
@@ -148,3 +152,7 @@
 
 	return n
 }
+
+func (cbs ClassBreaks) Dedup() ClassBreaks {
+	return ClassBreaks(common.DedupFloat64s(cbs))
+}
--- a/pkg/mesh/raster.go	Wed Jul 07 09:43:41 2021 +0200
+++ b/pkg/mesh/raster.go	Wed Jul 07 10:58:14 2021 +0200
@@ -195,7 +195,7 @@
 	return min, max, min != math.MaxFloat64
 }
 
-func (r *Raster) Trace(heights []float64) []wkb.MultiPolygonGeom {
+func (r *Raster) Trace(heights ClassBreaks) []wkb.MultiPolygonGeom {
 	start := time.Now()
 
 	tracer := contourmap.FromFloat64s(r.XCells+2, r.YCells+2, r.Cells)