class Waxy::Geometry::Hex

Attributes

q[RW]
r[RW]
s[RW]
size[RW]

Vector of 6 x (0.0 - 1.0) Used to scale the pie slices

!! @size is typically set during render through a Waxy::Meta

Public Class Methods

new(_q, _r, _s = nil) click to toggle source

All params are Int

# File lib/waxy/geometry/hex.rb, line 14
def initialize(_q, _r, _s = nil)
  @q = _q
  @r = _r 
  @s = _s 
end

Public Instance Methods

!=(b) click to toggle source
# File lib/waxy/geometry/hex.rb, line 32
def != (b)
  !(self == b)
end
*(k) click to toggle source

@param a [Hex] @param k [Int]

# File lib/waxy/geometry/hex.rb, line 46
def * (k)
  Hex.new(q * k, r * k, (s ? s * k : nil))
end
+(b) click to toggle source
# File lib/waxy/geometry/hex.rb, line 36
def + (b)
  Hex.new(q + b.q, r + b.r, ( s ? s + b.s : nil))
end
-(b) click to toggle source
# File lib/waxy/geometry/hex.rb, line 40
def - (b)
  Hex.new(q - b.q, r - b.r,  (s ? s - b.s : nil))
end
==(b) click to toggle source
# File lib/waxy/geometry/hex.rb, line 28
def == (b)
  q == b.q && r == b.r && s == b.s 
end
distance(b) click to toggle source
# File lib/waxy/geometry/hex.rb, line 54
def distance(b)
  hex_length(self - b)
end
hex_direction(i) click to toggle source
# File lib/waxy/geometry/hex.rb, line 58
def hex_direction(i)
  raise if !(0..5).include?(i)
  HEX_DIRECTIONS_FLAT[i]
end
hex_length(hex) click to toggle source
# File lib/waxy/geometry/hex.rb, line 50
def hex_length(hex)
  ((hex.q.abs + hex.r.abs + hex.s.abs) / 2).to_i
end
hex_neighbor(i) click to toggle source

(0..5, requires modulo prior)

# File lib/waxy/geometry/hex.rb, line 64
def hex_neighbor(i)
  self + hex_direction(i)
end