Class: Metro::Units::RectangleBounds
- Inherits:
-
Object
- Object
- Metro::Units::RectangleBounds
- Includes:
- CalculationValidations
- Defined in:
- lib/metro/units/rectangle_bounds.rb
Overview
An object that represents a rectanglar bounds.
Instance Attribute Summary collapse
-
#bottom ⇒ Object
Returns the value of attribute bottom.
-
#left ⇒ Object
Returns the value of attribute left.
-
#right ⇒ Object
Returns the value of attribute right.
-
#top ⇒ Object
Returns the value of attribute top.
Class Method Summary collapse
Instance Method Summary collapse
- #==(value) ⇒ Object
- #bottom_left ⇒ Object
- #bottom_right ⇒ Object
-
#contains?(point) ⇒ Boolean
Does this bounds contain the following point?.
- #dimensions ⇒ Object
-
#initialize(params = {}) ⇒ RectangleBounds
constructor
Create a bounds with bounds.
-
#intersect?(b) ⇒ Boolean
Does this rectanglular bounds intersect with another rectanglular bounds?.
- #shift(point) ⇒ Object
- #to_s ⇒ Object
- #top_left ⇒ Object
- #top_right ⇒ Object
Methods included from CalculationValidations
#*, #+, #-, #calculate, #check_calculation_requirements
Constructor Details
#initialize(params = {}) ⇒ RectangleBounds
Create a bounds with bounds.
19 20 21 22 23 24 |
# File 'lib/metro/units/rectangle_bounds.rb', line 19 def initialize(params = {}) @left = params[:left].to_f @top = params[:top].to_f @right = params[:right].to_f @bottom = params[:bottom].to_f end |
Instance Attribute Details
#bottom ⇒ Object
Returns the value of attribute bottom.
10 11 12 |
# File 'lib/metro/units/rectangle_bounds.rb', line 10 def bottom @bottom end |
#left ⇒ Object
Returns the value of attribute left.
10 11 12 |
# File 'lib/metro/units/rectangle_bounds.rb', line 10 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
10 11 12 |
# File 'lib/metro/units/rectangle_bounds.rb', line 10 def right @right end |
#top ⇒ Object
Returns the value of attribute top.
10 11 12 |
# File 'lib/metro/units/rectangle_bounds.rb', line 10 def top @top end |
Class Method Details
.none ⇒ Object
12 13 14 |
# File 'lib/metro/units/rectangle_bounds.rb', line 12 def self.none new left: 0, right: 0, top: 0, bottom: 0 end |
Instance Method Details
#==(value) ⇒ Object
53 54 55 56 |
# File 'lib/metro/units/rectangle_bounds.rb', line 53 def ==(value) check_calculation_requirements(value) left == value.left and right == value.right and top == value.top and bottom == value.bottom end |
#bottom_left ⇒ Object
45 46 47 |
# File 'lib/metro/units/rectangle_bounds.rb', line 45 def bottom_left Point.at(left,bottom) end |
#bottom_right ⇒ Object
41 42 43 |
# File 'lib/metro/units/rectangle_bounds.rb', line 41 def bottom_right Point.at(right,bottom) end |
#contains?(point) ⇒ Boolean
Does this bounds contain the following point?
61 62 63 |
# File 'lib/metro/units/rectangle_bounds.rb', line 61 def contains?(point) point.x > left and point.x < right and point.y > top and point.y < bottom end |
#dimensions ⇒ Object
49 50 51 |
# File 'lib/metro/units/rectangle_bounds.rb', line 49 def dimensions Dimensions.of (right - left), (bottom - top) end |
#intersect?(b) ⇒ Boolean
Does this rectanglular bounds intersect with another rectanglular bounds?
68 69 70 |
# File 'lib/metro/units/rectangle_bounds.rb', line 68 def intersect?(b) not(b.left > right or b.right < left or b.top > bottom or b.bottom < top) end |
#shift(point) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/metro/units/rectangle_bounds.rb', line 26 def shift(point) self.left = self.left + point.x self.right = self.right + point.x self.top = self.top + point.y self.bottom = self.bottom + point.y end |
#to_s ⇒ Object
72 73 74 |
# File 'lib/metro/units/rectangle_bounds.rb', line 72 def to_s "(#{left},#{top}) to (#{right},#{bottom})" end |