Module: Sevgi::Geometry::Operation::Align

Defined in:
lib/sevgi/geometry/operation/align.rb

Instance Method Summary collapse

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sevgi/geometry/operation/align.rb', line 11

def alignment(element, other, alignment = :center)
  this, that = element.box, other.box

  case alignment
  when :center
    Translation[(this.width - that.width) / 2.0, (this.height - that.height) / 2.0]
  when :left
    Translation[this.ne.x - that.ne.x, 0]
  when :right
    Translation[this.sw.x - that.sw.x, 0]
  when :top
    Translation[0, this.ne.y - that.ne.y]
  when :bottom
    Translation[0, this.sw.y - that.sw.y]
  else
    ArgumentError.("No such type of alignment: #{alignment}")
  end
end

#applicable?(element) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/sevgi/geometry/operation/align.rb', line 30

def applicable?(element)
  Translation.applicable?(element)
end