diff pkg/mesh/vertex.go @ 5428:b8d5f1cd15fb marking-single-beam

Simplified classification. Needs testing.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 11 Jul 2021 13:08:49 +0200
parents 202715173935
children 5f47eeea988d
line wrap: on
line diff
--- a/pkg/mesh/vertex.go	Sat Jul 10 01:09:57 2021 +0200
+++ b/pkg/mesh/vertex.go	Sun Jul 11 13:08:49 2021 +0200
@@ -1144,47 +1144,23 @@
 	return out
 }
 
-// All returns all points as an iterator.
-func (mpz MultiPointZ) All() func() (Vertex, bool) {
-	var idx int
-	return func() (v Vertex, ok bool) {
-		if idx >= len(mpz) {
-			ok = false
-			return
+// Filter returns a copy removed the vertices which
+// don't pass the filter test.
+func (mpz MultiPointZ) Filter(filter func(Vertex) bool) MultiPointZ {
+	n := make(MultiPointZ, 0, len(mpz))
+	for _, v := range mpz {
+		if filter(v) {
+			n = append(n, v)
 		}
-		v, ok = mpz[idx], true
-		idx++
-		return
 	}
+	return n
 }
 
-// FilterRemoved returns an iterator that only delivers the vertices
-// which indices are not marked as removed.
-func (mpz MultiPointZ) FilterRemoved(removed map[int32]struct{}) func() (Vertex, bool) {
-	var idx int32
-	return func() (v Vertex, ok bool) {
-		for {
-			if idx >= int32(len(mpz)) {
-				ok = false
-				return
-			}
-			if _, rm := removed[idx]; rm {
-				idx++
-				continue
-			}
-			break
-		}
-		v, ok = mpz[idx], true
-		idx++
-		return
-	}
-}
-
-// MinMaxVertex runs over a point iterator and figures out its boundary.
-func MinMaxVertex(points func() (Vertex, bool)) (Vertex, Vertex) {
+// MinMaxVertex returns the extend of the point set.
+func (mpz MultiPointZ) MinMax() (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() {
+	for _, v := range mpz {
 		min.Minimize(v)
 		max.Maximize(v)
 	}