Class: VectorSalad::StandardShapes::Polygon
- Inherits:
 - 
      BasicShape
      
        
- Object
 - BasicShape
 - VectorSalad::StandardShapes::Polygon
 
 - Includes:
 - Mixins::At
 - Defined in:
 - lib/vector_salad/standard_shapes/polygon.rb
 
Overview
Regular polygon shape.
Instance Attribute Summary (collapse)
- 
  
    
      - (Object) options 
    
    
  
  
    
      inherited
      from BasicShape
    
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute options.
 - 
  
    
      - (Object) sides 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute sides.
 
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.
 - 
  
    
      - (Polygon) initialize(sides, radius, **options) 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Create a regular polygon with a specified number of sides.
 - 
  
    
      - (Any) move(x, y) 
    
    
  
  
    
      included
      from Mixins::At
    
  
  
  
  
  
  
  
  
    
Move the shape relatively.
 - 
  
    
      - (Object) to_path 
    
    
  
  
  
  
  
  
  
  
  
    
Convert the shape to a path.
 
Constructor Details
- (Polygon) initialize(sides, radius, **options)
Create a regular polygon with a specified number of sides.
      18 19 20 21 22 23  | 
    
      # File 'lib/vector_salad/standard_shapes/polygon.rb', line 18 def initialize(sides, radius, **) @sides, @radius = sides, radius @options = @x, @y = 0, 0 self end  | 
  
Instance Attribute Details
- (Object) options Originally defined in class BasicShape
Returns the value of attribute options
- (Object) sides (readonly)
Returns the value of attribute sides
      11 12 13  | 
    
      # File 'lib/vector_salad/standard_shapes/polygon.rb', line 11 def sides @sides 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  | 
    
      # File 'lib/vector_salad/standard_shapes/polygon.rb', line 26 def to_path nodes = [] angle = 2 * Math::PI / @sides theta = angle / 2 + Math::PI / 2 @sides.times do |n| nodes[n] = [] nodes[n][0] = @radius * Math.cos(angle * n + theta) + @x nodes[n][1] = @radius * Math.sin(angle * n + theta) + @y end Path.new(*nodes, **@options) end  |