Module: Rectangle

Includes:
Dimensions
Defined in:
tomes/spells/geometry/rectangle.rb

Overview

A module for giving an object the properties of a rectangle.

Instance Attribute Summary

Attributes included from Size

#height, #width

Attributes included from Location

#x, #y

Instance Method Summary collapse

Methods included from Dimensions

#change_dimensions, #dimensions, #rect

Methods included from Center

#horizontal_center, #true_center, #vertical_center

Methods included from Apex

#apex, #apex_x, #apex_y

Methods included from Size

#adjust_size, #size, #size=

Methods included from Location

#adjust_location, #location, #location=

Instance Method Details

#areaInteger

Calculates the area of this rectangle.

Returns:

  • (Integer)


17
18
19
# File 'tomes/spells/geometry/rectangle.rb', line 17

def area
  width * height
end

#hypotenuseInteger

Calculates the hypotenuse of this rectangle’s diagonal.

Returns:

  • (Integer)


23
24
25
# File 'tomes/spells/geometry/rectangle.rb', line 23

def hypotenuse
  Math.sqrt((width**2) + (height**2)).round(0o2)
end

#perimeterInteger

Calculates the perimeter of this rectangle.

Returns:

  • (Integer)


11
12
13
# File 'tomes/spells/geometry/rectangle.rb', line 11

def perimeter
  (width * 2) + (height * 2)
end