# HG changeset patch # User Sascha L. Teichmann # Date 1625650945 -7200 # Node ID 99f32f0dc70c25323a8edecac504715d3b5bf66c # Parent 34bc6041e61e709f8b0ac4dc002dea6859c0e762 Added tools to classify vertices by their heights with class breaks. diff -r 34bc6041e61e -r 99f32f0dc70c pkg/mesh/classbreaks.go --- 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 +} diff -r 34bc6041e61e -r 99f32f0dc70c pkg/mesh/vertex.go --- 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)