Moved extent to a seperate file

This commit is contained in:
Danny Robson 2011-10-26 21:43:38 +11:00
parent 020a3a4afe
commit d1187ecf3a
5 changed files with 128 additions and 78 deletions

View File

@ -15,6 +15,7 @@ UTIL_INCLUDE = \
enable_if.hpp \ enable_if.hpp \
endian.hpp \ endian.hpp \
except.hpp \ except.hpp \
extent.hpp \
fixed.hpp \ fixed.hpp \
float.hpp \ float.hpp \
fwd.hpp \ fwd.hpp \
@ -46,6 +47,7 @@ UTIL_FILES = \
debug.cpp \ debug.cpp \
endian.cpp \ endian.cpp \
except.cpp \ except.cpp \
extent.cpp \
fixed.cpp \ fixed.cpp \
float.cpp \ float.cpp \
guid.cpp \ guid.cpp \

79
extent.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*
* Copyright 2010 Danny Robson <danny@blubinc.net>
*/
#include "extent.hpp"
#include "debug.hpp"
#include "maths.hpp"
#include <cmath>
using namespace util;
template <typename T>
extent<T>::extent (const T _width, const T _height):
width (_width),
height (_height)
{ ; }
template <typename T>
T
extent<T>::diameter (void) const {
return (T)sqrt (width * width + height * height);
}
template <typename T>
T
extent<T>::area (void) const
{ return width * height; }
template <typename T>
bool
extent<T>::empty (void) const
{ return almost_equal (area(), 0); }
template <typename T>
bool
extent<T>::operator ==(const extent& rhs) const {
return almost_equal (width, rhs.width) &&
almost_equal (height, rhs.height);
}
template <typename T>
void
extent<T>::sanity (void) const
{ check (width >= 0 && height >= 0); }
namespace util {
template <>
void
extent<unsigned int>::sanity (void) const
{ return; }
}
template struct extent<unsigned int>;
template struct extent<double>;

47
extent.hpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*
* Copyright 2010 Danny Robson <danny@blubinc.net>
*/
#ifndef __UTIL_EXTENT_HPP
#define __UTIL_EXTENT_HPP
namespace util {
/**
* A pure two-dimensional size, without positioning
*/
template <typename T>
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

View File

@ -28,62 +28,6 @@
using namespace util; using namespace util;
/*
* Rect
*/
template <typename T>
extent<T>::extent (const T _width, const T _height):
width (_width),
height (_height)
{ ; }
template <typename T>
T
extent<T>::diameter (void) const {
return (T)sqrt (width * width + height * height);
}
template <typename T>
T
extent<T>::area (void) const
{ return width * height; }
template <typename T>
bool
extent<T>::empty (void) const
{ return almost_equal (area(), 0); }
template <typename T>
bool
extent<T>::operator ==(const extent& rhs) const {
return almost_equal (width, rhs.width) &&
almost_equal (height, rhs.height);
}
template <typename T>
void
extent<T>::sanity (void) const
{ check (width >= 0 && height >= 0); }
namespace util {
template <>
void
extent<unsigned int>::sanity (void) const
{ return; }
}
template struct extent<unsigned int>;
template struct extent<double>;
/*
* Region
*/
template <typename T> template <typename T>
region<T>::region (T _x, T _y, T _width, T _height): region<T>::region (T _x, T _y, T _width, T _height):

View File

@ -24,28 +24,6 @@
#include "point.hpp" #include "point.hpp"
namespace util { namespace util {
/**
* A pure two-dimensional size, without positioning
*/
template <typename T>
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. * A two-dimensional rectangle, with size and position.
*/ */