class TheFox::TermKit::Rect

A composition of the Point class (`@origin` attribute) and the Size class (`@size` attribute).

Attributes

origin[R]

Point instance.

size[R]

Size instance.

x_range[R]
y_range[R]

Public Class Methods

new(x = nil, y = nil, width = nil, height = nil) click to toggle source
# File lib/termkit/misc/rect.rb, line 18
def initialize(x = nil, y = nil, width = nil, height = nil)
        @origin = Point.new(x, y)
        @size = Size.new(width, height)
        set_x_range
        set_y_range
end

Public Instance Methods

has_default_values?() click to toggle source
# File lib/termkit/misc/rect.rb, line 69
def has_default_values?
        @origin.x.nil? && @origin.y.nil? && @size.width.nil? && @size.height.nil?
end
height() click to toggle source
# File lib/termkit/misc/rect.rb, line 65
def height
        @size.height
end
inspect() click to toggle source
# File lib/termkit/misc/rect.rb, line 93
def inspect
        x_s = x.nil? ? 'NIL' : x
        y_s = y.nil? ? 'NIL' : y
        
        w_s = width.nil? ? 'NIL' : width
        h_s = height.nil? ? 'NIL' : height
        
        "#<Rect x=#{x_s} y=#{y_s} w=#{w_s} h=#{h_s}>"
end
origin=(origin) click to toggle source
# File lib/termkit/misc/rect.rb, line 25
def origin=(origin)
        @origin = origin
        set_x_range
        set_y_range
end
size=(size) click to toggle source
# File lib/termkit/misc/rect.rb, line 31
def size=(size)
        @size = size
        set_x_range
        set_y_range
end
to_points() click to toggle source
# File lib/termkit/misc/rect.rb, line 73
def to_points
        points = []
        @x_range.each do |x_pos|
                @y_range.each do |y_pos|
                        points << Point.new(x_pos, y_pos)
                end
        end
        points
end
to_s() click to toggle source
# File lib/termkit/misc/rect.rb, line 83
def to_s
        x_s = x.nil? ? 'NIL' : x
        y_s = y.nil? ? 'NIL' : y
        
        w_s = width.nil? ? 'NIL' : width
        h_s = height.nil? ? 'NIL' : height
        
        "#{x_s}:#{y_s}[#{w_s}:#{h_s}]"
end
width() click to toggle source
# File lib/termkit/misc/rect.rb, line 61
def width
        @size.width
end
x() click to toggle source
# File lib/termkit/misc/rect.rb, line 37
def x
        @origin.x
end
x_max() click to toggle source
# File lib/termkit/misc/rect.rb, line 41
def x_max
        if !@origin.x.nil? && !@size.width.nil?
                @origin.x + @size.width - 1
        else
                -1
        end
end
y() click to toggle source
# File lib/termkit/misc/rect.rb, line 49
def y
        @origin.y
end
y_max() click to toggle source
# File lib/termkit/misc/rect.rb, line 53
def y_max
        if !@origin.y.nil? && !@size.height.nil?
                @origin.y + @size.height - 1
        else
                -1
        end
end

Private Instance Methods

set_x_range() click to toggle source
# File lib/termkit/misc/rect.rb, line 105
def set_x_range
        @x_range = Range.new(@origin.x.nil? ? 0: @origin.x, x_max)
end
set_y_range() click to toggle source
# File lib/termkit/misc/rect.rb, line 109
def set_y_range
        @y_range = Range.new(@origin.y.nil? ? 0: @origin.y, y_max)
end