Переход на i32

This commit is contained in:
2026-03-03 15:26:01 +03:00
parent 7aa9673b44
commit 5b1b3a8c5e
3 changed files with 22 additions and 20 deletions

View File

@@ -89,7 +89,7 @@ pub fn draw(ctx: *DrawContext, obj: *const Object) void {
const ny = loc_y * inv_ry;
const d = nx * nx + ny * ny;
if (d >= d_inner_sq and d <= d_outer_sq) {
ctx.blendPixelAtBuffer(@intCast(bx), @intCast(by), stroke);
ctx.blendPixelAtBuffer(bx, by, stroke);
}
}
}

View File

@@ -162,9 +162,8 @@ fn drawLineInBuffer(ctx: *DrawContext, bx0: i32, by0: i32, bx1: i32, by1: i32, c
while (thick <= half_thickness) {
const x = if (use_vertical) x0 + thick else x0;
const y = if (use_vertical) y0 else y0 + thick;
if (x >= 0 and y >= 0) {
ctx.blendPixelAtBuffer(@intCast(x), @intCast(y), color);
}
ctx.blendPixelAtBuffer(x, y, color);
thick += 1;
}

View File

@@ -134,9 +134,12 @@ pub const DrawContext = struct {
/// Смешивает цвет в пикселе буфера с учётом opacity трансформа. В replace_mode просто перезаписывает пиксель.
/// Если активен fill canvas, каждый записанный пиксель помечается как граница для заливки.
pub fn blendPixelAtBuffer(self: *DrawContext, bx: u32, by: u32, color: Color.PMA) void {
if (bx >= self.buf_width or by >= self.buf_height) return;
if (self._fill_canvas) |fc| fc.setBorder(bx, by);
pub fn blendPixelAtBuffer(self: *DrawContext, bx_i32: i32, by_i32: i32, color: Color.PMA) void {
if (self._fill_canvas) |fc| fc.setBorder(bx_i32, by_i32);
if (bx_i32 < 0 or by_i32 < 0 or bx_i32 >= self.buf_width or by_i32 >= self.buf_height) return;
const bx: u32 = @intCast(bx_i32);
const by: u32 = @intCast(by_i32);
const idx = by * self.buf_width + bx;
const dst = &self.pixels[idx];
if (self.replace_mode) {
@@ -184,7 +187,7 @@ pub const DrawContext = struct {
const vw = @as(i32, @intCast(self.visible_rect.w));
const vh = @as(i32, @intCast(self.visible_rect.h));
if (bx < 0 or bx >= vw or by < 0 or by >= vh) return;
self.blendPixelAtBuffer(@intCast(bx), @intCast(by), color);
self.blendPixelAtBuffer(bx, by, color);
}
/// Начинает сбор границ для заливки: создаёт FillCanvas и при последующих вызовах blendPixelAtBuffer помечает пиксели как границу.
@@ -238,8 +241,8 @@ const FillCanvas = struct {
const Row = struct {
pixels: []PixelType,
first_border_x: ?u32 = null,
last_border_x: ?u32 = null,
first_border_x: ?i32 = null,
last_border_x: ?i32 = null,
};
pub fn init(allocator: std.mem.Allocator, width: u32, height: u32) !FillCanvas {
@@ -273,26 +276,26 @@ const FillCanvas = struct {
allocator.free(self._pixels);
}
pub fn setBorder(self: *FillCanvas, x: u32, y: u32) void {
if (x >= self.buf_width or y >= self.buf_height) return;
pub fn setBorder(self: *FillCanvas, x: i32, y: i32) void {
if (x < 0 or y < 0 or x >= self.buf_width or y >= self.buf_height) return;
const row = &self.rows[y];
row.pixels[x] = .Border;
const row = &self.rows[@intCast(y)];
row.pixels[@intCast(x)] = .Border;
if (row.first_border_x) |first| {
if (x < first) {
row.first_border_x = x;
row.first_border_x = @intCast(x);
}
} else {
row.first_border_x = x;
row.first_border_x = @intCast(x);
}
if (row.last_border_x) |last| {
if (x > last) {
row.last_border_x = x;
row.last_border_x = @intCast(x);
}
} else {
row.last_border_x = x;
row.last_border_x = @intCast(x);
}
}
@@ -310,7 +313,7 @@ const FillCanvas = struct {
var on_border = true;
var segment_index: usize = 0; // индекс "промежутка" (счет с 0)
var x = first;
var x: u32 = @intCast(first);
while (x <= last) : (x += 1) {
if (row.pixels[x] == .Border) {
on_border = true;
@@ -321,7 +324,7 @@ const FillCanvas = struct {
}
if (!on_border and row.pixels[x] == .Empty and segment_index % 2 == 1) {
row.pixels[x] = .Fill;
draw_ctx.blendPixelAtBuffer(x, y, color);
draw_ctx.blendPixelAtBuffer(@intCast(x), @intCast(y), color);
}
}
}