Sha256: 1c97470ea275e34b441fb1ee788390abf0b9b097c2dc772d91f2743faba485aa

Contents?: true

Size: 917 Bytes

Versions: 13

Compression:

Stored size: 917 Bytes

Contents

module AABBTreeDebugHelpers
  def valid?
    return true unless @root
    @root.contains_children?
  end

  def each(&blk)
    return unless @root
    query @root.bb, &blk
  end

  def each_node(&blk)
    return unless @root
    @root.each_node &blk
  end

  def each_leaf(&blk)
    return unless @root
    @root.each_leaf &blk
  end
end

module AABBNodeDebugHelpers

  def contains_children?
    if leaf?
      true
    else
      @bb.contain?(a.bb) &&
        @bb.contain?(b.bb) &&
        @a.contains_children? &&
        @b.contains_children?
    end
  end

  def each_node(&blk)
    blk.call self
    unless leaf?
      @a.each_node &blk
      @b.each_node &blk
    end
  end

  def each_leaf(&blk)
    if leaf?
      blk.call self
    else leaf?
      @a.each_leaf &blk
      @b.each_leaf &blk
    end
  end

  def root
    node = self
    while node.parent
      node = node.parent
    end
    node
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gamebox-0.5.5 lib/gamebox/core/aabb_helpers.rb
gamebox-0.5.4 lib/gamebox/core/aabb_helpers.rb
gamebox-0.5.2 lib/gamebox/core/aabb_helpers.rb
gamebox-0.5.1 lib/gamebox/core/aabb_helpers.rb
gamebox-0.5.0 lib/gamebox/core/aabb_helpers.rb
gamebox-0.4.1 lib/gamebox/core/aabb_helpers.rb
gamebox-0.4.0 lib/gamebox/core/aabb_helpers.rb
gamebox-0.4.0.rc11 lib/gamebox/core/aabb_helpers.rb
gamebox-0.4.0.rc5 lib/gamebox/core/aabb_helpers.rb
gamebox-0.4.0.rc4 lib/gamebox/core/aabb_helpers.rb
gamebox-0.4.0.rc3 lib/gamebox/core/aabb_helpers.rb
gamebox-0.4.0.rc2 lib/gamebox/core/aabb_helpers.rb
gamebox-0.4.0.rc1 lib/gamebox/core/aabb_helpers.rb