2003-03-26 19:57:29 +08:00
|
|
|
//
|
|
|
|
// ZoneMinder Box Class Interfaces, $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_BOX_H
|
|
|
|
#define ZM_BOX_H
|
|
|
|
|
|
|
|
#include "zm_coord.h"
|
2015-05-18 08:18:54 +08:00
|
|
|
#include <cmath>
|
2005-02-24 18:43:29 +08:00
|
|
|
|
2003-03-26 19:57:29 +08:00
|
|
|
//
|
|
|
|
// Class used for storing a box, which is defined as a region
|
|
|
|
// defined by two coordinates
|
|
|
|
//
|
2020-03-05 03:14:38 +08:00
|
|
|
class Box {
|
2003-03-26 19:57:29 +08:00
|
|
|
private:
|
2016-04-04 22:11:48 +08:00
|
|
|
Coord lo, hi;
|
|
|
|
Coord size;
|
2003-03-26 19:57:29 +08:00
|
|
|
|
|
|
|
public:
|
2020-03-05 03:14:38 +08:00
|
|
|
inline Box() { }
|
2017-11-16 22:15:04 +08:00
|
|
|
explicit inline Box( int p_size ) : lo( 0, 0 ), hi ( p_size-1, p_size-1 ), size( Coord::Range( hi, lo ) ) { }
|
2016-04-04 22:11:48 +08:00
|
|
|
inline Box( int p_x_size, int p_y_size ) : lo( 0, 0 ), hi ( p_x_size-1, p_y_size-1 ), size( Coord::Range( hi, lo ) ) { }
|
|
|
|
inline Box( int lo_x, int lo_y, int hi_x, int hi_y ) : lo( lo_x, lo_y ), hi( hi_x, hi_y ), size( Coord::Range( hi, lo ) ) { }
|
|
|
|
inline Box( const Coord &p_lo, const Coord &p_hi ) : lo( p_lo ), hi( p_hi ), size( Coord::Range( hi, lo ) ) { }
|
2003-03-26 19:57:29 +08:00
|
|
|
|
2020-03-05 03:14:38 +08:00
|
|
|
inline const Coord &Lo() const { return lo; }
|
|
|
|
inline int LoX() const { return lo.X(); }
|
2020-12-16 05:32:41 +08:00
|
|
|
inline int LoX(int p_lo_x) { return lo.X(p_lo_x); }
|
2020-03-05 03:14:38 +08:00
|
|
|
inline int LoY() const { return lo.Y(); }
|
2020-12-16 05:32:41 +08:00
|
|
|
inline int LoY(int p_lo_y) { return lo.Y(p_lo_y); }
|
2020-03-05 03:14:38 +08:00
|
|
|
inline const Coord &Hi() const { return hi; }
|
|
|
|
inline int HiX() const { return hi.X(); }
|
2020-12-16 05:32:41 +08:00
|
|
|
inline int HiX(int p_hi_x) { return hi.X(p_hi_x); }
|
2020-03-05 03:14:38 +08:00
|
|
|
inline int HiY() const { return hi.Y(); }
|
2020-12-16 05:32:41 +08:00
|
|
|
inline int HiY(int p_hi_y) { return hi.Y(p_hi_y); }
|
2020-03-05 03:14:38 +08:00
|
|
|
inline const Coord &Size() const { return size; }
|
|
|
|
inline int Width() const { return size.X(); }
|
|
|
|
inline int Height() const { return size.Y(); }
|
|
|
|
inline int Area() const { return size.X()*size.Y(); }
|
2003-03-26 19:57:29 +08:00
|
|
|
|
2020-03-05 03:14:38 +08:00
|
|
|
inline const Coord Centre() const {
|
2021-02-04 06:56:42 +08:00
|
|
|
int mid_x = int(std::round(lo.X()+(size.X()/2.0)));
|
|
|
|
int mid_y = int(std::round(lo.Y()+(size.Y()/2.0)));
|
2020-03-05 03:14:38 +08:00
|
|
|
return Coord( mid_x, mid_y );
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
|
|
|
inline bool Inside( const Coord &coord ) const
|
|
|
|
{
|
|
|
|
return( coord.X() >= lo.X() && coord.X() <= hi.X() && coord.Y() >= lo.Y() && coord.Y() <= hi.Y() );
|
|
|
|
}
|
2003-03-26 19:57:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ZM_BOX_H
|