Class: VectorSalad::StandardShapes::Oval
- Inherits:
-
BasicShape
- Object
- BasicShape
- VectorSalad::StandardShapes::Oval
- Includes:
- Mixins::At
- Defined in:
- lib/vector_salad/standard_shapes/oval.rb,
lib/vector_salad/exporters/svg_exporter.rb
Overview
Oval shape.
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.
-
- (Oval) initialize(width, height, **options)
constructor
Create an oval.
-
- (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
- (Oval) initialize(width, height, **options)
Create an oval.
18 19 20 21 22 23 |
# File 'lib/vector_salad/standard_shapes/oval.rb', line 18 def initialize(width, height, **) @options = @width, @height = width, height @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/oval.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/oval.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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vector_salad/standard_shapes/oval.rb', line 26 def to_path # http://stackoverflow.com/a/13338311 # c = 4 * (Math.sqrt(2) - 1) / 3 # c = 0.5522847498307936 # # http://spencermortensen.com/articles/bezier-circle/ c = 0.551915024494 dw = c * @width dh = c * @height Path.new( N.n(@x + @width, @y), N.c(@x + @width, @y + dh), N.c(@x + dw, @y + @height), N.n(@x, @y + @height), N.c(@x - dw, @y + @height), N.c(@x - @width, @y + dh), N.n(@x - @width, @y), N.c(@x - @width, @y - dh), N.c(@x - dw, @y - @height), N.n(@x, @y - @height), N.c(@x + dw, @y - @height), N.c(@x + @width, @y - dh), N.n(@x + @width, @y), @options ) end |
- (Object) to_svg
Export the shape to an svg string
111 112 113 114 115 116 |
# File 'lib/vector_salad/exporters/svg_exporter.rb', line 111 def to_svg svg = "<ellipse cx=\"#{at[0]}\" cy=\"#{at[1]}\"" svg << " rx=\"#{width}\" ry=\"#{height}\"" svg << Exporters::SvgExporter.(@options) svg << "/>" end |