extent: add a point inclusion query

This commit is contained in:
Danny Robson 2015-09-16 02:26:00 +10:00
parent 4fad54f0b0
commit 118d1accce
2 changed files with 19 additions and 1 deletions

View File

@ -19,6 +19,8 @@
#include "coord.hpp" #include "coord.hpp"
#include "vector.hpp" #include "vector.hpp"
#include "point.hpp"
#include <iostream> #include <iostream>
@ -40,6 +42,9 @@ namespace util {
template <typename U = float> template <typename U = float>
U aspect (void) const; U aspect (void) const;
template <typename U>
bool includes (util::point<S,U>) const;
extent expanded (vector<S,T>) const; extent expanded (vector<S,T>) const;
extent expanded (T) const; extent expanded (T) const;
extent contracted (vector<S,T>) const; extent contracted (vector<S,T>) const;

View File

@ -24,7 +24,7 @@
#include <algorithm> #include <algorithm>
//----------------------------------------------------------------------------- ///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T> template <size_t S, typename T>
template <typename U> template <typename U>
U U
@ -32,3 +32,16 @@ util::extent<S,T>::aspect (void) const
{ {
return static_cast<U> (this->w) / this->h; return static_cast<U> (this->w) / this->h;
} }
///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T>
template <typename U>
bool
util::extent<S,T>::includes (point<S,U> p) const
{
for (size_t i = 0; i < S; ++i)
if (p[i] < 0 || static_cast<T> (p[i]) >= this->data[i])
return false;
return true;
}