geom/aabb: make the equality operator a free function

This commit is contained in:
Danny Robson 2017-08-24 17:08:37 +10:00
parent 56444b4a50
commit 94e02fced4
2 changed files with 17 additions and 16 deletions

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
* Copyright 2015 Danny Robson <danny@nerdcruft.net> * Copyright 2015-2017 Danny Robson <danny@nerdcruft.net>
*/ */
@ -23,6 +23,7 @@
using util::geom::aabb; using util::geom::aabb;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
aabb<S,T>::aabb (point<S,T> _p0, point<S,T> _p1): aabb<S,T>::aabb (point<S,T> _p0, point<S,T> _p1):
@ -158,16 +159,6 @@ aabb<S,T>::operator- (vector<S,T> v) const
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T>
bool
aabb<S,T>::operator== (const aabb<S,T> rhs) const
{
return rhs.p0 == p0 && rhs.p1 == p1;
}
//-----------------------------------------------------------------------------
namespace util::debug { namespace util::debug {
template <size_t S, typename T> template <size_t S, typename T>
struct validator<aabb<S,T>> { struct validator<aabb<S,T>> {

View File

@ -11,12 +11,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
* Copyright 2015-2016 Danny Robson <danny@nerdcruft.net> * Copyright 2015-2017 Danny Robson <danny@nerdcruft.net>
*/ */
#ifndef __UTIL_GEOM_AABB_HPP #ifndef CRUFT_UTIL_GEOM_AABB_HPP
#define __UTIL_GEOM_AABB_HPP #define CRUFT_UTIL_GEOM_AABB_HPP
#include "../point.hpp" #include "../point.hpp"
#include "../extent.hpp" #include "../extent.hpp"
@ -24,6 +24,7 @@
#include <cstdint> #include <cstdint>
namespace util::geom { namespace util::geom {
///////////////////////////////////////////////////////////////////////////
template <size_t S, typename T> template <size_t S, typename T>
struct aabb { struct aabb {
aabb () = default; aabb () = default;
@ -47,12 +48,21 @@ namespace util::geom {
aabb<S,T> operator+ (vector<S,T>) const; aabb<S,T> operator+ (vector<S,T>) const;
aabb<S,T> operator- (vector<S,T>) const; aabb<S,T> operator- (vector<S,T>) const;
bool operator== (aabb) const;
point<S,T> p0; point<S,T> p0;
point<S,T> p1; point<S,T> p1;
}; };
///////////////////////////////////////////////////////////////////////////
template <std::size_t S, typename T>
constexpr bool
operator== (const aabb<S,T> &a, const aabb<S,T> &b) noexcept
{
return a.p0 == b.p0 && a.p1 == b.p1;
}
///////////////////////////////////////////////////////////////////////////
typedef aabb<2,float> aabb2f; typedef aabb<2,float> aabb2f;
typedef aabb<2,unsigned> aabb2u; typedef aabb<2,unsigned> aabb2u;
typedef aabb<2,int> aabb2i; typedef aabb<2,int> aabb2i;