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

Instance Attribute Summary collapse

Attributes inherited from BasicShape

#options

Instance Method Summary collapse

Methods included from Mixins::At

#[], #at, #move

Constructor Details

#initialize(width, height, **options) ⇒ Rect

Returns a new instance of Rect.



16
17
18
19
20
21
# File 'lib/vector_salad/standard_shapes/rect.rb', line 16

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.



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

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#to_pathObject



23
24
25
26
27
28
29
30
31
# File 'lib/vector_salad/standard_shapes/rect.rb', line 23

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



118
119
120
121
122
123
# File 'lib/vector_salad/exporters/svg_exporter.rb', line 118

def to_svg
  svg = "<rect x=\"#{at[0]}\" y=\"#{at[1]}\""
  svg << " width=\"#{width}\" height=\"#{height}\""
  svg << VectorSalad::Exporters::SvgExporter.options(@options)
  svg << '/>'
end