changeset 4575:6415368c2c60 iso-areas

Use simple super-sampling when rasterizing.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 07 Oct 2019 17:48:56 +0200
parents daed8a92024a
children 3290d1b2c580
files pkg/octree/areas.go
diffstat 1 files changed, 25 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/octree/areas.go	Mon Oct 07 13:13:14 2019 +0200
+++ b/pkg/octree/areas.go	Mon Oct 07 17:48:56 2019 +0200
@@ -61,15 +61,37 @@
 
 	rasterRow := func() {
 		defer wg.Done()
+		quat := 0.25 * cellSize
 		for i := range rows {
 			pos := (i+1)*(xcells+2) + 1
 			row := raster[pos : pos+xcells]
 			py := min.Y + float64(i)*cellSize + cellSize/2
 			px := min.X + cellSize/2
+			y1 := py - quat
+			y2 := py + quat
 			for j := range row {
-				v, ok := tree.Value(px, py)
-				if ok {
-					row[j] = v
+				var n int
+				var sum float64
+
+				if v, ok := tree.Value(px-quat, y1); ok {
+					sum = v
+					n = 1
+				}
+				if v, ok := tree.Value(px-quat, y2); ok {
+					sum += v
+					n++
+				}
+				if v, ok := tree.Value(px+quat, y1); ok {
+					sum += v
+					n++
+				}
+				if v, ok := tree.Value(px+quat, y2); ok {
+					sum += v
+					n++
+				}
+
+				if n > 0 {
+					row[j] = sum / float64(n)
 				}
 				px += cellSize
 			}