2024-01-16 14:53:31 -05:00
|
|
|
/*
|
|
|
|
* <Short Description>
|
|
|
|
* Copyright (C) 2024 Brett Terpstra
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GP_IMAGE_TEST_IMAGE_H
|
|
|
|
#define GP_IMAGE_TEST_IMAGE_H
|
|
|
|
|
|
|
|
#define NO_BLT_NAMESPACE_ON_TYPES
|
|
|
|
|
|
|
|
#include <blt/std/types.h>
|
|
|
|
#include <array>
|
|
|
|
#include <optional>
|
|
|
|
#include "blt/std/assert.h"
|
2024-01-19 15:27:32 -05:00
|
|
|
#include <functions.h>
|
2024-01-16 14:53:31 -05:00
|
|
|
|
|
|
|
inline constexpr i32 width = 1024, height = 1024;
|
|
|
|
|
|
|
|
class image
|
|
|
|
{
|
|
|
|
private:
|
2024-01-19 15:27:32 -05:00
|
|
|
std::array<blt::vec3, width * height> data;
|
2024-01-16 14:53:31 -05:00
|
|
|
public:
|
|
|
|
image() = default;
|
|
|
|
|
2024-01-19 15:27:32 -05:00
|
|
|
std::array<blt::vec3, width * height>& getData()
|
|
|
|
{
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
const blt::vec3& get(i32 x, i32 y)
|
2024-01-16 14:53:31 -05:00
|
|
|
{
|
|
|
|
return data[y * height + x];
|
|
|
|
}
|
|
|
|
|
2024-01-19 15:27:32 -05:00
|
|
|
void set(const blt::vec3& c, i32 x, i32 y)
|
2024-01-16 14:53:31 -05:00
|
|
|
{
|
|
|
|
data[y * height + x] = c;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
inline i32 inputs(function_t op)
|
|
|
|
{
|
|
|
|
// don't like this but it'll get compiled out
|
|
|
|
// and we get warnings when new enum is added
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case function_t::ADD:
|
|
|
|
case function_t::SUB:
|
|
|
|
case function_t::MUL:
|
|
|
|
case function_t::DIV:
|
|
|
|
case function_t::EXP:
|
|
|
|
return 2;
|
|
|
|
case function_t::LOG:
|
|
|
|
case function_t::SQRT:
|
|
|
|
case function_t::QUAD:
|
|
|
|
return 1;
|
|
|
|
case function_t::RANDOM:
|
|
|
|
case function_t::NOISE:
|
|
|
|
case function_t::COLOR:
|
|
|
|
case function_t::SCALAR:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BLT_THROW(std::runtime_error("If you are seeing this the universe has broken. Enjoy whatever hellhole is left"));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct op_con
|
|
|
|
{
|
2024-01-16 18:44:50 -05:00
|
|
|
const function_t op;
|
|
|
|
const std::optional<image*> i1, i2;
|
2024-01-16 14:53:31 -05:00
|
|
|
|
|
|
|
op_con(function_t op, const std::optional<image*>& i1, const std::optional<image*>& i2): op(op), i1(i1), i2(i2)
|
|
|
|
{}
|
|
|
|
|
2024-01-16 18:44:50 -05:00
|
|
|
[[nodiscard]] bool has_both() const noexcept
|
2024-01-16 14:53:31 -05:00
|
|
|
{
|
|
|
|
return i1.has_value() && i2.has_value();
|
|
|
|
}
|
|
|
|
|
2024-01-16 18:44:50 -05:00
|
|
|
[[nodiscard]] bool has_one() const noexcept
|
2024-01-16 14:53:31 -05:00
|
|
|
{
|
|
|
|
return i1.has_value() || i2.has_value();
|
|
|
|
}
|
|
|
|
|
2024-01-16 18:44:50 -05:00
|
|
|
[[nodiscard]] image* getOne() const
|
2024-01-16 14:53:31 -05:00
|
|
|
{
|
|
|
|
if (i1)
|
|
|
|
return i1.value();
|
|
|
|
if (i2)
|
|
|
|
return i2.value();
|
|
|
|
BLT_THROW(std::runtime_error("Unable to get when one is missing! You have an error in your GA!"));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //GP_IMAGE_TEST_IMAGE_H
|