Loading...
Searching...
No Matches

A rectangle defined by width and height. More...

#include <shapes.hpp>

Inheritance diagram for geometry::Rectangle:
[legend]
Collaboration diagram for geometry::Rectangle:
[legend]

Public Member Functions

 Rectangle (double width, double height)
 Construct a rectangle.
 
double area () const override
 Compute the area of the shape.
 
double height () const
 Get the height.
 
std::string name () const override
 Return the human-readable name of the shape.
 
double perimeter () const override
 Compute the perimeter of the shape.
 
double width () const
 Get the width.
 
- Public Member Functions inherited from geometry::Shape
virtual ~Shape ()=default
 Virtual destructor for safe polymorphic deletion.
 
std::string describe () const
 Pretty-print shape information.
 

Protected Attributes

double height_
 The rectangle's height.
 
double width_
 The rectangle's width.
 

Additional Inherited Members

- Static Public Member Functions inherited from geometry::Shape
static int instance_count ()
 Get the total count of Shape instances created.
 
- Protected Member Functions inherited from geometry::Shape
 Shape ()
 Increment the instance counter.
 

Detailed Description

A rectangle defined by width and height.

\[ A = w \times h, \qquad P = 2(w + h) \]

See also
Square (a special case where \(w = h\))

Definition at line 138 of file shapes.hpp.

Constructor & Destructor Documentation

◆ Rectangle()

geometry::Rectangle::Rectangle ( double width,
double height )
inline

Construct a rectangle.

Parameters
widthThe width (must be positive).
heightThe height (must be positive).

Definition at line 145 of file shapes.hpp.

double height() const
Get the height.
Definition shapes.hpp:160
double width() const
Get the width.
Definition shapes.hpp:158
double height_
The rectangle's height.
Definition shapes.hpp:164
double width_
The rectangle's width.
Definition shapes.hpp:163

References height(), height_, width(), and width_.

Referenced by geometry::Square::Square().

Member Function Documentation

◆ area()

double geometry::Rectangle::area ( ) const
inlinenodiscardoverridevirtual

Compute the area of the shape.

Returns
The area in square units.

Implements geometry::Shape.

Definition at line 147 of file shapes.hpp.

147 {
148 return width_ * height_;
149 }

References height_, and width_.

◆ height()

double geometry::Rectangle::height ( ) const
inlinenodiscard

Get the height.

Definition at line 160 of file shapes.hpp.

160{ return height_; }

References height_.

Referenced by Rectangle().

◆ name()

std::string geometry::Rectangle::name ( ) const
inlinenodiscardoverridevirtual

Return the human-readable name of the shape.

Returns
A string like "Circle", "Rectangle", etc.

Implements geometry::Shape.

Reimplemented in geometry::Square.

Definition at line 155 of file shapes.hpp.

155{ return "Rectangle"; }

◆ perimeter()

double geometry::Rectangle::perimeter ( ) const
inlinenodiscardoverridevirtual

Compute the perimeter of the shape.

Returns
The perimeter in linear units.

Implements geometry::Shape.

Definition at line 151 of file shapes.hpp.

151 {
152 return 2.0 * (width_ + height_);
153 }

References height_, and width_.

◆ width()

double geometry::Rectangle::width ( ) const
inlinenodiscard

Get the width.

Definition at line 158 of file shapes.hpp.

158{ return width_; }

References width_.

Referenced by Rectangle().

Member Data Documentation

◆ height_

double geometry::Rectangle::height_
protected

The rectangle's height.

Definition at line 164 of file shapes.hpp.

Referenced by Rectangle(), area(), height(), and perimeter().

◆ width_

double geometry::Rectangle::width_
protected

The rectangle's width.

Definition at line 163 of file shapes.hpp.

Referenced by Rectangle(), area(), perimeter(), geometry::Square::side(), and width().


The documentation for this class was generated from the following file: