n/basis: simplify fractional point extraction

This commit is contained in:
Danny Robson 2015-09-29 18:07:12 +10:00
parent 50c1088918
commit a03d407204
4 changed files with 4 additions and 16 deletions

View File

@ -51,10 +51,7 @@ namespace util { namespace noise { namespace basis {
patch<T>::operator () (point2<T> p) const
{
// extract integer and fractional parts. be careful to always round down
// (particularly with negatives) and avoid rounding errors.
auto p_int = p.template cast<intmax_t> ();
if (p.x < 0) p_int.x -= 1;
if (p.y < 0) p_int.y -= 1;
auto p_int = floor (p).template cast<intmax_t> ();
auto p_rem = (p - p_int).template as<point> ();
static const util::vector2i OFFSETS[] = {

View File

@ -47,10 +47,7 @@ namespace util { namespace noise { namespace basis {
perlin<T,L,G>::operator() (util::point<2,T> p) const
{
// extract integer and fractional parts. be careful to always round down
// (particularly with negatives) and avoid rounding errors.
auto p_int = p.template cast<intmax_t> ();
if (p.x < 0) p_int.x -= 1;
if (p.y < 0) p_int.y -= 1;
auto p_int = floor (p).template cast<intmax_t> ();
auto p_rem = p - p_int;
// generate the corner positions

View File

@ -62,10 +62,7 @@ namespace util { namespace noise { namespace basis {
value<T,L>::operator() (util::point<2,T> p) const
{
// extract integer and fractional parts. be careful to always round down
// (particularly with negatives) and avoid rounding errors.
auto p_int = p.template cast<intmax_t> ();
if (p.x < 0) p_int.x -= 1;
if (p.y < 0) p_int.y -= 1;
auto p_int = floor (p).template cast<intmax_t> ();
auto p_rem = p - p_int;
// generate the corner points

View File

@ -64,10 +64,7 @@ namespace util { namespace noise { namespace basis {
worley<T,F>::operator() (util::point<2,T> p) const
{
// extract integer and fractional parts. be careful to always round down
// (particularly with negatives) and avoid rounding errors.
auto p_int = p.template cast<intmax_t> ();
if (p.x < 0) p_int.x -= 1;
if (p.y < 0) p_int.y -= 1;
auto p_int = floor (p).template cast<intmax_t> ();
auto p_rem = (p - p_int).template as<point> ();
// setup an array of distances