Coords.hpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #ifndef NOMLIB_COORDS_HEADERS
30 #define NOMLIB_COORDS_HEADERS
31 
32 #include <algorithm>
33 
34 #include "nomlib/config.hpp"
35 
36 namespace nom {
37 
38 const std::string coords_delimiter = ", ";
39 
44 class Coords
45 {
46  public:
48  Coords ( void );
49 
51  ~Coords ( void );
52 
54  Coords ( const Coords& coords );
55 
57  Coords ( int32 x, int32 y, int32 width, int32 height );
58 
60  Coords ( int32 x, int32 y );
61 
66  bool isNull ( void ) const;
67 
69  const Coords& get ( void ) const;
70 
71  Coords getPosition ( void ) const;
72  void setPosition ( int32 x, int32 y );
73 
74  Coords getSize ( void ) const;
75  void setSize ( int32 width, int32 height );
76 
79  bool contains ( int32 x, int32 y ) const;
80 
85  bool contains ( const Coords& pos ) const;
86 
88  bool intersects ( Coords& rectangle ) const;
89 
91  Coords& operator = ( const Coords& other );
92 
94  static const Coords null;
95 
96  public:
97  int32 x;
98  int32 y;
99  int32 width;
100  int32 height;
101 
103  int32& w = width;
104 
106  int32& h = height;
107 };
108 
116 std::ostream& operator << ( std::ostream& os, const Coords& coords );
117 
118 bool operator == ( const Coords& left, const Coords& right );
119 bool operator != ( const Coords& left, const Coords& right );
120 Coords operator + ( const Coords& left, const Coords& right );
121 Coords operator ++ ( Coords& left );
122 Coords operator - ( const Coords& left, const Coords& right );
123 Coords operator -- ( Coords& left );
124 Coords operator * ( const Coords& left, const Coords& right );
125 Coords operator / ( const Coords& left, const Coords& right );
126 Coords& operator += ( Coords& left, const Coords& right );
127 Coords& operator -= ( Coords& left, const Coords& right );
128 Coords& operator *= ( Coords& left, const Coords& right );
129 
130 
131 } // namespace nom
132 
133 #endif // NOMLIB_COORDS_HEADERS defined
Coords & operator=(const Coords &other)
Copy assignment operator.
Definition: Coords.cpp:140
bool isNull(void) const
Definition: Coords.cpp:116
~Coords(void)
Destructor.
Definition: Coords.cpp:37
static const Coords null
Convenience object that will always contain a value of -1.
Definition: Coords.hpp:94
Coords(void)
Default constructor; sets all values to their respective defaults.
Definition: Coords.cpp:35
int32 & h
Reference alias for height instance variable.
Definition: Coords.hpp:106
bool intersects(Coords &rectangle) const
Checks to see if our rectangle overlaps with another.
Definition: Coords.cpp:89
bool contains(int32 x, int32 y) const
Definition: Coords.cpp:76
Coordinate values (x, y, z, width, height ) wrapper.
Definition: Coords.hpp:44
int32 & w
Reference alias for width instance variable.
Definition: Coords.hpp:103