Class: Entity
- Inherits:
-
Object
- Object
- Entity
- Defined in:
- lib/rmotion.rb,
ext/rmotion/rmotion_main.c
Class Method Summary collapse
Instance Method Summary collapse
- #center ⇒ Object
- #compare(oth) ⇒ Object
- #corners ⇒ Object
-
#initialize ⇒ Entity
constructor
A new instance of Entity.
Constructor Details
#initialize ⇒ Entity
Returns a new instance of Entity.
5 6 7 8 |
# File 'lib/rmotion.rb', line 5 def initialize @tlx = @tly = @brx = @bry = nil @@radius = 60 end |
Class Method Details
.reorder(previous, current) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rmotion.rb', line 26 def self.reorder previous, current previous.each_with_index do |p,i| next if p.center.nil? found = false current.each_with_index do |c,k| if p.compare c previous[i] = c current[k] = Entity.new found = true break end end unless found previous[i] = Entity.new end end current.each do |c| next if c.center.nil? previous.each_with_index do |p,i| if p.center.nil? previous[i] = c break end end end end |
.status ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/rmotion.rb', line 55 def self.status status = [] 8.times do status << Entity.new end status end |
Instance Method Details
#center ⇒ Object
10 11 12 |
# File 'lib/rmotion.rb', line 10 def center [(@tlx+@brx)/2,(@tly+@bry)/2] unless @tlx.nil? end |
#compare(oth) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/rmotion.rb', line 18 def compare oth if center.nil? or oth.center.nil? false else ((center.first - oth.center.first).abs < @@radius) and ((center.last - oth.center.last).abs < @@radius) end end |
#corners ⇒ Object
14 15 16 |
# File 'lib/rmotion.rb', line 14 def corners [@tlx,@tly,@brx,@bry] end |