ge211  2021.5.1
A student game engine
Dims< COORDINATE > Struct Template Reference

Detailed Description

template<typename COORDINATE>
struct ge211::geometry::Dims< COORDINATE >

Represents the dimensions of an object, or more generally, the displacement between two Posns.

The coordinate type COORDINATE may be any arithmetic type.

Definition at line 34 of file ge211_geometry.hxx.

Public Types

using Coordinate = COORDINATE
 The coordinate type for the dimensions. More...
 

Public Member Functions

Constructors and Conversions
 Dims (Coordinate width, Coordinate height)
 Constructs a dimensions from the given width and height.
 
 Dims ()
 Default-constructs the zero-sized Dims.
 
template<typename FROM_COORD >
 Dims (const Dims< FROM_COORD > &that)
 Casts or converts a Dims to a Dims of a different coordinate type. More...
 
template<typename TO_COORD >
ge211::Dims< TO_COORD > into () const
 Explicitly converts a Dims to a different coordinate type. More...
 
Operators
bool operator== (Dims that) const
 Equality for Dims.
 
bool operator!= (Dims that) const
 Disequality for Dims.
 
bool operator<= (Dims that) const
 Less-than-or-equal for Dims. More...
 
bool operator>= (Dims that) const
 Greater-than-or-equal for Dims. More...
 
bool operator< (Dims that) const
 Less-than for Dims. More...
 
bool operator> (Dims that) const
 Greater-than for Dims. More...
 
Dims operator+ (Dims that) const
 Adds two Dimses. This is vector addition.
 
Dims operator- (Dims that) const
 Subtracts two Dimses. This is vector subtraction.
 
template<typename OTHER_COORD , typename RESULT_COORD = Multiply_Result<Coordinate, OTHER_COORD>>
Dims< RESULT_COORD > operator* (Dims< OTHER_COORD > that) const
 Multiplies two Dimses. More...
 
template<typename ARITHMETIC_TYPE , typename = std::enable_if_t<Is_Arithmetic<ARITHMETIC_TYPE>>>
Dims operator* (ARITHMETIC_TYPE scalar) const
 Multiplies a Dims by a scalar.
 
template<typename ARITHMETIC_TYPE , typename = std::enable_if_t<Is_Arithmetic<ARITHMETIC_TYPE>>>
Dims operator/ (ARITHMETIC_TYPE scalar) const
 Divides a Dims by a scalar.
 
Dims operator- () const
 
Dimsoperator+= (Dims that)
 Succinct Dims addition.
 
Dimsoperator-= (Dims that)
 Succinct Dims subtraction.
 
template<typename OTHER_COORD >
Dimsoperator*= (Dims< OTHER_COORD > that)
 Succinct Dims–Dims multiplication. Scales *this by that.
 
template<typename ARITHMETIC_TYPE , typename = std::enable_if_t<Is_Arithmetic<ARITHMETIC_TYPE>>>
Dimsoperator*= (ARITHMETIC_TYPE scalar)
 Succinct Dims-scalar multiplication.
 
template<typename ARITHMETIC_TYPE , typename = std::enable_if_t<Is_Arithmetic<ARITHMETIC_TYPE>>>
Dimsoperator/= (ARITHMETIC_TYPE scalar)
 Succinct Dims-scalar division. More...
 

Public Attributes

Coordinate width
 The width of the object.
 
Coordinate height
 The height of the object.
 

Member Typedef Documentation

◆ Coordinate

using Coordinate = COORDINATE

The coordinate type for the dimensions.

This is an alias of geometry type parameter COORDINATE.

Definition at line 38 of file ge211_geometry.hxx.

Constructor & Destructor Documentation

◆ Dims()

Dims ( const Dims< FROM_COORD > &  that)
inlineexplicit

Casts or converts a Dims to a Dims of a different coordinate type.

For example:

ge211::Dims<int> p1 { 3, 4 };
auto p2 = ge211::Dims<double>(p1);

Definition at line 65 of file ge211_geometry.hxx.

Member Function Documentation

◆ into()

ge211::Dims<TO_COORD> into ( ) const
inline

Explicitly converts a Dims to a different coordinate type.

For example:

auto d1 = ge211::Dims<int>{3, 4};
auto d2 = d1.into<double>();

Definition at line 80 of file ge211_geometry.hxx.

◆ operator*()

Dims<RESULT_COORD> operator* ( Dims< OTHER_COORD >  that) const
inline

Multiplies two Dimses.

This scales them by multiplying the widths and heights, pointwise.

Example

ge211::Dims<double> cell_size {50, 25};
ge211::Dims<int> repetitions {3, 2};
ge211::Dims<double> actual_result = cell_size * repetitions;
ge211::Dims<double> expected_result {150, 50};
CHECK( actual_result == expected_result );

Definition at line 163 of file ge211_geometry.hxx.

◆ operator/=()

Dims& operator/= ( ARITHMETIC_TYPE  scalar)
inline

Succinct Dims-scalar division.

Preconditions

  • scalar != 0 (when ARITHMETIC_TYPE is an integer type)

Definition at line 238 of file ge211_geometry.hxx.

◆ operator<()

bool operator< ( Dims< COORDINATE >  that) const
inline

Less-than for Dims.

True when *this Dims fits inside that Dims but they aren't equal.

Definition at line 118 of file ge211_geometry.hxx.

◆ operator<=()

bool operator<= ( Dims< COORDINATE >  that) const
inline

Less-than-or-equal for Dims.

Determines whether *this Dims fits inside that Dims.

Definition at line 104 of file ge211_geometry.hxx.

◆ operator>()

bool operator> ( Dims< COORDINATE >  that) const
inline

Greater-than for Dims.

True when that Dims fits inside *this Dims but they aren't equal.

Definition at line 125 of file ge211_geometry.hxx.

◆ operator>=()

bool operator>= ( Dims< COORDINATE >  that) const
inline

Greater-than-or-equal for Dims.

Determines whether that Dims fits inside *this Dims.

Definition at line 111 of file ge211_geometry.hxx.


The documentation for this struct was generated from the following files:
ge211::geometry::Dims::into
ge211::Dims< TO_COORD > into() const
Explicitly converts a Dims to a different coordinate type.
Definition: ge211_geometry.hxx:80
ge211::geometry::Dims< int >