/*
* 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 .
*
* Copyright 2010 Danny Robson
*/
#include "region.hpp"
#include "enable_if.hpp"
#include "debug.hpp"
#include
#include
using namespace util;
template
region::region (T _x, T _y, T _w, T _h):
x (_x),
y (_y),
w (_w),
h (_h)
{ ; }
template
region&
region::operator+= (const vector &rhs) {
x += rhs.x;
y += rhs.y;
return *this;
}
template
T
region::area (void) const
{ return w * h; }
template
T
region::diameter (void) const {
return (T)sqrt (w * w + h * h);
}
template
bool
region::empty (void) const
{ return almost_equal (area (), 0); }
template
point
region::base (void) const {
return { static_cast (x), static_cast (y), 0.0 };
}
template
point
region::centre (void) const {
double cx = x + static_cast(w / 2.0),
cy = y + static_cast(h / 2.0);
return { cx, cy, 0.0 };
}
template
bool
region::includes (const point &p) const {
return p.x >= x &&
p.y >= y &&
p.x <= x + w &&
p.y <= y + h;
}
template
bool
region::contains (const point& p) const {
return p.x > x &&
p.y > y &&
p.x < x + w &&
p.y < y + h;
}
template
bool
region::overlaps (const region &rhs) const {
return x < rhs.x + rhs.w &&
x + w > rhs.x &&
y < rhs.y + rhs.h &&
y + h > rhs.y;
}
template
bool
region::operator ==(const region& rhs) const
{ return almost_equal (x, rhs.x) &&
almost_equal (y, rhs.y) &&
almost_equal (w, rhs.w) &&
almost_equal (h, rhs.h); }
template
void region::sanity (void) const
{ check (w >= 0 && h >= 0); }
namespace util {
template <>
void region::sanity (void) const
{ return; }
template <>
void region::sanity (void) const
{ return; }
}
template
std::ostream&
operator<< (std::ostream &os, const region &rhs) {
os << "region(" << rhs.x << ", " << rhs.y << ", " << rhs.w << ", " << rhs.h << ")";
return os;
}
template struct region;
template struct region;
template struct region;
template std::ostream& operator<< (std::ostream&, const region&);
template std::ostream& operator<< (std::ostream&, const region&);