Class: VectorSalad::StandardShapes::Rect
- Inherits:
-
BasicShape
- Object
- BasicShape
- VectorSalad::StandardShapes::Rect
- Includes:
- Mixins::At
- Defined in:
- lib/vector_salad/standard_shapes/rect.rb,
lib/vector_salad/exporters/svg_exporter.rb
Overview
and Square subclass
Direct Known Subclasses
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Attributes inherited from BasicShape
Instance Method Summary collapse
-
#initialize(width, height, **options) ⇒ Rect
constructor
A new instance of Rect.
-
#to_path ⇒ Object
Convert the shape to a path.
-
#to_svg ⇒ Object
Export the shape to an svg string.
Methods included from Mixins::At
Methods inherited from BasicShape
#flip, #flip_x, #flip_y, #jitter, #move, #rotate, #scale, #to_a, #to_bezier_path, #to_cubic_path, #to_multi_path, #to_simple_path
Constructor Details
#initialize(width, height, **options) ⇒ Rect
Returns a new instance of Rect.
17 18 19 20 21 22 |
# File 'lib/vector_salad/standard_shapes/rect.rb', line 17 def initialize(width, height, **) @width, @height = width, height @options = @x, @y = 0, 0 self end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
10 11 12 |
# File 'lib/vector_salad/standard_shapes/rect.rb', line 10 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
10 11 12 |
# File 'lib/vector_salad/standard_shapes/rect.rb', line 10 def width @width end |
Instance Method Details
#to_path ⇒ Object
Convert the shape to a path
25 26 27 28 29 30 31 32 33 |
# File 'lib/vector_salad/standard_shapes/rect.rb', line 25 def to_path Path.new( N.n(@x, @y), N.n(@x, @y + @height), N.n(@x + @width, @y + @height), N.n(@x + @width, @y), **@options ) end |
#to_svg ⇒ Object
Export the shape to an svg string
122 123 124 125 126 127 |
# File 'lib/vector_salad/exporters/svg_exporter.rb', line 122 def to_svg svg = "<rect x=\"#{at[0]}\" y=\"#{at[1]}\"" svg << " width=\"#{width}\" height=\"#{height}\"" svg << VectorSalad::Exporters::SvgExporter.(@options) svg << "/>" end |