ge211  2021.5.1
A student game engine
ge211_geometry.hxx
1 #pragma once
2 
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"
8 
9 #include <SDL_rect.h>
10 
11 #include <ostream>
12 #include <type_traits>
13 #include <utility>
14 
15 namespace ge211 {
16 
18 namespace geometry {
19 
26 {
27 };
28 
29 
33 template <typename COORDINATE>
34 struct Dims
35 {
38  using Coordinate = COORDINATE;
39 
42 
45 
48  : width{width},
49  height{height}
50  { }
51 
53  Dims()
54  : Dims{Coordinate{}, Coordinate{}}
55  { }
56 
64  template <typename FROM_COORD>
65  explicit Dims(const Dims<FROM_COORD> &that)
66  : width(that.width),
67  height(that.height)
68  { }
69 
78  template <typename TO_COORD>
80  into() const
81  {
82  return {TO_COORD(width), TO_COORD(height)};
83  }
84 
86 
89 
91  bool operator==(Dims that) const
92  {
93  return width == that.width && height == that.height;
94  }
95 
97  bool operator!=(Dims that) const
98  {
99  return !(*this == that);
100  }
101 
104  bool operator<=(Dims that) const
105  {
106  return width <= that.width && height <= that.height;
107  }
108 
111  bool operator>=(Dims that) const
112  {
113  return that <= *this;
114  }
115 
118  bool operator<(Dims that) const
119  {
120  return *this <= that && *this != that;
121  }
122 
125  bool operator>(Dims that) const
126  {
127  return that < *this;
128  }
129 
131  Dims operator+(Dims that) const
132  {
133  return {Coordinate(width + that.width),
134  Coordinate(height + that.height)};
135  }
136 
138  Dims operator-(Dims that) const
139  {
140  return {Coordinate(width - that.width),
141  Coordinate(height - that.height)};
142  }
143 
158  template <
159  typename OTHER_COORD,
160  typename RESULT_COORD = Multiply_Result<Coordinate, OTHER_COORD>
161  >
164  {
165  return {RESULT_COORD(width * that.width),
166  RESULT_COORD(height * that.height)};
167  }
168 
170  template <
171  typename ARITHMETIC_TYPE,
172  typename = std::enable_if_t<Is_Arithmetic<ARITHMETIC_TYPE>>
173  >
174  Dims operator*(ARITHMETIC_TYPE scalar) const
175  {
176  return {Coordinate(width * scalar), Coordinate(height * scalar)};
177  }
178 
180  template <
181  typename ARITHMETIC_TYPE,
182  typename = std::enable_if_t<Is_Arithmetic<ARITHMETIC_TYPE>>
183  >
184  Dims operator/(ARITHMETIC_TYPE scalar) const
185  {
186  return {Coordinate(width / scalar), Coordinate(height / scalar)};
187  }
188 
189  // Negates a Dims. (Multiplies it by -1.)
190  Dims operator-() const
191  {
192  return {-width, -height};
193  }
194 
197  {
198  return *this = *this + that;
199  }
200 
203  {
204  return *this = *this - that;
205  }
206 
208  template <
209  typename OTHER_COORD
210  >
212  {
213  return *this = *this * that;
214  }
215 
219  template <
220  typename ARITHMETIC_TYPE,
221  typename = std::enable_if_t<Is_Arithmetic<ARITHMETIC_TYPE>>
222  >
223  Dims &operator*=(ARITHMETIC_TYPE scalar)
224  {
225  return *this = *this * scalar;
226  }
227 
234  template <
235  typename ARITHMETIC_TYPE,
236  typename = std::enable_if_t<Is_Arithmetic<ARITHMETIC_TYPE>>
237  >
238  Dims &operator/=(ARITHMETIC_TYPE scalar)
239  {
240  return *this = *this / scalar;
241  }
242 
244 };
245 
246 
249 template <
250  typename COORDINATE,
251  typename SCALAR,
252  typename = std::enable_if_t<Is_Arithmetic<SCALAR>>
253 >
255 operator*(SCALAR scalar, Dims<COORDINATE> dims)
256 {
257  return dims * scalar;
258 }
259 
264 template <typename COORDINATE>
265 struct Posn
266 {
269  using Coordinate = COORDINATE;
270 
274 
277 
280 
283  NOEXCEPT_(detail::is_nothrow_convertible<Coordinate>())
284  : x{x},
285  y{y}
286  { }
287 
290  NOEXCEPT_(noexcept(Coordinate{}))
291  : Posn(Coordinate{}, Coordinate{})
292  { }
293 
296  explicit Posn(Dims_type dims)
297  NOEXCEPT_(detail::is_nothrow_convertible<Coordinate>())
298  : Posn{dims.width, dims.height}
299  { }
300 
308  template <typename FROM_COORD>
309  explicit Posn(const Posn<FROM_COORD> &that)
310  : x(that.x),
311  y(that.y)
312  { }
313 
322  template <typename TO_COORD>
324  into() const
325  {
326  return {TO_COORD(x), TO_COORD(y)};
327  }
328 
330 
333 
335  bool operator==(Posn that) const
336  NOEXCEPT_(detail::is_nothrow_comparable<Coordinate>())
337  {
338  return x == that.x && y == that.y;
339  }
340 
342  bool operator!=(Posn p2) const
343  NOEXCEPT_(detail::is_nothrow_comparable<Coordinate>())
344  {
345  return !(*this == p2);
346  }
347 
351  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
352  {
353  return down_right_by(dims);
354  }
355 
359  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
360  {
361  return up_left_by(dims);
362  }
363 
366  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
367  {
368  return {x - that.x, y - that.y};
369  }
370 
373  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
374  {
375  return *this = *this + dims;
376  }
377 
380  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
381  {
382  return *this = *this - dims;
383  }
384 
386 
389 
393  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
394  {
395  return {x, y - dy};
396  }
397 
401  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
402  {
403  return {x, y + dy};
404  }
405 
409  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
410  {
411  return {x - dx, y};
412  }
413 
417  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
418  {
419  return {x + dx, y};
420  }
421 
425  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
426  {
427  return {x - dims.width, y - dims.height};
428  }
429 
433  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
434  {
435  return {x + dims.width, y - dims.height};
436  }
437 
441  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
442  {
443  return {x - dims.width, y + dims.height};
444  }
445 
449  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
450  {
451  return {x + dims.width, y + dims.height};
452  }
453 
455 };
456 
457 
459 template <typename COORDINATE>
460 struct Rect
461 {
464  using Coordinate = COORDINATE;
465 
469 
473 
478 
481 
485  : x{x},
486  y{y},
487  width{width},
488  height{height}
489  { }
490 
494  { }
495 
503  template <typename FROM_COORD>
504  explicit Rect(const Rect<FROM_COORD> &that)
505  : x(that.x),
506  y(that.y),
507  width(that.width),
508  height(that.height)
509  { }
510 
519  template <typename TO_COORD>
521  into() const
522  {
523  return {TO_COORD(x), TO_COORD(y), TO_COORD(width), TO_COORD(height)};
524  }
525 
527 
530 
533  bool operator==(const Rect &that) const
534  NOEXCEPT_(detail::is_nothrow_comparable<Coordinate>())
535  {
536  return x == that.x &&
537  y == that.y &&
538  width == that.width &&
539  height == that.height;
540  }
541 
543  bool operator!=(const Rect &that) const
544  NOEXCEPT_(detail::is_nothrow_comparable<Coordinate>())
545  {
546  return !(*this == that);
547  }
548 
550 
553 
557  NOEXCEPT_(detail::is_nothrow_convertible<Coordinate>())
558  {
559  return {width, height};
560  }
561 
564  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
565  {
566  return {x, y};
567  }
568 
571  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
572  {
573  return top_left().right_by(width);
574  }
575 
578  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
579  {
580  return top_left().down_by(height);
581  }
582 
585  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
586  {
587  return top_left().down_right_by(dimensions());
588  }
589 
592  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>() &&
593  detail::has_nothrow_division<Coordinate>())
594  {
595  return top_left().down_right_by(dimensions() / Coordinate(2));
596  }
597 
599 
602 
606  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
607  {
608  return {tl.x, tl.y, dims.width, dims.height};
609  }
610 
614  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
615  {
616  return from_top_left(tr.left_by(dims.width), dims);
617  }
618 
622  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
623  {
624  return from_top_left(bl.up_by(dims.height), dims);
625  }
626 
630  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
631  {
632  return from_top_left(br.up_left_by(dims), dims);
633  }
634 
638  NOEXCEPT_(detail::has_nothrow_arithmetic<Coordinate>())
639  {
640  return from_top_left(center.up_left_by(dims / Coordinate(2)), dims);
641  }
642 
644 
645  class iterator;
646 
648  iterator begin() const
649  {
650  return {top_left(), y, y + height};
651  }
652 
654  iterator end() const
655  {
656  return {top_left().right_by(width), y, y + height};
657  }
658 
659 private:
660  friend Circle_sprite;
661  friend ::ge211::internal::Render_sprite;
662  friend class detail::Renderer;
663 
665  operator SDL_Rect() const
666  NOEXCEPT_(detail::is_nothrow_convertible<COORDINATE, int>())
667  {
668  SDL_Rect result;
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);
673  return result;
674  }
675 };
676 
680 template <typename COORDINATE>
681 class Rect<COORDINATE>::iterator
682  : public std::iterator<std::input_iterator_tag, const Posn_type>
683 {
684 public:
687  {
688  return current_;
689  }
690 
692  Posn_type const *operator->() const
693  {
694  return &current_;
695  }
696 
699  {
700  if (++current_.y >= y_end_) {
701  ++current_.x;
702  current_.y = y_begin_;
703  }
704 
705  return *this;
706  }
707 
710  {
711  if (current_.y == y_begin_) {
712  current_.y = y_end_;
713  --current_.x;
714  }
715 
716  --current_.y;
717 
718  return *this;
719  }
720 
723  {
724  iterator result(*this);
725  ++*this;
726  return result;
727  }
728 
731  {
732  iterator result(*this);
733  --*this;
734  return result;
735  }
736 
739  bool operator==(iterator const &that) const
740  {
741  return **this == *that;
742  }
743 
745  bool operator!=(iterator const &that) const
746  {
747  return !(*this == that);
748  }
749 
750 private:
751  friend Rect;
752 
753  iterator(Posn_type current, Coordinate y_begin, Coordinate y_end)
754  : current_(current),
755  y_begin_(y_begin),
756  y_end_(y_end)
757  { }
758 
759  Posn_type current_;
760  Coordinate y_begin_;
761  Coordinate y_end_;
762 };
763 
764 
793 {
794 public:
797 
799  Transform() NOEXCEPT;
800 
803  static Transform rotation(double) NOEXCEPT;
804 
806  static Transform flip_h() NOEXCEPT;
807 
809  static Transform flip_v() NOEXCEPT;
810 
812  static Transform scale(double) NOEXCEPT;
813 
815  static Transform scale_x(double) NOEXCEPT;
816 
818  static Transform scale_y(double) NOEXCEPT;
819 
821 
824 
826  Transform &set_rotation(double) NOEXCEPT;
827 
829  Transform &set_flip_h(bool) NOEXCEPT;
830 
832  Transform &set_flip_v(bool) NOEXCEPT;
833 
837  Transform &set_scale(double) NOEXCEPT;
838 
842  Transform &set_scale_x(double) NOEXCEPT;
843 
847  Transform &set_scale_y(double) NOEXCEPT;
848 
850 
853 
855  double get_rotation() const NOEXCEPT;
856 
858  bool get_flip_h() const NOEXCEPT;
859 
861  bool get_flip_v() const NOEXCEPT;
862 
864  double get_scale_x() const NOEXCEPT;
865 
867  double get_scale_y() const NOEXCEPT;
868 
870 
873 
878  bool is_identity() const NOEXCEPT;
879 
881  Transform operator*(const Transform& other) const NOEXCEPT;
882 
887  Transform inverse() const NOEXCEPT;
888 
890 
893 
895  bool operator==(const Transform& other) const NOEXCEPT;
896 
898  bool operator!=(const Transform& other) const NOEXCEPT;
899 
901 
902 private:
903  double rotation_;
904  double scale_x_;
905  double scale_y_;
906  bool flip_h_;
907  bool flip_v_;
908 };
909 
910 
923 //;
925 
926 
929 
939 template <typename COORDINATE>
941 make_dims(COORDINATE x, COORDINATE y)
942 {
943  return {x, y};
944 }
945 
955 template <typename COORDINATE>
957 make_posn(COORDINATE x, COORDINATE y)
958 {
959  return {x, y};
960 }
961 
962 
978 template <typename COORDINATE>
980 make_rect(COORDINATE x, COORDINATE y, COORDINATE width, COORDINATE height)
981 {
982  return {x, y, width, height};
983 }
984 
986 
989 
991 template <typename COORDINATE>
993 {
994  return out
995  << "Dims<" << detail::name_of_type<COORDINATE>() << ">("
996  << dims.width << ", " << dims.height << ")";
997 }
998 
1000 template <typename COORDINATE>
1002 {
1003  return out
1004  << "Posn<" << detail::name_of_type<COORDINATE>() << ">("
1005  << p.x << ", " << p.y << ")";
1006 }
1007 
1009 template <typename COORDINATE>
1011 {
1012  return out
1013  << "Rect<" << detail::name_of_type<COORDINATE>() << ">("
1014  << rect.x << ", " << rect.y << ", "
1015  << rect.width << ", " << rect.height << ")";
1016 }
1017 
1019 
1020 } // end namespace geometry.
1021 
1022 } // end namespace ge211
1023 
1024 // specializations in std:
1025 namespace std {
1026 
1031 template <typename COORDINATE>
1032 struct hash<ge211::Posn<COORDINATE>>
1033 {
1036  NOEXCEPT
1037  {
1038  return hash_t_(pos.x) * 31 ^ hash_t_(pos.y);
1039  }
1040 
1041 private:
1042  std::hash<COORDINATE> hash_t_;
1043 };
1044 
1045 } // end namespace std
1046 
ge211::geometry::Rect::iterator::operator--
iterator & operator--()
Pre-decrements, retreating this iterator to the previous Posn.
Definition: ge211_geometry.hxx:709
ge211::geometry::Posn::Posn
Posn(Coordinate x, Coordinate y)
Constructs a position from the given x and y coordinates.
Definition: ge211_geometry.hxx:282
ge211::geometry::Rect::iterator::operator!=
bool operator!=(iterator const &that) const
Iterator inequality.
Definition: ge211_geometry.hxx:745
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::Rect::from_center
static Rect from_center(Posn_type center, Dims_type dims)
Creates a Rect given the position of its center and its dimensions.
Definition: ge211_geometry.hxx:637
ge211::geometry::Dims::operator*=
Dims & operator*=(ARITHMETIC_TYPE scalar)
Succinct Dims-scalar multiplication.
Definition: ge211_geometry.hxx:223
ge211::geometry::Transform::flip_v
static Transform flip_v()
Constructs a transform that flips the sprite vertically.
Definition: ge211_geometry.cxx:24
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::Posn::operator-=
Posn & operator-=(Dims_type dims)
Succinct position translation.
Definition: ge211_geometry.hxx:379
ge211::geometry::Dims::operator>=
bool operator>=(Dims that) const
Greater-than-or-equal for Dims.
Definition: ge211_geometry.hxx:111
ge211::geometry::Rect::from_top_left
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.
Definition: ge211_geometry.hxx:605
ge211::geometry::Rect::dimensions
Dims_type dimensions() const
The dimensions of the rectangle.
Definition: ge211_geometry.hxx:556
ge211::geometry::Rect::x
Coordinate x
The x coordinate of the upper-left vertex.
Definition: ge211_geometry.hxx:474
ge211::geometry::make_dims
Dims< COORDINATE > make_dims(COORDINATE x, COORDINATE y)
Constructs a Dims given the width and height.
Definition: ge211_geometry.hxx:941
ge211::geometry::Posn::right_by
Posn right_by(Coordinate dx) const
Constructs the position that is to the right of this position by the given amount.
Definition: ge211_geometry.hxx:416
ge211::sprites::Circle_sprite
A Sprite that renders as a solid circle.
Definition: ge211_sprites.hxx:194
ge211::geometry::Transform::set_flip_h
Transform & set_flip_h(bool)
Modifies this transform to determine whether to flip horizontally.
Definition: ge211_geometry.cxx:51
ge211::geometry::Dims::operator!=
bool operator!=(Dims that) const
Disequality for Dims.
Definition: ge211_geometry.hxx:97
ge211::geometry::Transform::flip_h
static Transform flip_h()
Constructs a transform that flips the sprite horizontally.
Definition: ge211_geometry.cxx:19
ge211::geometry::Posn::operator!=
bool operator!=(Posn p2) const
Disequality for positions.
Definition: ge211_geometry.hxx:342
ge211::geometry::make_posn
Posn< COORDINATE > make_posn(COORDINATE x, COORDINATE y)
Constructs a Posn given the x and y coordinates.
Definition: ge211_geometry.hxx:957
ge211::geometry::Transform::scale_y
static Transform scale_y(double)
Constructs a transform that scales the sprite in the y dimension.
Definition: ge211_geometry.cxx:39
ge211::geometry::Dims::operator+=
Dims & operator+=(Dims that)
Succinct Dims addition.
Definition: ge211_geometry.hxx:196
ge211::geometry::Transform::set_flip_v
Transform & set_flip_v(bool)
Modifies this transform to determine whether to flip vertically.
Definition: ge211_geometry.cxx:57
ge211::geometry::Dims::Dims
Dims(const Dims< FROM_COORD > &that)
Casts or converts a Dims to a Dims of a different coordinate type.
Definition: ge211_geometry.hxx:65
ge211::geometry::Transform::rotation
static Transform rotation(double)
Constructs a rotating transform, given the rotation in degrees clockwise.
Definition: ge211_geometry.cxx:14
std::iterator
ge211::geometry::Rect::Posn_type
Posn< Coordinate > Posn_type
The position type corresponding to this type.
Definition: ge211_geometry.hxx:472
ge211::geometry::Posn::operator+
Posn operator+(Dims_type dims) const
Translates a position by some displacement.
Definition: ge211_geometry.hxx:350
ge211::geometry::Posn::down_right_by
Posn down_right_by(Dims_type dims) const
Constructs the position that is below and right of this position by the given dimensions.
Definition: ge211_geometry.hxx:448
ge211::geometry::Dims::operator<=
bool operator<=(Dims that) const
Less-than-or-equal for Dims.
Definition: ge211_geometry.hxx:104
ge211::geometry::Posn::operator-
Posn operator-(Dims_type dims) const
Translates a position by the opposite of some displacement.
Definition: ge211_geometry.hxx:358
ge211::geometry::Posn::operator==
bool operator==(Posn that) const
Equality for positions.
Definition: ge211_geometry.hxx:335
ge211::geometry::Rect::iterator::operator==
bool operator==(iterator const &that) const
Compares whether two iterators are equal.
Definition: ge211_geometry.hxx:739
ge211::geometry::Dims::operator==
bool operator==(Dims that) const
Equality for Dims.
Definition: ge211_geometry.hxx:91
ge211::geometry::Transform::operator==
bool operator==(const Transform &other) const
Equality for Transforms.
Definition: ge211_geometry.cxx:134
ge211::geometry::Transform::set_scale_y
Transform & set_scale_y(double)
Modifies this transform to scale the sprite vertically.
Definition: ge211_geometry.cxx:76
ge211::geometry::Rect::Rect
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...
Definition: ge211_geometry.hxx:484
ge211::geometry::Transform::get_scale_x
double get_scale_x() const
Returns how much the sprite will be scaled horizontally.
Definition: ge211_geometry.cxx:97
ge211::geometry::Transform::set_rotation
Transform & set_rotation(double)
Modifies this transform to have the given rotation, in degrees.
Definition: ge211_geometry.cxx:44
ge211::geometry::Posn::down_left_by
Posn down_left_by(Dims_type dims) const
Constructs the position that is below and left of this position by the given dimensions.
Definition: ge211_geometry.hxx:440
ge211::geometry::Dims::operator*=
Dims & operator*=(Dims< OTHER_COORD > that)
Succinct Dims–Dims multiplication. Scales *this by that.
Definition: ge211_geometry.hxx:211
ge211::geometry::Rect::width
Coordinate width
The width of the rectangle in pixels.
Definition: ge211_geometry.hxx:476
ge211::geometry::operator<<
std::ostream & operator<<(std::ostream &out, Dims< COORDINATE > dims)
Formats a Dims on an output stream.
Definition: ge211_geometry.hxx:992
ge211
The game engine namespace.
Definition: ge211.hxx:4
ge211::geometry::Rect::y
Coordinate y
The y coordinate of the upper-left vertex.
Definition: ge211_geometry.hxx:475
ge211::geometry::Rect::end
iterator end() const
Returns an iterator one past the end of this rectangle.
Definition: ge211_geometry.hxx:654
ge211::geometry::Posn::left_by
Posn left_by(Coordinate dx) const
Constructs the position that is to the left of this position by the given amount.
Definition: ge211_geometry.hxx:408
ge211::geometry::Transform::operator!=
bool operator!=(const Transform &other) const
Disequality for Transforms.
Definition: ge211_geometry.cxx:143
ge211::geometry::Posn::up_right_by
Posn up_right_by(Dims_type dims) const
Constructs the position that is above and right of this position by the given dimensions.
Definition: ge211_geometry.hxx:432
ge211::geometry::operator*
Dims< COORDINATE > operator*(SCALAR scalar, Dims< COORDINATE > dims)
Multiplies a scalar and a Dims.
Definition: ge211_geometry.hxx:255
ge211::geometry::Posn::x
Coordinate x
The x coordinate.
Definition: ge211_geometry.hxx:275
ge211::geometry::Rect::begin
iterator begin() const
Returns an iterator to the top left corner of this rectangle.
Definition: ge211_geometry.hxx:648
ge211::geometry::Dims
Represents the dimensions of an object, or more generally, the displacement between two Posns.
Definition: ge211_geometry.hxx:35
ge211::geometry::Dims::operator>
bool operator>(Dims that) const
Greater-than for Dims.
Definition: ge211_geometry.hxx:125
ge211::geometry::Transform::scale_x
static Transform scale_x(double)
Constructs a transform that scales the sprite in the x dimension.
Definition: ge211_geometry.cxx:34
std::ostream
ge211::geometry::Dims::operator*
Dims operator*(ARITHMETIC_TYPE scalar) const
Multiplies a Dims by a scalar.
Definition: ge211_geometry.hxx:174
ge211::geometry::the_origin
constexpr origin_type the_origin
Gets implicitly converted to Posn<COORDINATE>(0, 0) for any coordinate type COORDINATE.
Definition: ge211_geometry.hxx:924
ge211::geometry::Rect::iterator::operator++
iterator operator++(int)
Post-increments, advancing this iterator to the next Posn.
Definition: ge211_geometry.hxx:722
ge211::geometry::Posn::operator-
Dims_type operator-(Posn that) const
Subtracts two Posns, yields a Dims.
Definition: ge211_geometry.hxx:365
ge211::geometry::Dims::height
Coordinate height
The height of the object.
Definition: ge211_geometry.hxx:41
std::hash< ge211::Posn< COORDINATE > >::operator()
std::size_t operator()(ge211::Posn< COORDINATE > pos) const
Hashes a Posn<COORDINATE>, provided that COORDINATE is hashable.
Definition: ge211_geometry.hxx:1035
ge211::geometry::Rect::top_left
Posn_type top_left() const
The position of the top left vertex.
Definition: ge211_geometry.hxx:563
ge211::geometry::Transform::scale
static Transform scale(double)
Constructs a transform that scales the sprite in both dimensions.
Definition: ge211_geometry.cxx:29
ge211::geometry::Rect::iterator::operator--
iterator operator--(int)
Post-decrements, retreating this iterator to the previous Posn.
Definition: ge211_geometry.hxx:730
ge211::geometry::Rect::from_bottom_right
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.
Definition: ge211_geometry.hxx:629
ge211::geometry::Rect::iterator::operator*
Posn_type operator*() const
Returns the current Posn of this iterator.
Definition: ge211_geometry.hxx:686
ge211::geometry::Dims::operator/=
Dims & operator/=(ARITHMETIC_TYPE scalar)
Succinct Dims-scalar division.
Definition: ge211_geometry.hxx:238
ge211::geometry::Rect::Coordinate
COORDINATE Coordinate
The coordinate type for the rectangle.
Definition: ge211_geometry.hxx:464
ge211::geometry::make_rect
Rect< COORDINATE > make_rect(COORDINATE x, COORDINATE y, COORDINATE width, COORDINATE height)
Constructs a Rect given its member variables.
Definition: ge211_geometry.hxx:980
ge211::geometry::Posn::y
Coordinate y
The y coordiante.
Definition: ge211_geometry.hxx:276
ge211::geometry::Posn::up_left_by
Posn up_left_by(Dims_type dims) const
Constructs the position that is above and left of this position by the given dimensions.
Definition: ge211_geometry.hxx:424
ge211::geometry::Posn::Posn
Posn(Dims_type dims)
Constructs a position from a Dims, which gives the displacement of the position from the origin.
Definition: ge211_geometry.hxx:296
ge211::geometry::Transform::is_identity
bool is_identity() const
Is this transformation the identity transformation that does nothing? Because floating point is appro...
Definition: ge211_geometry.cxx:107
ge211::geometry::Posn< int >::Coordinate
int Coordinate
The coordinate type for the position.
Definition: ge211_geometry.hxx:269
ge211::geometry::Rect::iterator::operator->
Posn_type const * operator->() const
Returns a pointer to the current Posn of this iterator.
Definition: ge211_geometry.hxx:692
ge211::geometry::Posn::Posn
Posn(origin_type)
Constructs the origin when given the_origin.
Definition: ge211_geometry.hxx:289
ge211::geometry::Rect::Rect
Rect()
Default-constructs the zero-sized Rect at the origin.
Definition: ge211_geometry.hxx:492
ge211::geometry::Dims::operator*
Dims< RESULT_COORD > operator*(Dims< OTHER_COORD > that) const
Multiplies two Dimses.
Definition: ge211_geometry.hxx:163
ge211::geometry::Rect::center
Posn_type center() const
The position of the center of the rectangle.
Definition: ge211_geometry.hxx:591
ge211::geometry::Rect::Rect
Rect(const Rect< FROM_COORD > &that)
Casts or converts a Rect to a Rect of a different coordinate type.
Definition: ge211_geometry.hxx:504
ge211::geometry::Transform::set_scale_x
Transform & set_scale_x(double)
Modifies this transform to scale the sprite horizontally.
Definition: ge211_geometry.cxx:70
ge211::geometry::Rect::bottom_left
Posn_type bottom_left() const
The position of the bottom left vertex.
Definition: ge211_geometry.hxx:577
ge211::geometry::Dims::operator/
Dims operator/(ARITHMETIC_TYPE scalar) const
Divides a Dims by a scalar.
Definition: ge211_geometry.hxx:184
ge211::geometry::Transform::get_scale_y
double get_scale_y() const
Returns how much the sprite will be scaled vertically.
Definition: ge211_geometry.cxx:102
ge211::geometry::Dims::width
Coordinate width
The width of the object.
Definition: ge211_geometry.hxx:40
ge211::geometry::Transform::set_scale
Transform & set_scale(double)
Modifies this transform to scale the sprite by the given amount in both dimensions.
Definition: ge211_geometry.cxx:63
ge211::geometry::Rect::from_bottom_left
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.
Definition: ge211_geometry.hxx:621
ge211::geometry::Dims::Dims
Dims()
Default-constructs the zero-sized Dims.
Definition: ge211_geometry.hxx:53
ge211::geometry::Posn::up_by
Posn up_by(Coordinate dy) const
Constructs the position that is above this position by the given amount.
Definition: ge211_geometry.hxx:392
ge211::geometry::Transform::Transform
Transform()
Constructs the identity transform, which has no effect.
Definition: ge211_geometry.cxx:9
ge211::geometry::Posn::operator+=
Posn & operator+=(Dims_type dims)
Succinct position translation.
Definition: ge211_geometry.hxx:372
ge211::geometry::Rect::height
Coordinate height
The height of the rectangle in pixels.
Definition: ge211_geometry.hxx:477
ge211::geometry::Rect::operator!=
bool operator!=(const Rect &that) const
Disequality for rectangles.
Definition: ge211_geometry.hxx:543
ge211::geometry::Transform
A rendering transformation, which can scale, flip, and rotate.
Definition: ge211_geometry.hxx:793
ge211::geometry::Posn::Posn
Posn(const Posn< FROM_COORD > &that)
Casts or converts a Posn to a Posn of a different coordinate type.
Definition: ge211_geometry.hxx:309
ge211::geometry::Posn
A position in the COORDINATE-valued Cartesian plane, where COORDINATE can be any arithmetic type.
Definition: ge211_geometry.hxx:266
ge211::geometry::Transform::get_flip_v
bool get_flip_v() const
Returns whether the sprite will be flipped vertically.
Definition: ge211_geometry.cxx:92
ge211::geometry::Dims< int >::Coordinate
int Coordinate
The coordinate type for the dimensions.
Definition: ge211_geometry.hxx:38
ge211::geometry::Transform::get_flip_h
bool get_flip_h() const
Returns whether the sprite will be flipped horizontally.
Definition: ge211_geometry.cxx:87
ge211::geometry::Rect
Represents a positioned rectangle.
Definition: ge211_geometry.hxx:461
std::size_t
ge211::geometry::Transform::inverse
Transform inverse() const
Returns the inverse of this transform.
Definition: ge211_geometry.cxx:123
ge211::geometry::Rect::top_right
Posn_type top_right() const
The position of the top right vertex.
Definition: ge211_geometry.hxx:570
ge211::geometry::Rect::from_top_right
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.
Definition: ge211_geometry.hxx:613
ge211::geometry::Rect::operator==
bool operator==(const Rect &that) const
Equality for rectangles.
Definition: ge211_geometry.hxx:533
ge211::geometry::Dims::operator-
Dims operator-(Dims that) const
Subtracts two Dimses. This is vector subtraction.
Definition: ge211_geometry.hxx:138
ge211::geometry::Transform::operator*
Transform operator*(const Transform &other) const
Composes two transforms to combine both of their effects.
Definition: ge211_geometry.cxx:112
ge211::geometry::Dims::operator+
Dims operator+(Dims that) const
Adds two Dimses. This is vector addition.
Definition: ge211_geometry.hxx:131
ge211::geometry::Dims::operator<
bool operator<(Dims that) const
Less-than for Dims.
Definition: ge211_geometry.hxx:118
ge211::geometry::Transform::get_rotation
double get_rotation() const
Returns the rotation that will be applied to the sprite.
Definition: ge211_geometry.cxx:82
ge211::geometry::Dims::Dims
Dims(Coordinate width, Coordinate height)
Constructs a dimensions from the given width and height.
Definition: ge211_geometry.hxx:47
ge211::geometry::Rect::iterator::operator++
iterator & operator++()
Pre-increments, advancing this iterator to the next Posn.
Definition: ge211_geometry.hxx:698
ge211::geometry::origin_type
The type of the special value the_origin.
Definition: ge211_geometry.hxx:26
ge211::geometry::Posn::down_by
Posn down_by(Coordinate dy) const
Constructs the position that is below this position by the given amount.
Definition: ge211_geometry.hxx:400
std::hash
ge211::geometry::Posn::into
ge211::Posn< TO_COORD > into() const
Explicitly converts a Posn to another coordinate type.
Definition: ge211_geometry.hxx:324
ge211::geometry::Rect::bottom_right
Posn_type bottom_right() const
The position of the bottom right vertex.
Definition: ge211_geometry.hxx:584
ge211::geometry::Dims::operator-=
Dims & operator-=(Dims that)
Succinct Dims subtraction.
Definition: ge211_geometry.hxx:202
ge211::geometry::Rect::iterator
An iterator over the Posn<COORDINATE>s of a Rect<COORDINATE>.
Definition: ge211_geometry.hxx:683