# HG changeset patch # User Sascha L. Teichmann # Date 1537383834 -7200 # Node ID a31dc9486bd86b3d897c04ea9ddbce66692c7925 # Parent b17e3ce532852bd3b854f028fa013a697b323be4 octree: fixed triangle indexing bug in horizontal traversal and deduplicate triangles before sending them to callback. diff -r b17e3ce53285 -r a31dc9486bd8 cmd/octree2contour/loader.go --- a/cmd/octree2contour/loader.go Wed Sep 19 20:55:02 2018 +0200 +++ b/cmd/octree2contour/loader.go Wed Sep 19 21:03:54 2018 +0200 @@ -148,6 +148,8 @@ stack := []frame{{1, ot.min.z, ot.max.z}} + dupes := map[int32]struct{}{} + for len(stack) > 0 { top := stack[len(stack)-1] stack = stack[:len(stack)-1] @@ -176,7 +178,7 @@ //log.Printf("%d %d %d\n", pos, n, len(ot.index)) indices := ot.index[pos+1 : pos+1+n] - for idx := range indices { + for _, idx := range indices { tri := ot.triangles[idx] v0 := ot.vertices[tri[0]] v1 := ot.vertices[tri[1]] @@ -184,7 +186,10 @@ if !(math.Min(v0.z, math.Min(v1.z, v2.z)) > h || math.Max(v0.z, math.Max(v1.z, v2.z)) < h) { - fn(tri) + if _, found := dupes[idx]; !found { + dupes[idx] = struct{}{} + fn(tri) + } } } }