mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
Ran rubocop autocorrect
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
class AABBTree
|
||||
class AABBNode
|
||||
attr_accessor :bounding_box, :parent, :object
|
||||
attr_reader :a, :b
|
||||
|
||||
def initialize(parent:, object:, bounding_box:)
|
||||
@parent = parent
|
||||
@object = object
|
||||
@@ -34,7 +36,7 @@ class IMICFPS
|
||||
new_node.a = self
|
||||
new_node.b = leaf
|
||||
|
||||
return new_node
|
||||
new_node
|
||||
else
|
||||
cost_a = @a.bounding_box.volume + @b.bounding_box.union(leaf.bounding_box).volume
|
||||
cost_b = @b.bounding_box.volume + @a.bounding_box.union(leaf.bounding_box).volume
|
||||
@@ -52,7 +54,7 @@ class IMICFPS
|
||||
|
||||
@bounding_box = @bounding_box.union(leaf.bounding_box)
|
||||
|
||||
return self
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
@@ -66,21 +68,19 @@ class IMICFPS
|
||||
end
|
||||
end
|
||||
|
||||
return items
|
||||
items
|
||||
end
|
||||
|
||||
def remove_subtree(leaf)
|
||||
if leaf
|
||||
return self
|
||||
self
|
||||
elsif leaf.parent == self
|
||||
other_child = other(leaf)
|
||||
other_child.parent = @parent
|
||||
other_child
|
||||
else
|
||||
if leaf.parent == self
|
||||
other_child = other(leaf)
|
||||
other_child.parent = @parent
|
||||
return other_child
|
||||
else
|
||||
leaf.parent.disown_child(leaf)
|
||||
return self
|
||||
end
|
||||
leaf.parent.disown_child(leaf)
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
@@ -116,11 +116,11 @@ class IMICFPS
|
||||
unless node.leaf?
|
||||
node.bounding_box = node.a.bounding_box.union(node.b.bounding_box)
|
||||
|
||||
while(node = node.parent)
|
||||
while (node = node.parent)
|
||||
node.bounding_box = node.a.bounding_box.union(node.b.bounding_box)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
class AABBTree
|
||||
include IMICFPS::AABBTreeDebug
|
||||
|
||||
attr_reader :root, :objects, :branches, :leaves
|
||||
|
||||
def initialize
|
||||
@objects = {}
|
||||
@root = nil
|
||||
@@ -23,11 +25,11 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def insert_leaf(leaf)
|
||||
if @root
|
||||
@root = @root.insert_subtree(leaf)
|
||||
else
|
||||
@root = leaf
|
||||
end
|
||||
@root = if @root
|
||||
@root.insert_subtree(leaf)
|
||||
else
|
||||
leaf
|
||||
end
|
||||
end
|
||||
|
||||
def update(object, bounding_box)
|
||||
@@ -41,17 +43,17 @@ class IMICFPS
|
||||
items = []
|
||||
if @root
|
||||
items = @root.search_subtree(collider)
|
||||
items.map! {|e| e.object} unless return_nodes
|
||||
items.map!(&:object) unless return_nodes
|
||||
end
|
||||
|
||||
return items
|
||||
items
|
||||
end
|
||||
|
||||
def remove(object)
|
||||
leaf = @objects.delete(object)
|
||||
@root = @root.remove_subtree(leaf) if leaf
|
||||
|
||||
return leaf
|
||||
leaf
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class IMICFPS
|
||||
# Gets included into AABBTree
|
||||
module AABBTreeDebug
|
||||
def inspect
|
||||
@branches, @leaves = 0, 0
|
||||
@branches = 0
|
||||
@leaves = 0
|
||||
if @root
|
||||
node = @root
|
||||
|
||||
@@ -11,7 +13,7 @@ class IMICFPS
|
||||
debug_search(node.b)
|
||||
end
|
||||
|
||||
puts "<#{self.class}:#{self.object_id}> has #{@branches} branches and #{@leaves} leaves"
|
||||
puts "<#{self.class}:#{object_id}> has #{@branches} branches and #{@leaves} leaves"
|
||||
end
|
||||
|
||||
def debug_search(node)
|
||||
@@ -24,4 +26,4 @@ class IMICFPS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user