diff --git a/Makefile.am b/Makefile.am index 62c87679..c39558f3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,6 +15,7 @@ UTIL_INCLUDE = \ enable_if.hpp \ endian.hpp \ except.hpp \ + extent.hpp \ fixed.hpp \ float.hpp \ fwd.hpp \ @@ -46,6 +47,7 @@ UTIL_FILES = \ debug.cpp \ endian.cpp \ except.cpp \ + extent.cpp \ fixed.cpp \ float.cpp \ guid.cpp \ diff --git a/extent.cpp b/extent.cpp new file mode 100644 index 00000000..fe984b5a --- /dev/null +++ b/extent.cpp @@ -0,0 +1,79 @@ +/* + * 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 "extent.hpp" + +#include "debug.hpp" +#include "maths.hpp" + +#include + +using namespace util; + + +template +extent::extent (const T _width, const T _height): + width (_width), + height (_height) + { ; } + + +template +T +extent::diameter (void) const { + return (T)sqrt (width * width + height * height); +} + + +template +T +extent::area (void) const + { return width * height; } + + +template +bool +extent::empty (void) const + { return almost_equal (area(), 0); } + + +template +bool +extent::operator ==(const extent& rhs) const { + return almost_equal (width, rhs.width) && + almost_equal (height, rhs.height); +} + + +template +void +extent::sanity (void) const + { check (width >= 0 && height >= 0); } + + +namespace util { + template <> + void + extent::sanity (void) const + { return; } +} + +template struct extent; +template struct extent; + diff --git a/extent.hpp b/extent.hpp new file mode 100644 index 00000000..fa560697 --- /dev/null +++ b/extent.hpp @@ -0,0 +1,47 @@ +/* + * 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 + */ + +#ifndef __UTIL_EXTENT_HPP +#define __UTIL_EXTENT_HPP + +namespace util { + /** + * A pure two-dimensional size, without positioning + */ + template + struct extent { + T width, height; + + extent (const T _width, const T _height); + + T area (void) const; + T diameter (void) const; + + bool empty (void) const; + + bool operator ==(const extent& rhs) const; + bool operator !=(const extent& rhs) const + { return !(*this == rhs); } + + void sanity (void) const; + }; +} + +#endif + diff --git a/region.cpp b/region.cpp index d305dea2..a8c81895 100644 --- a/region.cpp +++ b/region.cpp @@ -28,62 +28,6 @@ using namespace util; -/* - * Rect - */ -template -extent::extent (const T _width, const T _height): - width (_width), - height (_height) - { ; } - - -template -T -extent::diameter (void) const { - return (T)sqrt (width * width + height * height); -} - - -template -T -extent::area (void) const - { return width * height; } - - -template -bool -extent::empty (void) const - { return almost_equal (area(), 0); } - - -template -bool -extent::operator ==(const extent& rhs) const { - return almost_equal (width, rhs.width) && - almost_equal (height, rhs.height); -} - - -template -void -extent::sanity (void) const - { check (width >= 0 && height >= 0); } - - -namespace util { - template <> - void - extent::sanity (void) const - { return; } -} - -template struct extent; -template struct extent; - -/* - * Region - */ template region::region (T _x, T _y, T _width, T _height): diff --git a/region.hpp b/region.hpp index a8e6f46a..7da7e687 100644 --- a/region.hpp +++ b/region.hpp @@ -24,28 +24,6 @@ #include "point.hpp" namespace util { - /** - * A pure two-dimensional size, without positioning - */ - template - struct extent { - T width, height; - - extent (const T _width, const T _height); - - T area (void) const; - T diameter (void) const; - - bool empty (void) const; - - bool operator ==(const extent& rhs) const; - bool operator !=(const extent& rhs) const - { return !(*this == rhs); } - - void sanity (void) const; - }; - - /** * A two-dimensional rectangle, with size and position. */