Module: Sevgi::Geometry::Operation::Align
- Defined in:
- lib/sevgi/geometry/operation/align.rb
Instance Method Summary collapse
- #align(element, other, alignment = :center) ⇒ Object
- #alignment(element, other, alignment = :center) ⇒ Object
- #applicable?(element) ⇒ Boolean
Instance Method Details
#align(element, other, alignment = :center) ⇒ Object
7 8 9 |
# File 'lib/sevgi/geometry/operation/align.rb', line 7 def align(element, other, alignment = :center) alignment(element, other, alignment).apply(element) end |
#alignment(element, other, alignment = :center) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sevgi/geometry/operation/align.rb', line 12 def alignment(element, other, alignment = :center) this, that = element.box, other.box case alignment when :center then Translation[(this.width - that.width) / 2.0, (this.height - that.height) / 2.0] when :left then Translation[this.ne.x - that.ne.x, 0] when :right then Translation[this.sw.x - that.sw.x, 0] when :top then Translation[0, this.ne.y - that.ne.y] when :bottom then Translation[0, this.sw.y - that.sw.y] else ArgumentError.("No such type of alignment: #{alignment}") end end |
#applicable?(element) ⇒ Boolean
26 27 28 |
# File 'lib/sevgi/geometry/operation/align.rb', line 26 def applicable?(element) Translation.applicable?(element) end |