Fix wrapping

This commit is contained in:
2025-10-18 17:43:22 +01:00
parent 0deaf4435c
commit 770f7a569c

View File

@@ -5,7 +5,6 @@
#include <assert.h>
#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <xf86drm.h>
@@ -31,9 +30,7 @@ static void page_flip_handler(int, unsigned, unsigned, unsigned, void *)
static void set_pixel(uint32_t x, uint32_t y)
{
x %= width;
y %= height;
const uint32_t offset = y * (fbs[back].pitch / 4) + x;
const uint32_t offset = y * (fbs[back].pitch / 4) + x;
fbs[back].buf[offset] = 0xff'ff'ff;
}
@@ -45,8 +42,22 @@ static void draw_line(vec3_t v1, vec3_t v2)
if (step != 0.0) {
const float step_x = delta_x / step;
const float step_y = delta_y / step;
for (unsigned i = 0; i <= step; ++i)
set_pixel(roundf(v1.x + i * step_x), roundf(v1.y + i * step_y));
for (unsigned i = 0; i <= step; ++i) {
float x = roundf(v1.x + i * step_x);
if (x >= width)
x -= width;
else if (x < 0)
x += width;
float y = roundf(v1.y + i * step_y);
if (y >= height)
y -= height;
else if (y < 0)
y += height;
set_pixel(x, y);
}
} else {
set_pixel(roundf(v1.x), roundf(v1.y));
}