Class: Alchemist::Geography::Loc
- Defined in:
- lib/alchemist-server/geography.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #distance(loc) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(x, y) ⇒ Loc
constructor
A new instance of Loc.
- #within?(min, max) ⇒ Boolean
Constructor Details
#initialize(x, y) ⇒ Loc
Returns a new instance of Loc.
78 79 80 81 |
# File 'lib/alchemist-server/geography.rb', line 78 def initialize(x,y) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
72 73 74 |
# File 'lib/alchemist-server/geography.rb', line 72 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
72 73 74 |
# File 'lib/alchemist-server/geography.rb', line 72 def y @y end |
Class Method Details
.[](*args) ⇒ Object
74 75 76 |
# File 'lib/alchemist-server/geography.rb', line 74 def self.[](*args) new *args end |
Instance Method Details
#==(other) ⇒ Object
99 100 101 102 103 |
# File 'lib/alchemist-server/geography.rb', line 99 def ==(other) other.class == self.class && other.x == x && other.y == y end |
#distance(loc) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/alchemist-server/geography.rb', line 92 def distance(loc) [ (loc.x - x).abs, (loc.y - y).abs ].max end |
#eql?(other) ⇒ Boolean
105 106 107 |
# File 'lib/alchemist-server/geography.rb', line 105 def eql?(other) self == other end |
#hash ⇒ Object
83 84 85 |
# File 'lib/alchemist-server/geography.rb', line 83 def hash (@x.hash * 31) + @y.hash end |
#within?(min, max) ⇒ Boolean
87 88 89 90 |
# File 'lib/alchemist-server/geography.rb', line 87 def within?(min, max) min.x <= x && x <= max.x && min.y <= y && y <= max.y end |