seperate different Position classes into own files
also tests and have Position module keep all positions (singletons should be at module, not class level)
This commit is contained in:
36
lib/risc/position/object_position.rb
Normal file
36
lib/risc/position/object_position.rb
Normal file
@ -0,0 +1,36 @@
|
||||
module Risc
|
||||
module Position
|
||||
class ObjectPosition
|
||||
attr_reader :at
|
||||
|
||||
def initialize( at )
|
||||
@at = at
|
||||
raise "not int #{self}-#{at}" unless @at.is_a?(Integer)
|
||||
end
|
||||
|
||||
def +(offset)
|
||||
offset = offset.at if offset.is_a?(ObjectPosition)
|
||||
@at + offset
|
||||
end
|
||||
|
||||
def -(offset)
|
||||
offset = offset.at if offset.is_a?(ObjectPosition)
|
||||
@at - offset
|
||||
end
|
||||
def to_s
|
||||
"0x#{@at.to_s(16)}"
|
||||
end
|
||||
# just a callback after creation AND insertion
|
||||
def init(pos)
|
||||
end
|
||||
def reset_to(pos)
|
||||
return false if pos == at
|
||||
if((at - pos).abs > 1000)
|
||||
raise "position set too far off #{pos}!=#{at} for #{object}:#{object.class}"
|
||||
end
|
||||
@at = pos
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user