2023-05-06 16:37:48 +02:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
typedef uint8_t Transformation;
|
|
|
|
|
|
|
|
const Transformation TRANSFORM_MIRROR_X = 1 << 0;
|
|
|
|
const Transformation TRANSFORM_MIRROR_Y = 1 << 1;
|
|
|
|
const Transformation TRANSFORM_ROTATE_CW = 1 << 2;
|
|
|
|
const Transformation TRANSFORM_ROTATE_CCW = 1 << 3;
|
|
|
|
|
|
|
|
// Applies the provided transformation to the point, mutating it in place.
|
|
|
|
// Rotation is done before mirroring.
|
|
|
|
void transform_mut(Transformation transformation, int &x, int &y);
|
|
|
|
// Applies the provided transformation to the point,
|
|
|
|
// returning the transformed point.
|
|
|
|
// Rotation is done before mirroring.
|
|
|
|
std::pair<int, int> transform(Transformation transformation, int x, int y);
|
|
|
|
|
|
|
|
// Applies the inverse transformation to the point, mutating it in place.
|
|
|
|
// Composition of this with the transformation is the identity function.
|
|
|
|
void transform_inv_mut(Transformation transformation, int &x, int &y);
|
|
|
|
// Applies the inverse transformation to the point,
|
|
|
|
// returning the transformed point.
|
|
|
|
// Composition of this with the transformation is the identity function.
|
|
|
|
std::pair<int, int> transform_inv(Transformation transformation, int x, int y);
|
2023-05-06 16:40:17 +02:00
|
|
|
|
|
|
|
// Returns the transformation required
|
|
|
|
// to make the given endpoints of a line conform
|
|
|
|
// to the standard case for rasterization.
|
|
|
|
Transformation transformation_to_standard_case(int x0, int y0, int x1, int y1);
|
2023-05-07 16:25:48 +02:00
|
|
|
|
|
|
|
// Returns the barycentric coordinates of the point given by (xp, yp)
|
|
|
|
// in the triangle given by the three points (x0, y0), (x1, y1), (x2, y2).
|
2023-05-09 22:02:59 +02:00
|
|
|
// May return non-real values when the points are on a straight line.
|
2023-05-07 16:25:48 +02:00
|
|
|
std::tuple<float, float, float> barycentric_coordinates(int x0, int y0, int x1,
|
|
|
|
int y1, int x2, int y2,
|
|
|
|
int xp, int yp);
|
2023-05-07 19:24:48 +02:00
|
|
|
|
2023-05-09 22:06:18 +02:00
|
|
|
// Checks if the point given by (xp, yp) is inside the triangle
|
|
|
|
// given by the three points (x0, y0), (x1, y1), (x2, y2).
|
|
|
|
bool point_in_triangle(int x0, int y0, int x1, int y1, int x2, int y2, int xp,
|
|
|
|
int yp);
|
|
|
|
|
2023-05-07 19:24:48 +02:00
|
|
|
// Sorts the points of a triangle to be in ascending order (y0 < y1 < y2).
|
|
|
|
void sort_triangle_points(int &x0, int &y0, int &x1, int &y1, int &x2, int &y2);
|
2023-05-09 20:39:24 +02:00
|
|
|
|
|
|
|
// This calculates the slope of a line from (x0, y0) to (x1, y1).
|
|
|
|
// It handles special cases to ensure the return value will be real.
|
|
|
|
float slope(int x0, int y0, int x1, int y1);
|