Skip to content

Commit

Permalink
Remove useless CNTree.computeNumLevels()
Browse files Browse the repository at this point in the history
  • Loading branch information
arl committed Jun 4, 2017
1 parent 3d77788 commit 4444963
Showing 1 changed file with 10 additions and 36 deletions.
46 changes: 10 additions & 36 deletions cntree.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ func NewCNTree(scanner binimg.Scanner, resolution int) (*CNTree, error) {
resolution: resolution,
scanner: scanner,
},
nLevels: 1,
}
// given the resolution and the size, we can determine
// the max number of levels in the tree
q.computeNumLevels(scanner.Bounds().Dx())
// the maxmum number of levels the quadtree can have
n := uint(q.scanner.Bounds().Dx())
for n&1 == 0 {
n >>= 1
if n < uint(q.resolution) {
break
}
q.nLevels++
}

q.root = &CNNode{
basicNode: basicNode{
Expand Down Expand Up @@ -180,40 +188,6 @@ func (q *CNTree) subdivide(p *CNNode) {
}
}

// Root returns the quadtree root node.
func (q *CNTree) Root() Node {
return q.root
}

// ForEachLeaf calls the given function for each leaf node of the quadtree.
//
// Successive calls to the provided function are performed in no particular
// order. The color parameter allows to loop on the leaves of a particular
// color, Black or White.
// NOTE: As by definition, Gray leaves do not exist, passing Gray to
// ForEachLeaf should return all leaves, independently of their color.
func (q *CNTree) ForEachLeaf(color Color, fn func(Node)) {
for _, n := range q.leaves {
if color == Gray || n.Color() == color {
fn(n)
}
}
}

// given the resolution, that is a power of 2, and the size, compute the
// maximum number of levels the quadtree can have
func (q *CNTree) computeNumLevels(size int) {
q.nLevels = 1
n := uint(size)
for n&1 == 0 {
n >>= 1
if n < uint(q.resolution) {
break
}
q.nLevels++
}
}

// locate returns the Node that contains the given point, or nil.
func (q *CNTree) locate(pt image.Point) Node {
// binary branching method assumes the point lies in the bounds
Expand Down

0 comments on commit 4444963

Please sign in to comment.