๐ 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 (
intorfloat) - height (
intorfloat)
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 (
intorfloat)
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.