Class: CGRect
- Inherits:
-
Object
- Object
- CGRect
- Defined in:
- lib/project/cg_rect.rb
Class Method Summary collapse
-
.golden_section(options) ⇒ CGRect
The new object.
Instance Method Summary collapse
-
#golden_section(direction = :both, exp = 1) ⇒ CGRect
direction [Symbol] :width, :height, or :both, the dfeault.
-
#golden_split(direction, greater = :first) ⇒ Array
Splits a rectangle into two, with the proportion of the golden section.
Class Method Details
.golden_section(options) ⇒ CGRect
Returns the new object.
9 10 11 |
# File 'lib/project/cg_rect.rb', line 9 def self.golden_section() Golden_Sections::handler(Golden_Sections::CGRect_relations, , &Golden_Sections::CGRect_proc) end |
Instance Method Details
#golden_section(direction = :both, exp = 1) ⇒ CGRect
direction [Symbol] :width, :height, or :both, the dfeault
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/project/cg_rect.rb', line 18 def golden_section(direction=:both, exp=1) rect=self.dup fixed=false if direction==:width||direction==:both rect.width=rect.width.golden_section(exp) fixed=true end if direction==:height||direction==:both rect.height=rect.height.golden_section(exp) fixed=true end raise "CGRect#golden_section: unknown direction: #{direction}" unless fixed rect end |
#golden_split(direction, greater = :first) ⇒ Array
Splits a rectangle into two, with the proportion of the golden section
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/project/cg_rect.rb', line 37 def golden_split(direction, greater=:first) raise "Golden_Section#golden_split: unknown direction #{direction}" unless [:width, :height].member?(direction) raise "Golden_Section.golden_split: Unknown greater section #{greater}" unless [:first, :last].member?(greater) if greater==:first exp=1 else exp=2 end rect1=self.golden_section(direction,exp) if greater==:first exp=1 else exp=-1 end if direction==:width rect2=rect1.beside.width(rect1.width.golden_section(exp)) else rect2=rect1.below.height(rect1.height.golden_section(exp)) end [rect1,rect2] end |