Class: DYI::Shape::Rectangle
- Inherits:
-
Base
- Object
- Element
- GraphicalElement
- Base
- DYI::Shape::Rectangle
- Defined in:
- lib/dyi/shape/base.rb
Overview
The rectangle in the vector image
Direct Known Subclasses
Constant Summary
Constants inherited from GraphicalElement
GraphicalElement::CLASS_REGEXP
Constants inherited from Element
Instance Attribute Summary
Attributes inherited from Base
#anchor_href, #anchor_target, #attributes, #clipping, #parent
Attributes inherited from GraphicalElement
Attributes inherited from Element
Class Method Summary collapse
-
.create_on_corner(top, right, bottom, left, options = {}) ⇒ Rectangle
Create a new instance of Rectangle.
-
.create_on_width_height(left_top, width, height, options = {}) ⇒ Rectangle
Create a new instance of Rectangle.
Instance Method Summary collapse
-
#bottom ⇒ Length
Returns a y-axis coordinate of the bottom of the rectangle.
-
#center ⇒ Coordinate
Returns a coordinate of the center of the rectangle.
-
#initialize(left_top, width, height, options = {}) ⇒ Rectangle
constructor
A new instance of Rectangle.
-
#left ⇒ Length
Returns a x-axis coordinate of the left side of the rectangle.
-
#right ⇒ Length
Returns a x-axis coordinate of the right side of the rectangle.
-
#top ⇒ Length
Returns a y-axis coordinate of the top of the rectangle.
-
#write_as(formatter, io = $>) ⇒ Object
Writes the shape on io object.
Methods inherited from Base
#add_animation, #add_painting_animation, #add_transform_animation, #animate?, #animations, #clear_clipping, #draw_on, #has_marker?, #has_uri_reference?, #root_element?, #root_node?, #rotate, #scale, #set_clipping, #set_clipping_shapes, #set_event, #skew_x, #skew_y, #transform, #translate
Methods inherited from GraphicalElement
#add_css_class, #add_event_listener, #css_classes, #event_listeners, #event_target?, #remove_css_class, #remove_event_listener, #set_event, #to_reused_source
Methods inherited from Element
#canvas, #child_elements, #has_uri_reference?, #id, #id=, #include_external_file?, #inner_id
Constructor Details
#initialize(left_top, width, height, options = {}) ⇒ Rectangle
Returns a new instance of Rectangle.
419 420 421 422 423 424 425 426 427 428 |
# File 'lib/dyi/shape/base.rb', line 419 def initialize(left_top, width, height, ={}) 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() end |
Class Method Details
.create_on_corner(top, right, bottom, left, options = {}) ⇒ Rectangle
Create a new instance of Rectangle.
496 497 498 499 500 501 |
# File 'lib/dyi/shape/base.rb', line 496 def create_on_corner(top, right, bottom, left, ={}) 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, ) end |
.create_on_width_height(left_top, width, height, options = {}) ⇒ Rectangle
Create a new instance of Rectangle.
481 482 483 |
# File 'lib/dyi/shape/base.rb', line 481 def create_on_width_height(left_top, width, height, ={}) new(left_top, width, height, ) end |
Instance Method Details
#bottom ⇒ Length
Returns a y-axis coordinate of the bottom of the rectangle.
450 451 452 |
# File 'lib/dyi/shape/base.rb', line 450 def bottom @lt_pt.y + height end |
#center ⇒ Coordinate
Returns a coordinate of the center of the rectangle.
456 457 458 |
# File 'lib/dyi/shape/base.rb', line 456 def center @lt_pt + Coordinate.new(width.quo(2), height.quo(2)) end |
#left ⇒ Length
Returns a x-axis coordinate of the left side of the rectangle.
432 433 434 |
# File 'lib/dyi/shape/base.rb', line 432 def left @lt_pt.x end |
#right ⇒ Length
Returns a x-axis coordinate of the right side of the rectangle.
438 439 440 |
# File 'lib/dyi/shape/base.rb', line 438 def right @lt_pt.x + width end |
#top ⇒ Length
Returns a y-axis coordinate of the top of the rectangle.
444 445 446 |
# File 'lib/dyi/shape/base.rb', line 444 def top @lt_pt.y end |
#write_as(formatter, io = $>) ⇒ Object
Writes the shape on io object.
463 464 465 |
# File 'lib/dyi/shape/base.rb', line 463 def write_as(formatter, io=$>) formatter.write_rectangle(self, io, &(block_given? ? Proc.new : nil)) end |