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

Axis-aligned ellipse in 2D with center and semi-axes. More...

Public Member Functions

constexpr Ellipse () noexcept=default
 Default constructor.
constexpr Ellipse (const math::Vector2< T > &center, const math::Vector2< T > &radiuses) noexcept
 Constructs an ellipse with the given center and semi-axes.
constexpr T area () const noexcept
 Returns the area (π × radiuses.x × radiuses.y).
constexpr void reset () noexcept
 Puts the ellipse in reset state (center zero, radiuses zero).
constexpr bool isReset () const noexcept
 Returns true if the ellipse is in reset state (center zero, radiuses zero).
constexpr bool isValid () const noexcept
 Returns true if the ellipse has valid state (both semi-axes positive).
constexpr bool isContain (const math::Vector2< T > &vector) const noexcept
 Returns true if vector lies inside or on the ellipse.

Public Attributes

math::Vector2< T > center
 Center of the ellipse.
math::Vector2< T > radiuses
 Semi-axes of the ellipse (radiuses.x along x, radiuses.y along y).

Detailed Description

template<EllipseComponent T>
class toy::geometry::Ellipse< T >

Axis-aligned ellipse in 2D with center and semi-axes.

Represents an ellipse by center (toy::math::Vector2) and radiuses (semi-axes: radiuses.x along x, radiuses.y along y). Default-constructed ellipse is in reset state; use reset() to clear or construct with (center, radiuses) for a valid ellipse. operator== compares center and radiuses (tolerance-based for float, exact for fixed-point).

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

Key Features

  • Center and semi-axes: center and radiuses are public; radiuses.x and radiuses.y must be positive for a valid ellipse.
  • Reset state: reset() sets center and radiuses to zero; isReset() detects it.
  • Validity: isValid() is true when both radiuses.x and radiuses.y are > 0; constructor asserts in debug.
  • Containment: isContain() tests whether a point lies inside or on the ellipse using the normalized equation $ (x/a)^2 + (y/b)^2 \le 1 $.
  • Constexpr: All operations are constexpr and noexcept.

Usage Example

#include "geometry.hpp"
auto a = e.area();
bool inside = e.isContain(toy::math::Vector2(3.0f, 2.0f));
Axis-aligned ellipse in 2D with center and semi-axes.
Definition ellipse.hpp:97
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, radiuses) requires both radiuses.x and radiuses.y > 0 (assert in debug).
  • Exception safety: All operations are noexcept.
See also
EllipseComponent
toy::math::Vector2

Constructor & Destructor Documentation

◆ Ellipse() [1/2]

template<EllipseComponent T>
toy::geometry::Ellipse< T >::Ellipse ( )
constexprdefaultnoexcept

Default constructor.

◆ Ellipse() [2/2]

template<EllipseComponent T>
toy::geometry::Ellipse< T >::Ellipse ( const math::Vector2< T > & center,
const math::Vector2< T > & radiuses )
constexprnoexcept

Constructs an ellipse with the given center and semi-axes.

Parameters
centerCenter of the ellipse.
radiusesSemi-axes; both components must be > 0 (asserted in debug).
Precondition
radiuses.x > 0 and radiuses.y > 0.

Member Function Documentation

◆ area()

template<EllipseComponent T>
T toy::geometry::Ellipse< T >::area ( ) const
nodiscardconstexprnoexcept

Returns the area (π × radiuses.x × radiuses.y).

Returns
Area of the ellipse.

◆ isContain()

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

Returns true if vector lies inside or on the ellipse.

Uses the normalized ellipse equation: $ ((x-c_x)/a)^2 + ((y-c_y)/b)^2 \le 1 $ where center is $ (c_x, c_y) $ and radiuses is $ (a, b) $.

Parameters
vectorPoint to test.
Returns
true when the point satisfies the ellipse inequality.

◆ isReset()

template<EllipseComponent T>
bool toy::geometry::Ellipse< T >::isReset ( ) const
nodiscardconstexprnoexcept

Returns true if the ellipse is in reset state (center zero, radiuses zero).

Returns
true when center and radiuses are both zero.

◆ isValid()

template<EllipseComponent T>
bool toy::geometry::Ellipse< T >::isValid ( ) const
nodiscardconstexprnoexcept

Returns true if the ellipse has valid state (both semi-axes positive).

Returns
true when radiuses.x > 0 and radiuses.y > 0.

◆ reset()

template<EllipseComponent T>
void toy::geometry::Ellipse< T >::reset ( )
constexprnoexcept

Puts the ellipse in reset state (center zero, radiuses zero).

Postcondition
isReset() is true.

Member Data Documentation

◆ center

template<EllipseComponent T>
math::Vector2<T> toy::geometry::Ellipse< T >::center

Center of the ellipse.

◆ radiuses

template<EllipseComponent T>
math::Vector2<T> toy::geometry::Ellipse< T >::radiuses

Semi-axes of the ellipse (radiuses.x along x, radiuses.y along y).


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