comparison cmd/isoareas/main.go @ 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
comparison
equal deleted inserted replaced
4548:befb94e3a953 4549:9c65cef72753
21 "log" 21 "log"
22 "math" 22 "math"
23 "math/bits" 23 "math/bits"
24 "math/rand" 24 "math/rand"
25 "os" 25 "os"
26 "sort"
27 "strconv" 26 "strconv"
28 "strings" 27 "strings"
29 "time" 28 "time"
30 29
31 svg "github.com/ajstarks/svgo" 30 svg "github.com/ajstarks/svgo"
252 cuts[j] = append(cuts[j], indexedArc{arc: arc, index: i / 3}) 251 cuts[j] = append(cuts[j], indexedArc{arc: arc, index: i / 3})
253 } 252 }
254 } 253 }
255 } 254 }
256 255
257 for l, c := range classes {
258 sorted := sort.SliceIsSorted(c, func(i, j int) bool {
259 return c[i] < c[j]
260 })
261 log.Printf("class[%d] sorted: %t\n", l, sorted)
262 }
263
264 for l, c := range cuts {
265 sorted := sort.SliceIsSorted(c, func(i, j int) bool {
266 return c[i].index < c[j].index
267 })
268 log.Printf("cut[%d] sorted: %t\n", l, sorted)
269 }
270
271 // connect the arcs in a cut list to longer arcs. 256 // connect the arcs in a cut list to longer arcs.
272 257
273 for _, c := range cuts { 258 for _, c := range cuts {
274 connectArcs(tri, c, &arcs) 259 connectArcs(tri, c, &arcs)
275 } 260 }
288 allInClass: 273 allInClass:
289 for _, idx := range c { 274 for _, idx := range c {
290 ns := neighbors(tri, idx) 275 ns := neighbors(tri, idx)
291 mask := where(ns, c) 276 mask := where(ns, c)
292 switch bits.OnesCount8(mask) { 277 switch bits.OnesCount8(mask) {
293 case 0: 278 case 3:
294 // Totally insides do not contribute to the geometries. 279 // Totally insides do not contribute to the geometries.
295 inside++ 280 inside++
296 continue allInClass 281 continue allInClass
297 case 3: 282 case 0:
298 // Isolated are areas w/o connections to the rest. 283 // Isolated are areas w/o connections to the rest.
299 isolated++ 284 isolated++
300 ti := tri.Triangles[idx*3 : idx*3+3] 285 ti := tri.Triangles[idx*3 : idx*3+3]
301 pb.addTriangle( 286 pb.addTriangle(
302 tri.Points[ti[0]], 287 tri.Points[ti[0]],
365 i, inside, isolated, pb.open.Len(), len(pb.polygons), dupes, found) 350 i, inside, isolated, pb.open.Len(), len(pb.polygons), dupes, found)
366 351
367 /* 352 /*
368 for e := pb.open.Front(); e != nil; e = e.Next() { 353 for e := pb.open.Front(); e != nil; e = e.Next() {
369 line := e.Value.(octree.LineStringZ) 354 line := e.Value.(octree.LineStringZ)
355 if !line.CCW() {
356 line.Reverse()
357 }
370 pb.polygons = append(pb.polygons, line) 358 pb.polygons = append(pb.polygons, line)
371 } 359 }
372 */ 360 */
373 361
374 result[i] = pb.polygons 362 result[i] = pb.polygons
434 } 422 }
435 423
436 func where(neighbors, indices []int32) byte { 424 func where(neighbors, indices []int32) byte {
437 var mask byte 425 var mask byte
438 for i, n := range neighbors { 426 for i, n := range neighbors {
439 if n < 0 || !contains(n/3, indices) { 427 if n >= 0 && contains(n/3, indices) {
440 mask |= 1 << i 428 mask |= 1 << i
441 } 429 }
442 } 430 }
443 return mask 431 return mask
444 } 432 }