Parks-n-Rec/include/genetic/v2/functions.h

62 lines
1.9 KiB
C
Raw Normal View History

2023-07-17 19:48:46 -04:00
//
// Created by brett on 7/17/23.
//
#ifndef PARKSNREC_FUNCTIONS_H
#define PARKSNREC_FUNCTIONS_H
#include <memory>
#include <vector>
#include <genetic/util.h>
2023-07-17 19:49:46 -04:00
#include <genetic/v2/util.h>
2023-07-17 19:48:46 -04:00
namespace parks::genetic {
namespace funcs {
2023-07-17 22:30:27 -04:00
static Parameter add(const std::vector<Parameter>& params) {
2023-07-17 19:48:46 -04:00
auto p1Type = params[0].getType();
auto p2Type = params[1].getType();
if (p2Type == ParameterType::IMAGE && p1Type != ParameterType::IMAGE)
params[1].apply(std::plus(), params[0]);
else
params[0].apply(std::plus(), params[1]);
}
2023-07-17 22:30:27 -04:00
static Parameter sub(const std::vector<Parameter>& params) {
2023-07-17 19:48:46 -04:00
auto p1Type = params[0].getType();
auto p2Type = params[1].getType();
if (p2Type == ParameterType::IMAGE && p1Type != ParameterType::IMAGE)
params[1].apply(std::minus(), params[0]);
else
params[0].apply(std::minus(), params[1]);
}
2023-07-17 22:30:27 -04:00
static Parameter multiply(const std::vector<Parameter>& params) {
2023-07-17 19:48:46 -04:00
auto p1Type = params[0].getType();
auto p2Type = params[1].getType();
if (p2Type == ParameterType::IMAGE && p1Type != ParameterType::IMAGE)
params[1].apply(std::multiplies(), params[0]);
else
params[0].apply(std::multiplies(), params[1]);
}
2023-07-17 22:30:27 -04:00
static Parameter divide(const std::vector<Parameter>& params) {
2023-07-17 19:48:46 -04:00
auto p1Type = params[0].getType();
auto p2Type = params[1].getType();
if (p2Type == ParameterType::IMAGE && p1Type != ParameterType::IMAGE)
params[1].apply(std::divides(), params[0]);
else
params[0].apply(std::divides(), params[1]);
}
}
}
#endif //PARKSNREC_FUNCTIONS_H