class Qrio::Region
a rectangular matrix of bits
Attributes
orientation[R]
x1[R]
x2[R]
y1[R]
y2[R]
Public Class Methods
new(x1, y1, x2, y2)
click to toggle source
# File lib/qrio/region.rb, line 6 def initialize(x1, y1, x2, y2) @x1 = x1 @y1 = y1 @x2 = x2 @y2 = y2 set_orientation end
Public Instance Methods
==(other)
click to toggle source
# File lib/qrio/region.rb, line 48 def ==(other) to_s == other.to_s end
bottom()
click to toggle source
# File lib/qrio/region.rb, line 18 def bottom; y2; end
bottom_right()
click to toggle source
# File lib/qrio/region.rb, line 24 def bottom_right [x2, y2] end
center()
click to toggle source
# File lib/qrio/region.rb, line 60 def center [left + width / 2, top + height / 2] end
eql?(other)
click to toggle source
# File lib/qrio/region.rb, line 44 def eql?(other) self == other end
hash()
click to toggle source
# File lib/qrio/region.rb, line 40 def hash to_s.hash end
height()
click to toggle source
# File lib/qrio/region.rb, line 56 def height y2 - y1 + 1 end
horizontal?()
click to toggle source
# File lib/qrio/region.rb, line 64 def horizontal?; orientation == :horizontal; end
left()
click to toggle source
# File lib/qrio/region.rb, line 15 def left; x1; end
orientation_matches?(other)
click to toggle source
# File lib/qrio/region.rb, line 67 def orientation_matches?(other) orientation == other.orientation end
right()
click to toggle source
# File lib/qrio/region.rb, line 16 def right; x2; end
rotate(mw, mh)
click to toggle source
return a new region that would be the result of rotating a matrix of width x height containing this region
# 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()
click to toggle source
# File lib/qrio/region.rb, line 28 def to_coordinates [top_left, bottom_right].flatten end
to_point_size()
click to toggle source
# File lib/qrio/region.rb, line 32 def to_point_size [top_left, width, height].flatten end
to_s()
click to toggle source
# File lib/qrio/region.rb, line 36 def to_s "R[#{ to_coordinates.join(',') }]" end
top()
click to toggle source
# File lib/qrio/region.rb, line 17 def top; y1; end
top_left()
click to toggle source
# File lib/qrio/region.rb, line 20 def top_left [x1, y1] end
translate(xoffset, yoffset)
click to toggle source
# 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)
click to toggle source
# 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?()
click to toggle source
# File lib/qrio/region.rb, line 65 def vertical?; orientation == :vertical; end
width()
click to toggle source
# File lib/qrio/region.rb, line 52 def width x2 - x1 + 1 end
Private Instance Methods
set_orientation()
click to toggle source
# File lib/qrio/region.rb, line 102 def set_orientation @orientation = case when width > height :horizontal when height > width :vertical else :square end end