Class: Wx::SF::LayoutCircle
- Inherits:
-
LayoutAlgorithm
- Object
- LayoutAlgorithm
- Wx::SF::LayoutCircle
- Defined in:
- lib/wx/shapes/auto_layout.rb
Overview
Class encapsulating algorithm which layouts all top-most shapes into circle registered under “Circle” name. The algorithm doesn’t optimize connection lines crossing.
Instance Attribute Summary collapse
-
#distance_ratio ⇒ Object
Get or set ratio in which calculated distance between shapes will be reduced.
Instance Method Summary collapse
-
#do_layout(shapes) ⇒ Object
Function performing the layout change.
-
#initialize ⇒ LayoutCircle
constructor
Constructor.
Methods inherited from LayoutAlgorithm
#get_bounding_box, #get_shapes_center, #get_shapes_extent, #get_top_left
Constructor Details
#initialize ⇒ LayoutCircle
Constructor.
75 76 77 |
# File 'lib/wx/shapes/auto_layout.rb', line 75 def initialize @distance_ratio = 1.0 end |
Instance Attribute Details
#distance_ratio ⇒ Object
Get or set ratio in which calculated distance between shapes will be reduced. Values less than 1 means that the distance will be smaller, values bigger than 1 means that the distance will be bigger.
82 83 84 |
# File 'lib/wx/shapes/auto_layout.rb', line 82 def distance_ratio @distance_ratio end |
Instance Method Details
#do_layout(shapes) ⇒ Object
Function performing the layout change.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/wx/shapes/auto_layout.rb', line 86 def do_layout(shapes) size_shapes = get_shapes_extent(shapes) center = get_shapes_center(shapes) # double x, y step = 360.0 / shapes.size degree = 0 rx = (size_shapes.x / 2) * @distance_ratio ry = (size_shapes.y / 2) * @distance_ratio shapes.each do |shape| x = center.x + Math.cos(degree * Math::PI / 180 ) * rx y = center.y + Math.sin( degree * Math::PI / 180 ) * ry degree += step shape.move_to(x, y) end end |