Class: Bomp::QuadTree

Inherits:
ColliderSystem show all
Defined in:
lib/bomp.rb

Defined Under Namespace

Classes: QuadNode

Instance Attribute Summary collapse

Attributes inherited from ColliderSystem

#items

Instance Method Summary collapse

Methods inherited from ColliderSystem

#add, #clear!, #remove, #to_a

Constructor Details

#initialize(width, height, **opts) ⇒ QuadTree



181
182
183
184
185
# File 'lib/bomp.rb', line 181

def initialize(width, height, **opts)
  super()
  @opts = opts
  @child = QuadNode.new(0, 0, width, height, @opts)
end

Instance Attribute Details

#childObject (readonly)

Returns the value of attribute child.



179
180
181
# File 'lib/bomp.rb', line 179

def child
  @child
end

Instance Method Details

#reload!Object



197
198
199
200
# File 'lib/bomp.rb', line 197

def reload!
  @child&.clear
  @items.each { |item| @child.insert item }
end

#restart!Object



202
203
204
205
# File 'lib/bomp.rb', line 202

def restart!
  clear!
  @child = QuadNode.new(0, 0, width, height, @opts)
end

#sort(group = nil, reload = true) ⇒ Object



187
188
189
190
191
192
193
194
195
# File 'lib/bomp.rb', line 187

def sort(group = nil, reload = true)
  reload! if reload

  if group.nil?
    @child.to_a
  else
    @child.group_by group
  end
end