2003-03-26 19:57:29 +08:00
|
|
|
//
|
|
|
|
// ZoneMinder Coordinate Class Interface, $Date$, $Revision$
|
2008-07-25 17:33:23 +08:00
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
2003-03-26 19:57:29 +08:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2016-12-26 23:23:16 +08:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2003-03-26 19:57:29 +08:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ZM_COORD_H
|
|
|
|
#define ZM_COORD_H
|
|
|
|
|
2021-02-04 11:47:28 +08:00
|
|
|
#include "zm_define.h"
|
2003-03-26 19:57:29 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Class used for storing an x,y pair, i.e. a coordinate
|
|
|
|
//
|
2020-03-05 03:14:38 +08:00
|
|
|
class Coord {
|
2003-03-26 19:57:29 +08:00
|
|
|
private:
|
2016-04-04 22:11:48 +08:00
|
|
|
int x, y;
|
2003-03-26 19:57:29 +08:00
|
|
|
|
|
|
|
public:
|
2017-11-16 22:15:04 +08:00
|
|
|
inline Coord() : x(0), y(0) { }
|
|
|
|
inline Coord( int p_x, int p_y ) : x(p_x), y(p_y) { }
|
|
|
|
inline Coord( const Coord &p_coord ) : x(p_coord.x), y(p_coord.y) { }
|
|
|
|
inline Coord &operator =( const Coord &coord ) {
|
|
|
|
x = coord.x;
|
|
|
|
y = coord.y;
|
|
|
|
return *this;
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2020-12-16 05:32:41 +08:00
|
|
|
inline int &X(int p_x) { x=p_x; return x; }
|
|
|
|
inline const int &X() const { return x; }
|
|
|
|
inline int &Y(int p_y) { y=p_y; return y; }
|
|
|
|
inline const int &Y() const { return y; }
|
2003-03-26 19:57:29 +08:00
|
|
|
|
2020-03-05 03:14:38 +08:00
|
|
|
inline static Coord Range( const Coord &coord1, const Coord &coord2 ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
Coord result( (coord1.x-coord2.x)+1, (coord1.y-coord2.y)+1 );
|
2020-12-16 05:32:41 +08:00
|
|
|
return result;
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2003-03-26 19:57:29 +08:00
|
|
|
|
2020-11-02 05:11:19 +08:00
|
|
|
inline bool operator==( const Coord &coord ) const { return( x == coord.x && y == coord.y ); }
|
|
|
|
inline bool operator!=( const Coord &coord ) const { return( x != coord.x || y != coord.y ); }
|
|
|
|
inline bool operator>( const Coord &coord ) const { return( x > coord.x && y > coord.y ); }
|
|
|
|
inline bool operator>=( const Coord &coord ) const { return( !(operator<(coord)) ); }
|
|
|
|
inline bool operator<( const Coord &coord ) const { return( x < coord.x && y < coord.y ); }
|
|
|
|
inline bool operator<=( const Coord &coord ) const { return( !(operator>(coord)) ); }
|
2016-04-04 22:11:48 +08:00
|
|
|
inline Coord &operator+=( const Coord &coord ) { x += coord.x; y += coord.y; return( *this ); }
|
|
|
|
inline Coord &operator-=( const Coord &coord ) { x -= coord.x; y -= coord.y; return( *this ); }
|
2003-03-26 19:57:29 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
inline friend Coord operator+( const Coord &coord1, const Coord &coord2 ) { Coord result( coord1 ); result += coord2; return( result ); }
|
|
|
|
inline friend Coord operator-( const Coord &coord1, const Coord &coord2 ) { Coord result( coord1 ); result -= coord2; return( result ); }
|
2003-03-26 19:57:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ZM_COORD_H
|