Class: Mahoujin::Graphics::Utilities::Rectangle

Inherits:
Object
  • Object
show all
Defined in:
lib/mahoujin/graphics/utilities/rectangle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left = 0, top = 0, right = 0, bottom = 0) ⇒ Rectangle

Returns a new instance of Rectangle


7
8
9
10
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 7

def initialize(left = 0, top = 0, right = 0, bottom = 0)
  @left, @top, @right, @bottom = left, top, right, bottom
  @centerline = @top + (@bottom - @top).fdiv(2)
end

Instance Attribute Details

#bottomObject

Returns the value of attribute bottom


5
6
7
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 5

def bottom
  @bottom
end

#centerlineObject

Returns the value of attribute centerline


5
6
7
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 5

def centerline
  @centerline
end

#leftObject

Returns the value of attribute left


5
6
7
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 5

def left
  @left
end

#rightObject

Returns the value of attribute right


5
6
7
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 5

def right
  @right
end

#topObject

Returns the value of attribute top


5
6
7
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 5

def top
  @top
end

Instance Method Details

#heightObject


25
26
27
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 25

def height
  @bottom - @top
end

#height=(height) ⇒ Object


29
30
31
32
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 29

def height=(height)
  @centerline = @top + height * (@centerline - @top).fdiv(@bottom - @top)
  @bottom = @top + height
end

#move_bottom(bottom) ⇒ Object


50
51
52
53
54
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 50

def move_bottom(bottom)
  @centerline = bottom + (@centerline - @bottom)
  @top = bottom + (@top - @bottom)
  @bottom = bottom
end

#move_left(left) ⇒ Object


34
35
36
37
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 34

def move_left(left)
  @right = left + (@right - @left)
  @left = left
end

#move_right(right) ⇒ Object


39
40
41
42
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 39

def move_right(right)
  @left = right + (@left - @right)
  @right = right
end

#move_top(top) ⇒ Object


44
45
46
47
48
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 44

def move_top(top)
  @centerline = top + (@centerline - @top)
  @bottom = top + (@bottom - @top)
  @top = top
end

#sync_with(rectangle) ⇒ Object


12
13
14
15
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 12

def sync_with(rectangle)
  @left, @top, @right, @bottom = rectangle.left, rectangle.top, rectangle.right, rectangle.bottom
  @centerline = rectangle.centerline
end

#widthObject


17
18
19
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 17

def width
  @right - @left
end

#width=(width) ⇒ Object


21
22
23
# File 'lib/mahoujin/graphics/utilities/rectangle.rb', line 21

def width=(width)
  @right = @left + width
end