From 912228f87b0dc2206680b549d78837a7bffe4939 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 18 May 2015 14:42:28 +1000 Subject: [PATCH] noise: move lerp into noise namespace --- Makefile.am | 4 ++-- noise/basis.cpp | 12 ++++++------ noise/basis.hpp | 2 +- noise/fractal.cpp | 16 ++++++++-------- lerp.cpp => noise/lerp.cpp | 12 ++++++------ lerp.hpp => noise/lerp.hpp | 8 ++++---- tools/noise.cpp | 6 ++++-- 7 files changed, 31 insertions(+), 29 deletions(-) rename lerp.cpp => noise/lerp.cpp (85%) rename lerp.hpp => noise/lerp.hpp (90%) diff --git a/Makefile.am b/Makefile.am index 9c0d8436..7c579b59 100644 --- a/Makefile.am +++ b/Makefile.am @@ -100,8 +100,6 @@ UTIL_FILES = \ json/schema.hpp \ json/tree.cpp \ json/tree.hpp \ - lerp.cpp \ - lerp.hpp \ log.cpp \ log.hpp \ log.ipp \ @@ -132,6 +130,8 @@ UTIL_FILES = \ noise/basis.hpp \ noise/fractal.cpp \ noise/fractal.hpp \ + noise/lerp.cpp \ + noise/lerp.hpp \ noise/lut.cpp \ noise/lut.hpp \ options.cpp \ diff --git a/noise/basis.cpp b/noise/basis.cpp index 032edc86..a1eb594d 100644 --- a/noise/basis.cpp +++ b/noise/basis.cpp @@ -132,9 +132,9 @@ value::eval (double x, double y) const { //----------------------------------------------------------------------------- namespace util { namespace noise { - template struct value; - template struct value; - template struct value; + template struct value; + template struct value; + template struct value; } } @@ -196,9 +196,9 @@ gradient::eval (double x, double y) const { //----------------------------------------------------------------------------- namespace util { namespace noise { - template struct gradient; - template struct gradient; - template struct gradient; + template struct gradient; + template struct gradient; + template struct gradient; } } diff --git a/noise/basis.hpp b/noise/basis.hpp index 74c27914..9f7e6dd4 100644 --- a/noise/basis.hpp +++ b/noise/basis.hpp @@ -18,7 +18,7 @@ #define __UTIL_NOISE_BASIS_HPP #include -#include "../lerp.hpp" +#include "lerp.hpp" #include "../range.hpp" namespace util { diff --git a/noise/fractal.cpp b/noise/fractal.cpp index a6c0b71b..d502a250 100644 --- a/noise/fractal.cpp +++ b/noise/fractal.cpp @@ -91,10 +91,10 @@ util::noise::fbm::eval (double x, double y) const { //----------------------------------------------------------------------------- template struct util::noise::fbm; -template struct util::noise::fbm>; -template struct util::noise::fbm>; -template struct util::noise::fbm>; -template struct util::noise::fbm>; +template struct util::noise::fbm>; +template struct util::noise::fbm>; +template struct util::noise::fbm>; +template struct util::noise::fbm>; /////////////////////////////////////////////////////////////////////////////// @@ -157,8 +157,8 @@ util::noise::musgrave::eval (double x, double y) const { //----------------------------------------------------------------------------- template struct util::noise::musgrave; -template struct util::noise::musgrave>; -template struct util::noise::musgrave>; -template struct util::noise::musgrave>; -template struct util::noise::musgrave>; +template struct util::noise::musgrave>; +template struct util::noise::musgrave>; +template struct util::noise::musgrave>; +template struct util::noise::musgrave>; diff --git a/lerp.cpp b/noise/lerp.cpp similarity index 85% rename from lerp.cpp rename to noise/lerp.cpp index bd80e072..a9a646ec 100644 --- a/lerp.cpp +++ b/noise/lerp.cpp @@ -24,19 +24,19 @@ //----------------------------------------------------------------------------- double -lerp::sigmoid (double val) { +util::lerp::sigmoid (double val) { return -1.0 + 2.0 / (1.0 + exp (-2.0 * val)); } //----------------------------------------------------------------------------- -double lerp::trunc (double a, double, double) +double util::lerp::trunc (double a, double, double) { return a; } //----------------------------------------------------------------------------- double -lerp::linear (double a, double b, double weight) { +util::lerp::linear (double a, double b, double weight) { CHECK (weight >= 0.0 && weight <= 1.0); return a * (1.0 - weight) + b * weight; } @@ -44,7 +44,7 @@ lerp::linear (double a, double b, double weight) { //----------------------------------------------------------------------------- double -lerp::cosine (double a, double b, double weight) { +util::lerp::cosine (double a, double b, double weight) { CHECK (weight >= 0.0 && weight <= 1.0); double t = (1.0 - cos (weight * PI)) * 0.5; @@ -54,7 +54,7 @@ lerp::cosine (double a, double b, double weight) { //----------------------------------------------------------------------------- double -lerp::cubic (double a, double b, double weight) { +util::lerp::cubic (double a, double b, double weight) { CHECK (weight >= 0.0 && weight <= 1.0); double t = weight * weight * (3.0 - 2.0 * weight); return a * (1.0 - t) + b * t; @@ -63,7 +63,7 @@ lerp::cubic (double a, double b, double weight) { //----------------------------------------------------------------------------- double -lerp::quintic (double a, double b, double weight) { +util::lerp::quintic (double a, double b, double weight) { CHECK (weight >= 0.0 && weight <= 1.0); double t = weight * weight * weight * (weight * (weight * 6.0 - 15.0) + 10.0); return a * (1.0 - t) + b * t; diff --git a/lerp.hpp b/noise/lerp.hpp similarity index 90% rename from lerp.hpp rename to noise/lerp.hpp index 5aa81101..48d01b5a 100644 --- a/lerp.hpp +++ b/noise/lerp.hpp @@ -14,10 +14,10 @@ * Copyright 2011 Danny Robson */ -#ifndef __UTIL_LERP_HPP -#define __UTIL_LERP_HPP +#ifndef __UTIL_NOISE_LERP_HPP +#define __UTIL_NOISE_LERP_HPP -namespace lerp { +namespace util { namespace lerp { double sigmoid (double val); double linear (double a, double b, double weight); @@ -25,6 +25,6 @@ namespace lerp { double cubic (double a, double b, double weight); double quintic (double a, double b, double weight); double trunc (double a, double b, double weight); -} +} } #endif diff --git a/tools/noise.cpp b/tools/noise.cpp index 99b81e84..4e3e097d 100644 --- a/tools/noise.cpp +++ b/tools/noise.cpp @@ -1,6 +1,6 @@ #include "image.hpp" #include "noise.hpp" -#include "lerp.hpp" +#include "noise/lerp.hpp" int main (void) @@ -11,7 +11,9 @@ main (void) //using basis_t = util::noise::gradient; //using noise_t = util::noise::fbm; - using noise_t = util::noise::fbm>; + //using noise_t = util::noise::fbm>; + //using noise_t = util::noise::musgrave>; + using noise_t = util::noise::fbm; util::noise::fill (img, noise_t {});