Loading...
Searching...
No Matches
geometry::Circle Class Reference

A circle defined by its radius. More...

#include <shapes.hpp>

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

Public Member Functions

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

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 circle defined by its radius.

Area and perimeter are computed as:

\[ A = \pi r^2, \qquad P = 2\pi r \]

See also
Shape

Definition at line 103 of file shapes.hpp.

Constructor & Destructor Documentation

◆ Circle()

geometry::Circle::Circle ( double radius)
inlineexplicit

Construct a circle with the given radius.

Parameters
radiusThe radius (must be positive).
Precondition
\( r > 0 \)

Definition at line 110 of file shapes.hpp.

110: radius_(radius) {}
double radius() const
Get the radius.
Definition shapes.hpp:123

References radius().

Member Function Documentation

◆ area()

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

Compute the area of the shape.

Returns
The area in square units.

Implements geometry::Shape.

Definition at line 112 of file shapes.hpp.

112 {
113 return M_PI * radius_ * radius_;
114 }

◆ name()

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

Return the human-readable name of the shape.

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

Implements geometry::Shape.

Definition at line 120 of file shapes.hpp.

120{ return "Circle"; }

◆ perimeter()

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

Compute the perimeter of the shape.

Returns
The perimeter in linear units.

Implements geometry::Shape.

Definition at line 116 of file shapes.hpp.

116 {
117 return 2.0 * M_PI * radius_;
118 }

◆ radius()

double geometry::Circle::radius ( ) const
inlinenodiscard

Get the radius.

Definition at line 123 of file shapes.hpp.

123{ return radius_; }

Referenced by Circle().


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