summaryrefslogtreecommitdiff
path: root/graphics.c
diff options
context:
space:
mode:
Diffstat (limited to 'graphics.c')
-rw-r--r--graphics.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/graphics.c b/graphics.c
index 208d29a..02a0e63 100644
--- a/graphics.c
+++ b/graphics.c
@@ -589,8 +589,8 @@ b8 hit_line(vec2 vertices[2], f64 width, vec2 point) {
tx /= tl;
ty /= tl;
}
- tx *= width * .5;
- ty *= width * .5;
+ tx *= width * 0.5;
+ ty *= width * 0.5;
return hit_quad((vec2[4]) {
{ x0 - tx, y0 - ty },
@@ -890,7 +890,7 @@ static b8 quad_from_line_(vec2 *dst, vec2 vertices[2], f64 width) {
if (tl < EPSILON)
return 0;
- f64 k = .5 / tl;
+ f64 k = 0.5 / tl;
tx *= width * k;
ty *= width * k;
@@ -1365,7 +1365,7 @@ void draw_text_cursor_to_buffer(Pixel_Buffer dst, i32 font, vec4_f32 color, Box
(Box) {
.x = area.x + kx * cursor_x,
.y = area.y + ky * cursor_y - ky * LCD_Height,
- .width = kx * .5,
+ .width = kx * 0.5,
.height = ky * (LCD_Height - 1),
}
);
@@ -1694,10 +1694,10 @@ static Box graphics_request_area_(Graphics_Request req) {
static Graphics_Request_Norm_ normalize_graphics_request_(Graphics_Request req) {
Box area = graphics_request_area_(req);
- i64 x = (i64) floor(area.x - .5);
- i64 y = (i64) floor(area.y - .5);
- i64 w = (i64) ceil (area.x + area.width + .5) - x;
- i64 h = (i64) ceil (area.y + area.height + .5) - y;
+ i64 x = (i64) floor(area.x - 0.5);
+ i64 y = (i64) floor(area.y - 0.5);
+ i64 w = (i64) ceil (area.x + area.width + 0.5) - x;
+ i64 h = (i64) ceil (area.y + area.height + 0.5) - y;
return (Graphics_Request_Norm_) {
.req = graphics_request_moved_(req, (vec2) { -x, -y }),
@@ -2454,6 +2454,21 @@ TEST("rectangle aliasing") {
(Box) { .x = 7.4, .y = 4.4, .width = 1.2, .height = 1.2, }
);
+ fill_rectangle_to_buffer(
+ (Pixel_Buffer) { .width = w, .height = h, .stride = w, .pixels = pixels },
+ (vec4_f32) { 1.0f, 1.0f, 1.0f, 1.0f, },
+ (Box) { .x = 7.44, .y = 6.51, .width = 1.07, .height = 1.991, }
+ );
+
+ // printf("\n");
+ // for (i64 j = 0; j < h; ++j) {
+ // for (i64 i = 0; i < w; ++i) {
+ // printf(" %c", pixels[j * w + i].x > 0.5 ? 'x' : '.');
+ // }
+ // printf("\n");
+ // }
+ // printf("\n");
+
b8 expect_bits[100] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 0, 1, 1, 0, 1, 1, 0,
@@ -2462,8 +2477,8 @@ TEST("rectangle aliasing") {
0, 1, 1, 0, 1, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 1, 0, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};