Expose Geometry2D.bresenham_line() method

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
This commit is contained in:
Danil Alexeev
2024-10-21 08:19:00 +03:00
parent 78a4e634f0
commit 9f0ae21095
5 changed files with 38 additions and 7 deletions

View File

@@ -451,17 +451,17 @@ public:
return H;
}
static Vector<Point2i> bresenham_line(const Point2i &p_start, const Point2i &p_end) {
static Vector<Point2i> bresenham_line(const Point2i &p_from, const Point2i &p_to) {
Vector<Point2i> points;
Vector2i delta = (p_end - p_start).abs() * 2;
Vector2i step = (p_end - p_start).sign();
Vector2i current = p_start;
Vector2i delta = (p_to - p_from).abs() * 2;
Vector2i step = (p_to - p_from).sign();
Vector2i current = p_from;
if (delta.x > delta.y) {
int err = delta.x / 2;
for (; current.x != p_end.x; current.x += step.x) {
for (; current.x != p_to.x; current.x += step.x) {
points.push_back(current);
err -= delta.y;
@@ -473,7 +473,7 @@ public:
} else {
int err = delta.y / 2;
for (; current.y != p_end.y; current.y += step.y) {
for (; current.y != p_to.y; current.y += step.y) {
points.push_back(current);
err -= delta.x;