changeset 4549:9c65cef72753 iso-areas

Fixed bit mask usage.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 30 Sep 2019 14:59:20 +0200
parents befb94e3a953
children aa2d0006e742
files cmd/isoareas/main.go
diffstat 1 files changed, 6 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/cmd/isoareas/main.go	Mon Sep 30 11:22:41 2019 +0200
+++ b/cmd/isoareas/main.go	Mon Sep 30 14:59:20 2019 +0200
@@ -23,7 +23,6 @@
 	"math/bits"
 	"math/rand"
 	"os"
-	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -254,20 +253,6 @@
 		}
 	}
 
-	for l, c := range classes {
-		sorted := sort.SliceIsSorted(c, func(i, j int) bool {
-			return c[i] < c[j]
-		})
-		log.Printf("class[%d] sorted: %t\n", l, sorted)
-	}
-
-	for l, c := range cuts {
-		sorted := sort.SliceIsSorted(c, func(i, j int) bool {
-			return c[i].index < c[j].index
-		})
-		log.Printf("cut[%d] sorted: %t\n", l, sorted)
-	}
-
 	// connect the arcs in a cut list to longer arcs.
 
 	for _, c := range cuts {
@@ -290,11 +275,11 @@
 			ns := neighbors(tri, idx)
 			mask := where(ns, c)
 			switch bits.OnesCount8(mask) {
-			case 0:
+			case 3:
 				// Totally insides do not contribute to the geometries.
 				inside++
 				continue allInClass
-			case 3:
+			case 0:
 				// Isolated are areas w/o connections to the rest.
 				isolated++
 				ti := tri.Triangles[idx*3 : idx*3+3]
@@ -367,6 +352,9 @@
 		/*
 			for e := pb.open.Front(); e != nil; e = e.Next() {
 				line := e.Value.(octree.LineStringZ)
+				if !line.CCW() {
+					line.Reverse()
+				}
 				pb.polygons = append(pb.polygons, line)
 			}
 		*/
@@ -436,7 +424,7 @@
 func where(neighbors, indices []int32) byte {
 	var mask byte
 	for i, n := range neighbors {
-		if n < 0 || !contains(n/3, indices) {
+		if n >= 0 && contains(n/3, indices) {
 			mask |= 1 << i
 		}
 	}