Class: Qrio::Region
- Inherits:
-
Object
- Object
- Qrio::Region
- Defined in:
- lib/qrio/region.rb
Overview
a rectangular matrix of bits
Direct Known Subclasses
Instance Attribute Summary collapse
-
#orientation ⇒ Object
readonly
Returns the value of attribute orientation.
-
#x1 ⇒ Object
readonly
Returns the value of attribute x1.
-
#x2 ⇒ Object
readonly
Returns the value of attribute x2.
-
#y1 ⇒ Object
readonly
Returns the value of attribute y1.
-
#y2 ⇒ Object
readonly
Returns the value of attribute y2.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #bottom ⇒ Object
- #bottom_right ⇒ Object
- #center ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #height ⇒ Object
- #horizontal? ⇒ Boolean
-
#initialize(x1, y1, x2, y2) ⇒ Region
constructor
A new instance of Region.
- #left ⇒ Object
- #orientation_matches?(other) ⇒ Boolean
- #right ⇒ Object
-
#rotate(mw, mh) ⇒ Object
return a new region that would be the result of rotating a matrix of width x height containing this region.
- #to_coordinates ⇒ Object
- #to_point_size ⇒ Object
- #to_s ⇒ Object
- #top ⇒ Object
- #top_left ⇒ Object
- #translate(xoffset, yoffset) ⇒ Object
- #union(other) ⇒ Object
- #vertical? ⇒ Boolean
- #width ⇒ Object
Constructor Details
#initialize(x1, y1, x2, y2) ⇒ Region
Returns a new instance of Region.
6 7 8 9 10 11 12 13 |
# File 'lib/qrio/region.rb', line 6 def initialize(x1, y1, x2, y2) @x1 = x1 @y1 = y1 @x2 = x2 @y2 = y2 set_orientation end |
Instance Attribute Details
#orientation ⇒ Object (readonly)
Returns the value of attribute orientation.
4 5 6 |
# File 'lib/qrio/region.rb', line 4 def orientation @orientation end |
#x1 ⇒ Object (readonly)
Returns the value of attribute x1.
4 5 6 |
# File 'lib/qrio/region.rb', line 4 def x1 @x1 end |
#x2 ⇒ Object (readonly)
Returns the value of attribute x2.
4 5 6 |
# File 'lib/qrio/region.rb', line 4 def x2 @x2 end |
#y1 ⇒ Object (readonly)
Returns the value of attribute y1.
4 5 6 |
# File 'lib/qrio/region.rb', line 4 def y1 @y1 end |
#y2 ⇒ Object (readonly)
Returns the value of attribute y2.
4 5 6 |
# File 'lib/qrio/region.rb', line 4 def y2 @y2 end |
Instance Method Details
#==(other) ⇒ Object
48 49 50 |
# File 'lib/qrio/region.rb', line 48 def ==(other) to_s == other.to_s end |
#bottom ⇒ Object
18 |
# File 'lib/qrio/region.rb', line 18 def bottom; y2; end |
#bottom_right ⇒ Object
24 25 26 |
# File 'lib/qrio/region.rb', line 24 def bottom_right [x2, y2] end |
#center ⇒ Object
60 61 62 |
# File 'lib/qrio/region.rb', line 60 def center [left + width / 2, top + height / 2] end |
#eql?(other) ⇒ Boolean
44 45 46 |
# File 'lib/qrio/region.rb', line 44 def eql?(other) self == other end |
#hash ⇒ Object
40 41 42 |
# File 'lib/qrio/region.rb', line 40 def hash to_s.hash end |
#height ⇒ Object
56 57 58 |
# File 'lib/qrio/region.rb', line 56 def height y2 - y1 + 1 end |
#horizontal? ⇒ Boolean
64 |
# File 'lib/qrio/region.rb', line 64 def horizontal?; orientation == :horizontal; end |
#left ⇒ Object
15 |
# File 'lib/qrio/region.rb', line 15 def left; x1; end |
#orientation_matches?(other) ⇒ Boolean
67 68 69 |
# File 'lib/qrio/region.rb', line 67 def orientation_matches?(other) orientation == other.orientation end |
#right ⇒ Object
16 |
# File 'lib/qrio/region.rb', line 16 def right; x2; end |
#rotate(mw, mh) ⇒ Object
return a new region that would be the result of rotating a matrix of width x height containing this region
91 92 93 94 95 96 97 98 |
# File 'lib/qrio/region.rb', line 91 def rotate(mw, mh) self.class.new( mh - bottom - 1, left, mh - top - 1, right ) end |
#to_coordinates ⇒ Object
28 29 30 |
# File 'lib/qrio/region.rb', line 28 def to_coordinates [top_left, bottom_right].flatten end |
#to_point_size ⇒ Object
32 33 34 |
# File 'lib/qrio/region.rb', line 32 def to_point_size [top_left, width, height].flatten end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/qrio/region.rb', line 36 def to_s "R[#{ to_coordinates.join(',') }]" end |
#top ⇒ Object
17 |
# File 'lib/qrio/region.rb', line 17 def top; y1; end |
#top_left ⇒ Object
20 21 22 |
# File 'lib/qrio/region.rb', line 20 def top_left [x1, y1] end |
#translate(xoffset, yoffset) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/qrio/region.rb', line 80 def translate(xoffset, yoffset) self.class.new( left - xoffset, top - yoffset, right - xoffset, bottom - yoffset ) end |
#union(other) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/qrio/region.rb', line 71 def union(other) self.class.new( [left, other.left].min, [top, other.top].min, [right, other.right].max, [bottom, other.bottom].max ) end |
#vertical? ⇒ Boolean
65 |
# File 'lib/qrio/region.rb', line 65 def vertical?; orientation == :vertical; end |
#width ⇒ Object
52 53 54 |
# File 'lib/qrio/region.rb', line 52 def width x2 - x1 + 1 end |