mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Expose Geometry2D.bresenham_line() method
Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user