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

Detailed Description

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

A position in the COORDINATE-valued Cartesian plane, where COORDINATE can be any arithmetic type.

In graphics, the origin is traditionally in the upper left, so the x coordinate increases to the right and the y coordinate increases downward.

Definition at line 265 of file ge211_geometry.hxx.

Public Types

using Coordinate = COORDINATE
 The coordinate type for the position. More...
 
using Dims_type = Dims< COORDINATE >
 The dimensions type corresponding to this type. More...
 

Public Member Functions

Constructors and Conversions
 Posn (Coordinate x, Coordinate y)
 Constructs a position from the given x and y coordinates.
 
 Posn (origin_type)
 Constructs the origin when given the_origin.
 
 Posn (Dims_type dims)
 Constructs a position from a Dims, which gives the displacement of the position from the origin.
 
template<typename FROM_COORD >
 Posn (const Posn< FROM_COORD > &that)
 Casts or converts a Posn to a Posn of a different coordinate type. More...
 
template<typename TO_COORD >
ge211::Posn< TO_COORD > into () const
 Explicitly converts a Posn to another coordinate type. More...
 
Operators
bool operator== (Posn that) const
 Equality for positions.
 
bool operator!= (Posn p2) const
 Disequality for positions.
 
Posn operator+ (Dims_type dims) const
 Translates a position by some displacement. More...
 
Posn operator- (Dims_type dims) const
 Translates a position by the opposite of some displacement. More...
 
Dims_type operator- (Posn that) const
 Subtracts two Posns, yields a Dims.
 
Posnoperator+= (Dims_type dims)
 Succinct position translation.
 
Posnoperator-= (Dims_type dims)
 Succinct position translation.
 
Shifting member functions
Posn up_by (Coordinate dy) const
 Constructs the position that is above this position by the given amount.
 
Posn down_by (Coordinate dy) const
 Constructs the position that is below this position by the given amount.
 
Posn left_by (Coordinate dx) const
 Constructs the position that is to the left of this position by the given amount.
 
Posn right_by (Coordinate dx) const
 Constructs the position that is to the right of this position by the given amount.
 
Posn up_left_by (Dims_type dims) const
 Constructs the position that is above and left of this position by the given dimensions.
 
Posn up_right_by (Dims_type dims) const
 Constructs the position that is above and right of this position by the given dimensions.
 
Posn down_left_by (Dims_type dims) const
 Constructs the position that is below and left of this position by the given dimensions.
 
Posn down_right_by (Dims_type dims) const
 Constructs the position that is below and right of this position by the given dimensions.
 

Public Attributes

Coordinate x
 The x coordinate.
 
Coordinate y
 The y coordiante.
 

Member Typedef Documentation

◆ Coordinate

using Coordinate = COORDINATE

The coordinate type for the position.

This is an alias of type parameter COORDINATE.

Definition at line 269 of file ge211_geometry.hxx.

◆ Dims_type

using Dims_type = Dims<COORDINATE>

The dimensions type corresponding to this type.

This is an alias of ge211::geometry::Dims.

Definition at line 273 of file ge211_geometry.hxx.

Constructor & Destructor Documentation

◆ Posn()

Posn ( const Posn< FROM_COORD > &  that)
inlineexplicit

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

For example:

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

Definition at line 309 of file ge211_geometry.hxx.

Member Function Documentation

◆ into()

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

Explicitly converts a Posn to another coordinate type.

For example:

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

Definition at line 324 of file ge211_geometry.hxx.

◆ operator+()

Posn operator+ ( Dims_type  dims) const
inline

Translates a position by some displacement.

This is the same as Posn::down_right_by(Dims_type) const.

Definition at line 350 of file ge211_geometry.hxx.

◆ operator-()

Posn operator- ( Dims_type  dims) const
inline

Translates a position by the opposite of some displacement.

This is the same as Posn::up_left_by(Dims_type) const.

Definition at line 358 of file ge211_geometry.hxx.


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