class Hexagonly::Space

Attributes

center[R]
east[R]
height[R]
north[R]
points[R]
south[R]
west[R]
width[R]

Public Class Methods

new(points) click to toggle source

@param [Array<Hexagonly::Point>] points an array of points that make up the space

# File lib/hexagonly/space.rb, line 7
def initialize(points)
  @points = points
  refresh
end

Private Instance Methods

compute_boundries() click to toggle source
# File lib/hexagonly/space.rb, line 19
def compute_boundries
  @north, @west, @south, @east = nil
  @points.each do |p|
    @north = p if @north.nil? || @north.y_coord < p.y_coord
    @west = p if @west.nil? || @west.x_coord > p.x_coord
    @south = p if @south.nil? || @south.y_coord > p.y_coord
    @east = p if @east.nil? || @east.x_coord < p.x_coord
  end
end
compute_center() click to toggle source
# File lib/hexagonly/space.rb, line 29
def compute_center
  compute_boundries if @north.nil? || @west.nil? || @south.nil? || @east.nil?
  @height = @north.y_coord - @south.y_coord
  @width = @east.x_coord - @west.x_coord
  @center = Hexagonly::Point.new(@width / 2 + @west.x_coord, @height / 2 + @south.y_coord)
end
refresh() click to toggle source
# File lib/hexagonly/space.rb, line 14
def refresh
  compute_boundries
  compute_center
end