ge211
2021.5.1
A student game engine
|
|
3 #include "ge211_forward.hxx"
4 #include "ge211_if_cpp.hxx"
5 #include "ge211_noexcept.hxx"
6 #include "ge211_type_traits.hxx"
7 #include "ge211_util.hxx"
12 #include <type_traits>
33 template <
typename COORDINATE>
64 template <
typename FROM_COORD>
78 template <
typename TO_COORD>
99 return !(*
this == that);
113 return that <= *
this;
120 return *
this <= that && *
this != that;
159 typename OTHER_COORD,
160 typename RESULT_COORD = Multiply_Result<Coordinate, OTHER_COORD>
171 typename ARITHMETIC_TYPE,
172 typename = std::enable_if_t<Is_Arithmetic<ARITHMETIC_TYPE>>
181 typename ARITHMETIC_TYPE,
182 typename = std::enable_if_t<Is_Arithmetic<ARITHMETIC_TYPE>>
190 Dims operator-()
const
198 return *
this = *
this + that;
204 return *
this = *
this - that;
213 return *
this = *
this * that;
220 typename ARITHMETIC_TYPE,
221 typename = std::enable_if_t<Is_Arithmetic<ARITHMETIC_TYPE>>
225 return *
this = *
this * scalar;
235 typename ARITHMETIC_TYPE,
236 typename = std::enable_if_t<Is_Arithmetic<ARITHMETIC_TYPE>>
240 return *
this = *
this / scalar;
252 typename = std::enable_if_t<Is_Arithmetic<SCALAR>>
257 return dims * scalar;
264 template <
typename COORDINATE>
283 NOEXCEPT_(detail::is_nothrow_convertible<Coordinate>())
297 NOEXCEPT_(detail::is_nothrow_convertible<Coordinate>())
298 :
Posn{dims.width, dims.height}
308 template <
typename FROM_COORD>
322 template <
typename TO_COORD>
326 return {TO_COORD(
x), TO_COORD(
y)};
336 NOEXCEPT_(detail::is_nothrow_comparable<Coordinate>())
338 return x == that.x &&
y == that.y;
343 NOEXCEPT_(detail::is_nothrow_comparable<Coordinate>())
345 return !(*
this == p2);
351 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
359 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
366 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
368 return {
x - that.x,
y - that.y};
373 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
375 return *
this = *
this + dims;
380 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
382 return *
this = *
this - dims;
393 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
401 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
409 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
417 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
425 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
427 return {
x - dims.width,
y - dims.height};
433 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
435 return {
x + dims.width,
y - dims.height};
441 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
443 return {
x - dims.width,
y + dims.height};
449 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
451 return {
x + dims.width,
y + dims.height};
459 template <
typename COORDINATE>
503 template <
typename FROM_COORD>
519 template <
typename TO_COORD>
523 return {TO_COORD(
x), TO_COORD(
y), TO_COORD(
width), TO_COORD(
height)};
534 NOEXCEPT_(detail::is_nothrow_comparable<Coordinate>())
536 return x == that.x &&
538 width == that.width &&
544 NOEXCEPT_(detail::is_nothrow_comparable<Coordinate>())
546 return !(*
this == that);
557 NOEXCEPT_(detail::is_nothrow_convertible<
Coordinate>())
564 NOEXCEPT_(detail::has_nothrow_arithmetic<
Coordinate>())
571 NOEXCEPT_(detail::has_nothrow_arithmetic<
Coordinate>())
578 NOEXCEPT_(detail::has_nothrow_arithmetic<
Coordinate>())
585 NOEXCEPT_(detail::has_nothrow_arithmetic<
Coordinate>())
592 NOEXCEPT_(detail::has_nothrow_arithmetic<
Coordinate>() &&
606 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
608 return {tl.x, tl.y, dims.width, dims.height};
614 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
622 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
630 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
638 NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
661 friend ::ge211::internal::Render_sprite;
662 friend class detail::Renderer;
665 operator SDL_Rect() const
666 NOEXCEPT_(detail::is_nothrow_convertible<COORDINATE,
int>())
669 result.x =
static_cast<int>(
x);
670 result.y =
static_cast<int>(
y);
671 result.w =
static_cast<int>(
width);
672 result.h =
static_cast<int>(
height);
680 template <
typename COORDINATE>
682 :
public std::iterator<std::input_iterator_tag, const Posn_type>
700 if (++current_.y >= y_end_) {
702 current_.y = y_begin_;
711 if (current_.y == y_begin_) {
741 return **
this == *that;
747 return !(*
this == that);
939 template <
typename COORDINATE>
955 template <
typename COORDINATE>
978 template <
typename COORDINATE>
980 make_rect(COORDINATE x, COORDINATE y, COORDINATE width, COORDINATE height)
982 return {x, y, width, height};
991 template <
typename COORDINATE>
995 <<
"Dims<" << detail::name_of_type<COORDINATE>() <<
">("
1000 template <
typename COORDINATE>
1004 <<
"Posn<" << detail::name_of_type<COORDINATE>() <<
">("
1005 << p.
x <<
", " << p.
y <<
")";
1009 template <
typename COORDINATE>
1013 <<
"Rect<" << detail::name_of_type<COORDINATE>() <<
">("
1014 << rect.
x <<
", " << rect.
y <<
", "
1031 template <
typename COORDINATE>
1038 return hash_t_(pos.x) * 31 ^ hash_t_(pos.y);
iterator & operator--()
Pre-decrements, retreating this iterator to the previous Posn.
Posn(Coordinate x, Coordinate y)
Constructs a position from the given x and y coordinates.
bool operator!=(iterator const &that) const
Iterator inequality.
ge211::Rect< TO_COORD > into() const
Explicitly converts a Rect to another coordinate type.
static Rect from_center(Posn_type center, Dims_type dims)
Creates a Rect given the position of its center and its dimensions.
Dims & operator*=(ARITHMETIC_TYPE scalar)
Succinct Dims-scalar multiplication.
ge211::Dims< TO_COORD > into() const
Explicitly converts a Dims to a different coordinate type.
Posn & operator-=(Dims_type dims)
Succinct position translation.
bool operator>=(Dims that) const
Greater-than-or-equal for Dims.
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.
Dims_type dimensions() const
The dimensions of the rectangle.
Coordinate x
The x coordinate of the upper-left vertex.
Dims< COORDINATE > make_dims(COORDINATE x, COORDINATE y)
Constructs a Dims given the width and height.
Posn right_by(Coordinate dx) const
Constructs the position that is to the right of this position by the given amount.
A Sprite that renders as a solid circle.
bool operator!=(Dims that) const
Disequality for Dims.
bool operator!=(Posn p2) const
Disequality for positions.
Posn< COORDINATE > make_posn(COORDINATE x, COORDINATE y)
Constructs a Posn given the x and y coordinates.
Dims & operator+=(Dims that)
Succinct Dims addition.
Dims(const Dims< FROM_COORD > &that)
Casts or converts a Dims to a Dims of a different coordinate type.
Posn< Coordinate > Posn_type
The position type corresponding to this type.
Posn operator+(Dims_type dims) const
Translates a position by some displacement.
Posn down_right_by(Dims_type dims) const
Constructs the position that is below and right of this position by the given dimensions.
bool operator<=(Dims that) const
Less-than-or-equal for Dims.
Posn operator-(Dims_type dims) const
Translates a position by the opposite of some displacement.
bool operator==(Posn that) const
Equality for positions.
bool operator==(iterator const &that) const
Compares whether two iterators are equal.
bool operator==(Dims that) const
Equality for Dims.
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...
Posn down_left_by(Dims_type dims) const
Constructs the position that is below and left of this position by the given dimensions.
Dims & operator*=(Dims< OTHER_COORD > that)
Succinct Dims–Dims multiplication. Scales *this by that.
Coordinate width
The width of the rectangle in pixels.
std::ostream & operator<<(std::ostream &out, Dims< COORDINATE > dims)
Formats a Dims on an output stream.
The game engine namespace.
Coordinate y
The y coordinate of the upper-left vertex.
iterator end() const
Returns an iterator one past the end of this rectangle.
Posn left_by(Coordinate dx) const
Constructs the position that is to the left of this position by the given amount.
Posn up_right_by(Dims_type dims) const
Constructs the position that is above and right of this position by the given dimensions.
Dims< COORDINATE > operator*(SCALAR scalar, Dims< COORDINATE > dims)
Multiplies a scalar and a Dims.
Coordinate x
The x coordinate.
iterator begin() const
Returns an iterator to the top left corner of this rectangle.
Represents the dimensions of an object, or more generally, the displacement between two Posns.
bool operator>(Dims that) const
Greater-than for Dims.
Dims operator*(ARITHMETIC_TYPE scalar) const
Multiplies a Dims by a scalar.
constexpr origin_type the_origin
Gets implicitly converted to Posn<COORDINATE>(0, 0) for any coordinate type COORDINATE.
iterator operator++(int)
Post-increments, advancing this iterator to the next Posn.
Dims_type operator-(Posn that) const
Subtracts two Posns, yields a Dims.
Coordinate height
The height of the object.
std::size_t operator()(ge211::Posn< COORDINATE > pos) const
Hashes a Posn<COORDINATE>, provided that COORDINATE is hashable.
Posn_type top_left() const
The position of the top left vertex.
iterator operator--(int)
Post-decrements, retreating this iterator to the previous Posn.
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.
Posn_type operator*() const
Returns the current Posn of this iterator.
Dims & operator/=(ARITHMETIC_TYPE scalar)
Succinct Dims-scalar division.
COORDINATE Coordinate
The coordinate type for the rectangle.
Rect< COORDINATE > make_rect(COORDINATE x, COORDINATE y, COORDINATE width, COORDINATE height)
Constructs a Rect given its member variables.
Coordinate y
The y coordiante.
Posn up_left_by(Dims_type dims) const
Constructs the position that is above and left of this position by the given dimensions.
Posn(Dims_type dims)
Constructs a position from a Dims, which gives the displacement of the position from the origin.
int Coordinate
The coordinate type for the position.
Posn_type const * operator->() const
Returns a pointer to the current Posn of this iterator.
Posn(origin_type)
Constructs the origin when given the_origin.
Rect()
Default-constructs the zero-sized Rect at the origin.
Dims< RESULT_COORD > operator*(Dims< OTHER_COORD > that) const
Multiplies two Dimses.
Posn_type center() const
The position of the center of the rectangle.
Rect(const Rect< FROM_COORD > &that)
Casts or converts a Rect to a Rect of a different coordinate type.
Posn_type bottom_left() const
The position of the bottom left vertex.
Dims operator/(ARITHMETIC_TYPE scalar) const
Divides a Dims by a scalar.
Coordinate width
The width of the object.
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.
Dims()
Default-constructs the zero-sized Dims.
Posn up_by(Coordinate dy) const
Constructs the position that is above this position by the given amount.
Posn & operator+=(Dims_type dims)
Succinct position translation.
Coordinate height
The height of the rectangle in pixels.
bool operator!=(const Rect &that) const
Disequality for rectangles.
Posn(const Posn< FROM_COORD > &that)
Casts or converts a Posn to a Posn of a different coordinate type.
A position in the COORDINATE-valued Cartesian plane, where COORDINATE can be any arithmetic type.
int Coordinate
The coordinate type for the dimensions.
Represents a positioned rectangle.
Posn_type top_right() const
The position of the top right vertex.
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.
bool operator==(const Rect &that) const
Equality for rectangles.
Dims operator-(Dims that) const
Subtracts two Dimses. This is vector subtraction.
Dims operator+(Dims that) const
Adds two Dimses. This is vector addition.
bool operator<(Dims that) const
Less-than for Dims.
Dims(Coordinate width, Coordinate height)
Constructs a dimensions from the given width and height.
iterator & operator++()
Pre-increments, advancing this iterator to the next Posn.
The type of the special value the_origin.
Posn down_by(Coordinate dy) const
Constructs the position that is below this position by the given amount.
ge211::Posn< TO_COORD > into() const
Explicitly converts a Posn to another coordinate type.
Posn_type bottom_right() const
The position of the bottom right vertex.
Dims & operator-=(Dims that)
Succinct Dims subtraction.
An iterator over the Posn<COORDINATE>s of a Rect<COORDINATE>.