Class: EightCorner::Bounds
- Inherits:
-
Object
- Object
- EightCorner::Bounds
- Defined in:
- lib/eight_corner/bounds.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
width.
-
#y ⇒ Object
height.
Instance Method Summary collapse
-
#initialize(x = nil, y = nil) ⇒ Bounds
constructor
A new instance of Bounds.
- #quadrant(point) ⇒ Object
- #x_from_pct(percent) ⇒ Object
- #y_from_pct(percent) ⇒ Object
Constructor Details
#initialize(x = nil, y = nil) ⇒ Bounds
Returns a new instance of Bounds.
11 12 13 14 |
# File 'lib/eight_corner/bounds.rb', line 11 def initialize(x=nil, y=nil) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object
width
6 7 8 |
# File 'lib/eight_corner/bounds.rb', line 6 def x @x end |
#y ⇒ Object
height
9 10 11 |
# File 'lib/eight_corner/bounds.rb', line 9 def y @y end |
Instance Method Details
#quadrant(point) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/eight_corner/bounds.rb', line 23 def quadrant(point) current = [ point.x < x/2 ? 0 : 1, point.y < y/2 ? 0 : 1 ] { [0,0] => Quadrant::UPPER_LEFT, [1,0] => Quadrant::UPPER_RIGHT, [0,1] => Quadrant::LOWER_LEFT, [1,1] => Quadrant::LOWER_RIGHT }[current] end |
#x_from_pct(percent) ⇒ Object
16 17 18 |
# File 'lib/eight_corner/bounds.rb', line 16 def x_from_pct(percent) @x * percent end |
#y_from_pct(percent) ⇒ Object
19 20 21 |
# File 'lib/eight_corner/bounds.rb', line 19 def y_from_pct(percent) @y * percent end |