Class: Geometer::Dimensions
- Inherits:
-
Struct
- Object
- Struct
- Geometer::Dimensions
- Includes:
- PointHelpers
- Defined in:
- lib/geometer/dimensions.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #all_locations ⇒ Object
- #area ⇒ Object
- #assemble_all_locations ⇒ Object
- #contains?(position) ⇒ Boolean
- #inspect ⇒ Object
- #sample ⇒ Object
- #x_range ⇒ Object
- #y_range ⇒ Object
Methods included from PointHelpers
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height
2 3 4 |
# File 'lib/geometer/dimensions.rb', line 2 def height @height end |
#width ⇒ Object
Returns the value of attribute width
2 3 4 |
# File 'lib/geometer/dimensions.rb', line 2 def width @width end |
Instance Method Details
#all_locations ⇒ Object
31 32 33 |
# File 'lib/geometer/dimensions.rb', line 31 def all_locations @all_locations ||= assemble_all_locations end |
#area ⇒ Object
19 20 21 |
# File 'lib/geometer/dimensions.rb', line 19 def area x_range.size * y_range.size end |
#assemble_all_locations ⇒ Object
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
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 |
#inspect ⇒ Object
5 6 7 |
# File 'lib/geometer/dimensions.rb', line 5 def inspect "#{width}x#{height}" end |
#sample ⇒ Object
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_range ⇒ Object
23 24 25 |
# File 'lib/geometer/dimensions.rb', line 23 def x_range 0..(width-1) end |
#y_range ⇒ Object
27 28 29 |
# File 'lib/geometer/dimensions.rb', line 27 def y_range 0..(height-1) end |