# HG changeset patch # User Sascha L. Teichmann # Date 1570830395 -7200 # Node ID a1a9b1eab57c6daf4dfae59c785c132242815bf0 # Parent b5d9647c5bc1035e3ed440b638dca4630bf5527f Use append/slicing trick to simplify tree traversals. diff -r b5d9647c5bc1 -r a1a9b1eab57c pkg/octree/strtree.go --- a/pkg/octree/strtree.go Fri Oct 11 23:36:28 2019 +0200 +++ b/pkg/octree/strtree.go Fri Oct 11 23:46:35 2019 +0200 @@ -127,12 +127,8 @@ s.allTriangles(top, removed) default: // mixed bag - // TODO slicing like: - // n := s.index[top+1] - // stack = append(stack, s.index[top+2:top+2+n]...) - for i, n := int32(0), s.index[top+1]; i < n; i++ { - stack = append(stack, s.index[top+2+i]) - } + n := s.index[top+1] + stack = append(stack, s.index[top+2:top+2+n]...) } } else { // leaf top = -top - 1 @@ -160,9 +156,8 @@ top := stack[len(stack)-1] stack = stack[:len(stack)-1] if top > 0 { // node - for i, n := int32(0), s.index[top+1]; i < n; i++ { - stack = append(stack, s.index[top+2+i]) - } + n := s.index[top+1] + stack = append(stack, s.index[top+2:top+2+n]...) } else { // leaf top = -top - 1 for i, n := int32(0), s.index[top+1]; i < n; i++ {