#ifndef PERLIN_2D_HPP_
#define PERLIN_2D_HPP_

#include <unordered_map>

#include <GeneratorNode/GeneratorNode.hpp>

/**
 * @brief Represents a 2D perlin noise generator.
 */
class Perlin2D
{
private:
    GeneratorNode genNode;

    std::unordered_map<uint64_t, float> angleMap;

    float getAngleAt(uint32_t chunkX, uint32_t chunkY, uint32_t order);
    float interpolate(float a, float b, float t);
    float evaluateVector(float offsetX, float offsetY, float angle);

public:
    /**
     * @brief Construct the perline noise map for the specified node.
     */
    Perlin2D(GeneratorNode node);

    /**
     * @brief Sample the noise at the specified coordinates with the specified order.
     */
    float sample(int x, int y, uint32_t order);

    /**
     * @brief Sample the fractal noise at the specified coordinates.
     * 
     * @param x The X coordinate to sample at.
     * @param y The Y coordinate to sample at.
     * @param numOctaves Number of octaves (layers of noise).
     * @param initialAmplitude The amplitude of the first octave.
     * @param persistence The factor by which successive octaves' influence evolves. 
     * @return float The sampled value.
     */
    float sampleFractal(int x, int y, int numOctaves, float initialAmplitude, float persistence);
};

#endif