Skip to content

๐Ÿ“š API Reference

This page provides detailed documentation for all classes and methods in the Polygon Area Calculator project.


๐ŸŸฆ Rectangle

The Rectangle class represents a simple rectangle defined by its width and height.

Constructor

Rectangle(width, height)

Parameters:

  • width (int or float)
  • height (int or float)

Methods

๐Ÿ”น set_width(width)

Sets a new width.

rect.set_width(10)

๐Ÿ”น set_height(height)

Sets a new height.

rect.set_height(5)

๐Ÿ”น get_area()

Returns the area of the rectangle.

width * height
rect.get_area()

๐Ÿ”น get_perimeter()

Returns the perimeter.

2 * width + 2 * height
rect.get_perimeter()

๐Ÿ”น get_diagonal()

Returns the diagonal length based on the Pythorean theorem.

(widthยฒ + heightยฒ) ** 0.5
rect.get_diagonal()

๐Ÿ”น get_picture()

Returns an ASCII-art representation of the rectangle using * characters.

  • If width or height is greater than 50, returns: Too big for picture.
print(rect.get_picture())

๐Ÿ”น get_amount_inside(shape)

Returns how many times another shape can fit inside the rectangle.

Measured using integer division:

(self.width // shape.width) * (self.height // shape.height)
rect.get_amount_inside(sq)

๐Ÿ”น __str__()

String representation of the rectangle:

Rectangle(width=10, height=5)

๐ŸŸฅ Square

The Square class is a subclass of Rectangle, where both width and height remain equal.

Constructor

Square(side)

Parameter:

  • side (int or float)

Methods

๐Ÿ”น set_side(side)

Sets both width and height to the same value.

sq.set_side(6)

๐Ÿ”น set_width(width) (overridden)

Ensures width and height remain equal.

๐Ÿ”น set_height(height) (overridden)

Ensures width and height remain equal.

๐Ÿ”น __str__()

String representation of a square:

Square(side=5)

๐Ÿงฑ Class Relationship Diagram

 Rectangle
    โ–ฒ
    โ”‚ (inherits)
    โ”‚
 Square

๐Ÿงฉ Notes

  • All geometric calculations return numeric values.
  • ASCII drawing uses * characters and line breaks.
  • Shape packing always uses integer division.

You may now continue to Examples or Usage for practical demonstrations.