Class: Alchemist::Geography::Loc

Inherits:
Object
  • Object
show all
Defined in:
lib/alchemist-server/geography.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#xObject (readonly)

Returns the value of attribute x.



72
73
74
# File 'lib/alchemist-server/geography.rb', line 72

def x
  @x
end

#yObject (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

Returns:

  • (Boolean)


105
106
107
# File 'lib/alchemist-server/geography.rb', line 105

def eql?(other)
  self == other
end

#hashObject



83
84
85
# File 'lib/alchemist-server/geography.rb', line 83

def hash
  (@x.hash * 31) + @y.hash
end

#within?(min, max) ⇒ Boolean

Returns:

  • (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