ToyGine2 26.2.0
Game Engine for retro consoles
Loading...
Searching...
No Matches
toy::geometry::Circle< T > Class Template Reference

Circle in 2D with center and radius. More...

Collaboration diagram for toy::geometry::Circle< T >:

Public Member Functions

constexpr Circle () noexcept
 Default constructor.
constexpr Circle (const math::Vector2< T > &center, const T &radius) noexcept
 Constructs a circle with the given center and radius.
constexpr T area () const noexcept
 Returns the area (π * radius²).
constexpr void reset () noexcept
 Puts the circle in reset state (center zero, radius zero).
constexpr bool isReset () const noexcept
 Returns true if the circle is in reset state (center zero, radius zero).
constexpr bool isValid () const noexcept
 Returns true if the circle has valid state (radius > 0).
constexpr bool isContain (const math::Vector2< T > &vector) const noexcept
 Returns true if vector lies inside or on the circle.

Public Attributes

math::Vector2< T > center
 Center of the circle.
radius
 Radius of the circle.

Detailed Description

template<CircleComponent T>
class toy::geometry::Circle< T >

Circle in 2D with center and radius.

Represents a circle by center (toy::math::Vector2) and radius. Default-constructed circle is in reset state; use reset() to clear or construct with (center, radius) for a valid circle. operator== compares center and radius (tolerance-based for float, exact for fixed-point).

Template Parameters
TComponent type; must satisfy toy::geometry::CircleComponent.

Key Features

  • Center and radius: center and radius are public; T is floating-point or fixed-point.
  • Reset state: reset() sets center to zero and radius to zero; isReset() detects it.
  • Validity: isValid() is true when radius > 0; constructor asserts radius > 0 in debug.
  • Containment: isContain() tests whether a point lies inside or on the circle (squared distance).
  • Constexpr: All operations are constexpr and noexcept.

Usage Example

#include "geometry.hpp"
auto a = c.area();
bool inside = c.isContain(toy::math::Vector2(5.0f, 0.0f));
Circle in 2D with center and radius.
Definition circle.hpp:92
2D vector with floating-point or fixed-point components for positions, movement, and physics.
Definition vector2.hpp:96
Umbrella header for the geometry module.

Performance Characteristics

Operations are O(1). No allocations.

Safety Guarantees

  • Preconditions: Constructor (center, radius) requires radius > 0 (assert in debug).
  • Exception safety: All operations are noexcept.
See also
CircleComponent
toy::math::Vector2

Constructor & Destructor Documentation

◆ Circle() [1/2]

template<CircleComponent T>
toy::geometry::Circle< T >::Circle ( )
constexprnoexcept

Default constructor.

◆ Circle() [2/2]

template<CircleComponent T>
toy::geometry::Circle< T >::Circle ( const math::Vector2< T > & center,
const T & radius )
constexprnoexcept

Constructs a circle with the given center and radius.

Parameters
centerCenter of the circle.
radiusRadius; must be > 0 (asserted in debug).
Precondition
radius > 0 (circle must be valid).

Member Function Documentation

◆ area()

template<CircleComponent T>
T toy::geometry::Circle< T >::area ( ) const
nodiscardconstexprnoexcept

Returns the area (π * radius²).

Returns
Area of the circle.

◆ isContain()

template<CircleComponent T>
bool toy::geometry::Circle< T >::isContain ( const math::Vector2< T > & vector) const
nodiscardconstexprnoexcept

Returns true if vector lies inside or on the circle.

Parameters
vectorPoint to test.
Returns
true when squared distance from vector to center is <= radius².

◆ isReset()

template<CircleComponent T>
bool toy::geometry::Circle< T >::isReset ( ) const
nodiscardconstexprnoexcept

Returns true if the circle is in reset state (center zero, radius zero).

Returns
true when center is zero and radius is zero.

◆ isValid()

template<CircleComponent T>
bool toy::geometry::Circle< T >::isValid ( ) const
nodiscardconstexprnoexcept

Returns true if the circle has valid state (radius > 0).

Returns
true when radius > 0.

◆ reset()

template<CircleComponent T>
void toy::geometry::Circle< T >::reset ( )
constexprnoexcept

Puts the circle in reset state (center zero, radius zero).

Postcondition
isReset() is true.

Member Data Documentation

◆ center

template<CircleComponent T>
math::Vector2<T> toy::geometry::Circle< T >::center

Center of the circle.

◆ radius

template<CircleComponent T>
T toy::geometry::Circle< T >::radius

Radius of the circle.


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