changeset 5413:99f32f0dc70c marking-single-beam

Added tools to classify vertices by their heights with class breaks.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 07 Jul 2021 11:42:25 +0200
parents 34bc6041e61e
children bb402cdfe545
files pkg/mesh/classbreaks.go pkg/mesh/vertex.go
diffstat 2 files changed, 45 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/mesh/classbreaks.go	Wed Jul 07 10:58:14 2021 +0200
+++ b/pkg/mesh/classbreaks.go	Wed Jul 07 11:42:25 2021 +0200
@@ -156,3 +156,18 @@
 func (cbs ClassBreaks) Dedup() ClassBreaks {
 	return ClassBreaks(common.DedupFloat64s(cbs))
 }
+
+func (cbs ClassBreaks) Classify(points func() (Vertex, bool)) []MultiPointZ {
+	classes := make([]MultiPointZ, len(cbs)+1)
+	for v, ok := points(); ok; v, ok = points() {
+		idx := len(cbs)
+		for i, cb := range cbs {
+			if v.Z <= cb {
+				idx = i
+				break
+			}
+		}
+		classes[idx] = append(classes[idx], v)
+	}
+	return classes
+}
--- a/pkg/mesh/vertex.go	Wed Jul 07 10:58:14 2021 +0200
+++ b/pkg/mesh/vertex.go	Wed Jul 07 11:42:25 2021 +0200
@@ -1134,6 +1134,36 @@
 	return out
 }
 
+// FilterRemoved returns an iterator that only delivers the vertices
+// which indices are not marked as removed.
+func (mpz MultiPointZ) FilterRemoved(removed map[int]struct{}) func() (Vertex, bool) {
+	var idx int
+	return func() (Vertex, bool) {
+		for {
+			if idx >= len(mpz) {
+				return Vertex{}, false
+			}
+			if _, rm := removed[idx]; rm {
+				idx++
+				continue
+			}
+			break
+		}
+		return mpz[idx], true
+	}
+}
+
+// MinMaxVertex runs over a point iterator and figures out its boundary.
+func MinMaxVertex(points func() (Vertex, bool)) (Vertex, Vertex) {
+	min := Vertex{math.MaxFloat64, math.MaxFloat64, math.MaxFloat64}
+	max := Vertex{-math.MaxFloat64, -math.MaxFloat64, -math.MaxFloat64}
+	for v, ok := points(); ok; v, ok = points() {
+		min.Minimize(v)
+		max.Maximize(v)
+	}
+	return min, max
+}
+
 // AsWKB returns a WKB representation of the given point cloud.
 func (mpz MultiPointZ) AsWKB() []byte {
 	size := 1 + 4 + 4 + len(mpz)*(1+4+3*8)