comparison pkg/mesh/raster.go @ 5601:1222b777f51f

Made golint finally happy.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 06 Aug 2022 02:09:57 +0200
parents 5f47eeea988d
children d2ccf6bb6940
comparison
equal deleted inserted replaced
5600:9967a78e43f4 5601:1222b777f51f
24 "gemma.intevation.de/gemma/pkg/common" 24 "gemma.intevation.de/gemma/pkg/common"
25 "gemma.intevation.de/gemma/pkg/log" 25 "gemma.intevation.de/gemma/pkg/log"
26 "gemma.intevation.de/gemma/pkg/wkb" 26 "gemma.intevation.de/gemma/pkg/wkb"
27 ) 27 )
28 28
29 // Raster represents a 2D cell raster with a given extend.
30 // The cells are equally sized in X and Y direction.
29 type Raster struct { 31 type Raster struct {
30 BBox Box2D 32 BBox Box2D
31 CellSize float64 33 CellSize float64
32 XCells int 34 XCells int
33 YCells int 35 YCells int
34 Cells []float64 36 Cells []float64
35 } 37 }
36 38
37 const noData = -math.MaxFloat64 39 const noData = -math.MaxFloat64
38 40
41 // NewRaster creates a new Raster with the given extend
42 // and cell size.
39 func NewRaster(bbox Box2D, cellSize float64) *Raster { 43 func NewRaster(bbox Box2D, cellSize float64) *Raster {
40 44
41 width, height := bbox.Size() 45 width, height := bbox.Size()
42 46
43 log.Infof("raster extent: %.2f / %.2f", width, height) 47 log.Infof("raster extent: %.2f / %.2f", width, height)
59 YCells: yCells, 63 YCells: yCells,
60 Cells: cells, 64 Cells: cells,
61 } 65 }
62 } 66 }
63 67
68 // Rasterize fills the raster with the evaluation data
69 // received via the given eval function. The cell values
70 // 4x oversampled,
64 func (r *Raster) Rasterize(eval func(float64, float64) (float64, bool)) { 71 func (r *Raster) Rasterize(eval func(float64, float64) (float64, bool)) {
65 var wg sync.WaitGroup 72 var wg sync.WaitGroup
66 73
67 rows := make(chan int) 74 rows := make(chan int)
68 75
115 } 122 }
116 close(rows) 123 close(rows)
117 wg.Wait() 124 wg.Wait()
118 } 125 }
119 126
127 // Diff updates the cell values of the raster with difference
128 // of this raster and the values from the gien eval function.
129 // The data will 4x over-sampled.
120 func (r *Raster) Diff(eval func(float64, float64) (float64, bool)) { 130 func (r *Raster) Diff(eval func(float64, float64) (float64, bool)) {
121 var wg sync.WaitGroup 131 var wg sync.WaitGroup
122 132
123 rows := make(chan int) 133 rows := make(chan int)
124 134
179 } 189 }
180 close(rows) 190 close(rows)
181 wg.Wait() 191 wg.Wait()
182 } 192 }
183 193
194 // ZExtent returns the z-range of the raster.
195 // The last return value is false if the raster
196 // only consists of no data values.
184 func (r *Raster) ZExtent() (float64, float64, bool) { 197 func (r *Raster) ZExtent() (float64, float64, bool) {
185 min, max := math.MaxFloat64, -math.MaxFloat64 198 min, max := math.MaxFloat64, -math.MaxFloat64
186 for _, v := range r.Cells { 199 for _, v := range r.Cells {
187 if v == noData { 200 if v == noData {
188 continue 201 continue
195 } 208 }
196 } 209 }
197 return min, max, min != math.MaxFloat64 210 return min, max, min != math.MaxFloat64
198 } 211 }
199 212
213 // Trace generates contour lines of this raster given
214 // the given class breaks.
200 func (r *Raster) Trace(heights ClassBreaks) []wkb.MultiPolygonGeom { 215 func (r *Raster) Trace(heights ClassBreaks) []wkb.MultiPolygonGeom {
201 start := time.Now() 216 start := time.Now()
202 217
203 tracer := contourmap.FromFloat64s(r.XCells+2, r.YCells+2, r.Cells) 218 tracer := contourmap.FromFloat64s(r.XCells+2, r.YCells+2, r.Cells)
204 219