Class: Geometer::Dimensions

Inherits:
Struct
  • Object
show all
Includes:
PointHelpers
Defined in:
lib/geometer/dimensions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PointHelpers

#coord

Instance Attribute Details

#heightObject

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



2
3
4
# File 'lib/geometer/dimensions.rb', line 2

def height
  @height
end

#widthObject

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



2
3
4
# File 'lib/geometer/dimensions.rb', line 2

def width
  @width
end

Instance Method Details

#all_locationsObject



31
32
33
# File 'lib/geometer/dimensions.rb', line 31

def all_locations
  @all_locations ||= assemble_all_locations
end

#areaObject



19
20
21
# File 'lib/geometer/dimensions.rb', line 19

def area
  x_range.size * y_range.size
end

#assemble_all_locationsObject



35
36
37
38
39
40
41
42
43
# File 'lib/geometer/dimensions.rb', line 35

def assemble_all_locations
  locs = []
  x_range.each do |x|
    y_range.each do |y|
      locs.push coord(x,y)
    end
  end
  locs
end

#contains?(position) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/geometer/dimensions.rb', line 9

def contains?(position)
  x,y=*position
  x_range.include?(x) && y_range.include?(y)
end

#inspectObject



5
6
7
# File 'lib/geometer/dimensions.rb', line 5

def inspect
  "#{width}x#{height}"
end

#sampleObject



14
15
16
17
# File 'lib/geometer/dimensions.rb', line 14

def sample
  x,y = x_range.to_a.sample, y_range.to_a.sample
  coord(x,y)
end

#x_rangeObject



23
24
25
# File 'lib/geometer/dimensions.rb', line 23

def x_range
  0..(width-1)
end

#y_rangeObject



27
28
29
# File 'lib/geometer/dimensions.rb', line 27

def y_range
  0..(height-1)
end