#include <FractalNoise1D/FractalNoise1D.hpp>

void FractalNoise1D::addLayer(GeneratorNode genNode, uint64_t period, float amplitude)
{
    layers.push_back({Perlin1D(genNode), period, amplitude});
}

float FractalNoise1D::sample(uint64_t t)
{
    float sum = 0.0f;
    for (Layer &layer : layers)
    {
        uint64_t tempPoint = t / layer.controlPeriod;
        float tempOffset = static_cast<float>(t % layer.controlPeriod) / static_cast<float>(layer.controlPeriod);

        sum += layer.amplitude * layer.perlin.sample(tempPoint, tempOffset);
    }

    return sum;
}