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)
-
- (Object) height
readonly
Returns the value of attribute height.
-
- (Object) options
inherited
from BasicShape
Returns the value of attribute options.
-
- (Object) width
readonly
Returns the value of attribute width.
Instance Method Summary (collapse)
-
- (Any) [](x, y)
included
from Mixins::At
Set the x, y coordinates of the shape.
-
- (Coords) at
included
from Mixins::At
Get the x, y coordinates of the shape.
-
- (Any) at=(at)
included
from Mixins::At
Set the x, y coordinates of the shape directly.
-
- (Rect) initialize(width, height, **options)
constructor
Create a rectangle with specified width and height.
-
- (Any) move(x, y)
included
from Mixins::At
Move the shape relatively.
-
- (Object) to_path
Convert the shape to a path.
-
- (Object) to_svg
Export the shape to an svg string.
Constructor Details
- (Rect) initialize(width, height, **options)
Create a rectangle with specified width and height.
18 19 20 21 22 23 |
# File 'lib/vector_salad/standard_shapes/rect.rb', line 18 def initialize(width, height, **) @width, @height = width, height @options = @x, @y = 0, 0 self end |
Instance Attribute Details
- (Object) height (readonly)
Returns the value of attribute height
11 12 13 |
# File 'lib/vector_salad/standard_shapes/rect.rb', line 11 def height @height end |
- (Object) options Originally defined in class BasicShape
Returns the value of attribute options
- (Object) width (readonly)
Returns the value of attribute width
11 12 13 |
# File 'lib/vector_salad/standard_shapes/rect.rb', line 11 def width @width end |
Instance Method Details
- (Any) [](x, y) Originally defined in module Mixins::At
Set the x, y coordinates of the shape.
- (Coords) at Originally defined in module Mixins::At
Get the x, y coordinates of the shape.
- (Any) at=(at) Originally defined in module Mixins::At
Set the x, y coordinates of the shape directly.
- (Any) move(x, y) Originally defined in module Mixins::At
Move the shape relatively.
- (Object) to_path
Convert the shape to a path
26 27 28 29 30 31 32 33 34 |
# File 'lib/vector_salad/standard_shapes/rect.rb', line 26 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 |
- (Object) to_svg
Export the shape to an svg string
121 122 123 124 125 126 |
# File 'lib/vector_salad/exporters/svg_exporter.rb', line 121 def to_svg svg = "<rect x=\"#{at[0]}\" y=\"#{at[1]}\"" svg << " width=\"#{width}\" height=\"#{height}\"" svg << Exporters::SvgExporter.(@options) svg << "/>" end |