class DYI::Shape::Rectangle
The rectangle in the vector image @since 0.0.0
Public Class Methods
Create a new instance of Rectangle
. @param [Length] top a y-axis coordinate of the top @param [Length] right a x-axis coordinate of the right side @param [Length] bottom a y-axis coordinate of the bottom @param [Length] left a x-axis coordinate of the left side @option options [Painting] :painting painting status of the rectangle @option options [Length] :rx the x-axis radius of the ellipse for
rounded the rectangle
@option options [Length] :ry the y-axis radius of the ellipse for
rounded the rectangle
@return [Rectangle] a new instance of Rectangle
# File lib/dyi/shape/base.rb, line 495 def create_on_corner(top, right, bottom, left, options={}) left_top = Coordinate.new([left, right].min, [top, bottom].min) width = (Length.new(right) - Length.new(left)).abs height = (Length.new(bottom) - Length.new(top)).abs new(left_top, width, height, options) end
Create a new instance of Rectangle
. @param [Coordinate] left_top a coordinate of a corner of the rectangle @param [Length] width width of the rectangle @param [Length] heigth heigth of the rectangle @option options [Painting] :painting painting status of the shape @option options [Length] :rx the x-axis radius of the ellipse for
rounded the rectangle
@option options [Length] :ry the y-axis radius of the ellipse for
rounded the rectangle
@return [Rectangle] a new instance of Rectangle
# File lib/dyi/shape/base.rb, line 480 def create_on_width_height(left_top, width, height, options={}) new(left_top, width, height, options) end
@param [Coordinate] left_top a left-top coordinate of the rectangle @param [Length] width width of the rectangle @param [Length] heigth heigth of the rectangle @option options [Painting] :painting painting status of this shape @option options [Length] :rx the x-axis radius of the ellipse for
rounded the rectangle
@option options [Length] :ry the y-axis radius of the ellipse for
rounded the rectangle
@option options [String] :description the description of this shape @option options [String] :title the title of this shape
# File lib/dyi/shape/base.rb, line 418 def initialize(left_top, width, height, options={}) width = Length.new(width) height = Length.new(height) @lt_pt = Coordinate.new(left_top) @lt_pt += Coordinate.new(width, 0) if width < Length::ZERO @lt_pt += Coordinate.new(0, height) if height < Length::ZERO @width = width.abs @height = height.abs @attributes = init_attributes(options) end
Public Instance Methods
Returns a y-axis coordinate of the bottom of the rectangle. @return [Length] a y-axis coordinate of the bottom
# File lib/dyi/shape/base.rb, line 449 def bottom @lt_pt.y + height end
Returns a coordinate of the center of the rectangle. @return [Coordinate] a coordinate of the center
# File lib/dyi/shape/base.rb, line 455 def center @lt_pt + Coordinate.new(width.quo(2), height.quo(2)) end
Returns a x-axis coordinate of the left side of the rectangle. @return [Length] the x-axis coordinate of the left side
# File lib/dyi/shape/base.rb, line 431 def left @lt_pt.x end
Returns a x-axis coordinate of the right side of the rectangle. @return [Length] the x-axis coordinate of the right side
# File lib/dyi/shape/base.rb, line 437 def right @lt_pt.x + width end
Returns a y-axis coordinate of the top of the rectangle. @return [Length] a y-axis coordinate of the top
# File lib/dyi/shape/base.rb, line 443 def top @lt_pt.y end
Writes the shape on io object. @param [Formatter::Base] formatter an object that defines the image format @param [IO] io an io to be written
# File lib/dyi/shape/base.rb, line 462 def write_as(formatter, io=$>) formatter.write_rectangle(self, io, &(block_given? ? Proc.new : nil)) end