Class: VectorSalad::StandardShapes::Rect

Inherits:
BasicShape
  • Object
show all
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

Square

Instance Attribute Summary collapse

Attributes inherited from BasicShape

#options

Instance Method Summary collapse

Methods included from Mixins::At

#[], #at, #at=, #move

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, **options)
  @width, @height = width, height
  @options = options
  @x, @y = 0, 0
  self
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



10
11
12
# File 'lib/vector_salad/standard_shapes/rect.rb', line 10

def height
  @height
end

#widthObject (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_pathObject

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_svgObject

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(@options)
  svg << "/>"
end