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

One-dimensional interval [start, end] over a numeric endpoint type. More...

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

Public Member Functions

constexpr Section () noexcept
 Default constructor.
constexpr Section (const T &min, const T &max) noexcept
 Constructs a section with the given bounds.
constexpr T midpoint () const noexcept
 Returns the midpoint of the interval.
constexpr T length () const noexcept
 Returns the length of the interval.
constexpr void reset () noexcept
 Puts the section in reset (empty) state.
constexpr void expand (const T &value) noexcept
 Extends the interval to include value if outside current bounds.
constexpr void expand (const Section< T > &section) noexcept
 Merges section into this interval (union of two intervals).
constexpr bool isReset () const noexcept
 Returns true if the section is in reset (empty) state.
constexpr bool isValid () const noexcept
 Returns true if the section represents a valid non-empty interval.
constexpr bool isContains (const T &value) const noexcept
 Returns true if value lies inside [start, end] (inclusive).

Public Attributes

start
 Lower bound of the interval.
end
 Upper bound of the interval.

Detailed Description

template<SectionEndpoint T>
class toy::geometry::Section< T >

One-dimensional interval [start, end] over a numeric endpoint type.

Represents a closed interval on a numeric type. Default-constructed section is in reset (empty) state: start > end, isValid() returns false. Use reset() to clear, or construct with (min, max) for a valid interval.

Template Parameters
TEndpoint type; must satisfy toy::geometry::SectionEndpoint (signed integral, floating-point, or fixed-point).

Key Features

  • Numeric endpoint only: T constrained by toy::geometry::SectionEndpoint (signed integral, floating-point, or fixed-point only; unsigned integral is not allowed).
  • Reset state: Empty interval represented by start > end; reset() restores it.
  • Expand: expand() extends bounds to include a value or another section (union).
  • Constexpr: All operations are constexpr and noexcept where applicable.

Usage Example

#include "geometry.hpp"
s.expand(5); // now [5, 20]
s.expand(toy::geometry::Section<int>(25, 30)); // now [5, 30]
One-dimensional interval [start, end] over a numeric endpoint type.
Definition section.hpp:95
Umbrella header for the geometry module.

Performance Characteristics

Operations**: O(1). No allocations.

Safety Guarantees

See also
operator==(), operator!=()

Constructor & Destructor Documentation

◆ Section() [1/2]

template<SectionEndpoint T>
toy::geometry::Section< T >::Section ( )
constexprnoexcept

Default constructor.

◆ Section() [2/2]

template<SectionEndpoint T>
toy::geometry::Section< T >::Section ( const T & min,
const T & max )
constexprnoexcept

Constructs a section with the given bounds.

Parameters
minLower bound.
maxUpper bound.

Member Function Documentation

◆ expand() [1/2]

template<SectionEndpoint T>
void toy::geometry::Section< T >::expand ( const Section< T > & section)
constexprnoexcept

Merges section into this interval (union of two intervals).

Precondition
section.isValid() is true.
Parameters
sectionSection to merge.
Postcondition
This section contains the union of the previous interval and section.

◆ expand() [2/2]

template<SectionEndpoint T>
void toy::geometry::Section< T >::expand ( const T & value)
constexprnoexcept

Extends the interval to include value if outside current bounds.

Parameters
valueValue to include.

◆ isContains()

template<SectionEndpoint T>
bool toy::geometry::Section< T >::isContains ( const T & value) const
nodiscardconstexprnoexcept

Returns true if value lies inside [start, end] (inclusive).

Parameters
valueValue to test.
Returns
true when start <= value <= end.

◆ isReset()

template<SectionEndpoint T>
bool toy::geometry::Section< T >::isReset ( ) const
nodiscardconstexprnoexcept

Returns true if the section is in reset (empty) state.

Returns
true when start > end.

◆ isValid()

template<SectionEndpoint T>
bool toy::geometry::Section< T >::isValid ( ) const
nodiscardconstexprnoexcept

Returns true if the section represents a valid non-empty interval.

Returns
true when start <= end.

◆ length()

template<SectionEndpoint T>
T toy::geometry::Section< T >::length ( ) const
nodiscardconstexprnoexcept

Returns the length of the interval.

Returns
end - start.

◆ midpoint()

template<SectionEndpoint T>
T toy::geometry::Section< T >::midpoint ( ) const
nodiscardconstexprnoexcept

Returns the midpoint of the interval.

Returns
(start + end) / 2.

◆ reset()

template<SectionEndpoint T>
void toy::geometry::Section< T >::reset ( )
constexprnoexcept

Puts the section in reset (empty) state.

Postcondition
isReset() is true, isValid() is false.

Member Data Documentation

◆ end

template<SectionEndpoint T>
T toy::geometry::Section< T >::end

Upper bound of the interval.

◆ start

template<SectionEndpoint T>
T toy::geometry::Section< T >::start

Lower bound of the interval.


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