2011-06-21 20:26:32 +10:00
|
|
|
/*
|
|
|
|
* This file is part of libgim.
|
|
|
|
*
|
|
|
|
* libgim 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 3 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* libgim 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 libgim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Copyright 2010 Danny Robson <danny@blubinc.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-05-23 17:18:52 +10:00
|
|
|
#include "region.hpp"
|
|
|
|
|
2011-08-15 20:10:43 +10:00
|
|
|
#include "enable_if.hpp"
|
2011-05-23 17:18:52 +10:00
|
|
|
#include "debug.hpp"
|
|
|
|
|
2011-08-15 20:10:43 +10:00
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
using namespace util;
|
2011-05-23 17:18:52 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Rect
|
|
|
|
*/
|
|
|
|
template <typename T>
|
2011-08-15 20:10:43 +10:00
|
|
|
extent<T>::extent (const T _width, const T _height):
|
2011-05-23 17:18:52 +10:00
|
|
|
width (_width),
|
|
|
|
height (_height)
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T
|
2011-08-15 20:10:43 +10:00
|
|
|
extent<T>::area (void) const
|
2011-05-23 17:18:52 +10:00
|
|
|
{ return width * height; }
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool
|
2011-08-15 20:10:43 +10:00
|
|
|
extent<T>::empty (void) const
|
|
|
|
{ return almost_equal (area(), 0); }
|
2011-05-23 17:18:52 +10:00
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool
|
2011-08-15 20:10:43 +10:00
|
|
|
extent<T>::operator ==(const extent& rhs) const {
|
|
|
|
return almost_equal (width, rhs.width) &&
|
|
|
|
almost_equal (height, rhs.height);
|
|
|
|
}
|
2011-05-23 17:18:52 +10:00
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void
|
2011-08-15 20:10:43 +10:00
|
|
|
extent<T>::sanity (void) const
|
2011-05-23 17:18:52 +10:00
|
|
|
{ check (width >= 0 && height >= 0); }
|
|
|
|
|
|
|
|
|
2011-08-15 20:10:43 +10:00
|
|
|
namespace util {
|
|
|
|
template <>
|
|
|
|
void
|
|
|
|
extent<unsigned int>::sanity (void) const
|
|
|
|
{ return; }
|
|
|
|
}
|
2011-05-23 17:18:52 +10:00
|
|
|
|
|
|
|
|
2011-08-15 20:10:43 +10:00
|
|
|
template struct extent<unsigned int>;
|
|
|
|
template struct extent<double>;
|
2011-05-23 17:18:52 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Region
|
|
|
|
*/
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
_region<T>::_region (T _x, T _y, T _width, T _height):
|
|
|
|
x (_x),
|
|
|
|
y (_y),
|
|
|
|
width (_width),
|
|
|
|
height (_height)
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T
|
|
|
|
_region<T>::area (void) const
|
|
|
|
{ return width * height; }
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool
|
|
|
|
_region<T>::empty (void) const
|
|
|
|
{ return area () == 0; }
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool
|
|
|
|
_region<T>::operator ==(const _region& rhs) const
|
|
|
|
{ return x == rhs.x &&
|
|
|
|
y == rhs.y &&
|
|
|
|
width == rhs.width &&
|
|
|
|
height == rhs.height; }
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void _region<T>::sanity (void) const
|
|
|
|
{ check (width >= 0 && height >= 0); }
|