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

Detailed Description

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

Represents a positioned rectangle.

Definition at line 460 of file ge211_geometry.hxx.

Classes

class  iterator
 An iterator over the Posn<COORDINATE>s of a Rect<COORDINATE>. More...
 

Public Types

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

Public Member Functions

iterator begin () const
 Returns an iterator to the top left corner of this rectangle.
 
iterator end () const
 Returns an iterator one past the end of this rectangle.
 
Construction and Conversion
 Rect (Coordinate x, Coordinate y, Coordinate width, Coordinate height)
 Constructs a rectangle given the x and y coordinates of its top left corner, and its width and height.
 
 Rect ()
 Default-constructs the zero-sized Rect at the origin.
 
template<typename FROM_COORD >
 Rect (const Rect< FROM_COORD > &that)
 Casts or converts a Rect to a Rect of a different coordinate type. More...
 
template<typename TO_COORD >
ge211::Rect< TO_COORD > into () const
 Explicitly converts a Rect to another coordinate type. More...
 
Operators
bool operator== (const Rect &that) const
 Equality for rectangles. More...
 
bool operator!= (const Rect &that) const
 Disequality for rectangles.
 
Dims and positions
Dims_type dimensions () const
 The dimensions of the rectangle. More...
 
Posn_type top_left () const
 The position of the top left vertex.
 
Posn_type top_right () const
 The position of the top right vertex.
 
Posn_type bottom_left () const
 The position of the bottom left vertex.
 
Posn_type bottom_right () const
 The position of the bottom right vertex.
 
Posn_type center () const
 The position of the center of the rectangle.
 

Static Public Member Functions

Static factory functions
static Rect from_top_left (Posn_type tl, Dims_type dims)
 Creates a Rect given the position of its top left vertex and its dimensions.
 
static Rect from_top_right (Posn_type tr, Dims_type dims)
 Creates a Rect given the position of its top right vertex and its dimensions.
 
static Rect from_bottom_left (Posn_type bl, Dims_type dims)
 Creates a Rect given the position of its bottom left vertex and its dimensions.
 
static Rect from_bottom_right (Posn_type br, Dims_type dims)
 Creates a Rect given the position of its bottom right vertex and its dimensions.
 
static Rect from_center (Posn_type center, Dims_type dims)
 Creates a Rect given the position of its center and its dimensions.
 

Public Attributes

Coordinate x
 The x coordinate of the upper-left vertex.
 
Coordinate y
 The y coordinate of the upper-left vertex.
 
Coordinate width
 The width of the rectangle in pixels.
 
Coordinate height
 The height of the rectangle in pixels.
 

Member Typedef Documentation

◆ Coordinate

using Coordinate = COORDINATE

The coordinate type for the rectangle.

This is an alias of type parameter COORDINATE.

Definition at line 464 of file ge211_geometry.hxx.

◆ Dims_type

The dimensions type corresponding to this type.

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

Definition at line 468 of file ge211_geometry.hxx.

◆ Posn_type

The position type corresponding to this type.

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

Definition at line 472 of file ge211_geometry.hxx.

Constructor & Destructor Documentation

◆ Rect()

Rect ( const Rect< FROM_COORD > &  that)
inlineexplicit

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

For example:

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

Definition at line 504 of file ge211_geometry.hxx.

Member Function Documentation

◆ dimensions()

Dims_type dimensions ( ) const
inline

The dimensions of the rectangle.

Equivalent to Dims<Coordinate>{rect.width, rect.height}.

Definition at line 556 of file ge211_geometry.hxx.

◆ into()

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

Explicitly converts a Rect to another coordinate type.

For example:

auto r1 = ge211::Rect<int>{-1, -1, 2, 2};
auto r2 = r1.into<double>();

Definition at line 521 of file ge211_geometry.hxx.

◆ operator==()

bool operator== ( const Rect< COORDINATE > &  that) const
inline

Equality for rectangles.

Note that this is naïve, in that it considers empty rectangles with different positions to be different.

Definition at line 533 of file ge211_geometry.hxx.


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