And finally, a bit of optimisation

This commit is contained in:
augustin64 2025-03-26 15:50:12 +01:00
parent 3bd422ab9f
commit 9cf197027d

View File

@ -15,9 +15,7 @@
bool silent;
bool test_energy;
int min(int a, int b) {
return a < b ? a : b;
}
#define min(a, b) { (a < b ? a : b) }
bool nearly_equal(float a, float b) {
return std::nextafter(a, std::numeric_limits<float>::lowest()) <= b
@ -110,9 +108,9 @@ std::vector<int> optimal_vertical_seam(std::vector<float> energy, int width, int
//Idea : float next_energy = min_val - energy[width*i + min_idx];
//! With floats, we don't always have x + y - y == x, so we check is x+y == x+y
auto is_next_idx = [=](int idx) {
return nearly_equal(dyn_energy[(i-1)*width + idx]+energy[width*i + min_idx], min_val);
};
// This define is a bit ugly but 200x faster than using a lambda function
#define is_next_idx(idx) \
(dyn_energy[(i-1)*width + idx]+energy[width*i + min_idx] == min_val)
if (is_next_idx(min_idx)) {
// min_idx does not change