This repository has been archived on 2024-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
ecg-prog-filtered/u02/src/util.cpp

50 lines
1.2 KiB
C++

// SPDX-License-Identifier: LGPL-3.0-or-later
#include "util.h"
#include <cmath>
void transform_mut(Transformation transformation, int &x, int &y) {
if ((transformation & TRANSFORM_ROTATE_CW) != 0) {
std::swap(x, y);
x = -x;
}
if ((transformation & TRANSFORM_ROTATE_CCW) != 0) {
std::swap(x, y);
y = -y;
}
if ((transformation & TRANSFORM_MIRROR_X) != 0) {
y = -y;
}
if ((transformation & TRANSFORM_MIRROR_Y) != 0) {
x = -x;
}
}
std::pair<int, int> transform(Transformation transformation, int x, int y) {
transform_mut(transformation, x, y);
return std::make_pair(x, y);
}
void transform_inv_mut(Transformation transformation, int &x, int &y) {
if ((transformation & TRANSFORM_MIRROR_Y) != 0) {
x = -x;
}
if ((transformation & TRANSFORM_MIRROR_X) != 0) {
y = -y;
}
if (transformation & TRANSFORM_ROTATE_CCW) {
// does clockwise rotation
std::swap(x, y);
x = -x;
}
if (transformation & TRANSFORM_ROTATE_CW) {
// does counterclockwise rotation
std::swap(x, y);
y = -y;
}
}
std::pair<int, int> transform_inv(Transformation transformation, int x, int y) {
transform_inv_mut(transformation, x, y);
return std::make_pair(x, y);
}