убраны круги из линий
This commit is contained in:
@@ -114,32 +114,6 @@ fn clipLineToBuffer(ctx: *DrawContext, a: *Point2_i, b: *Point2_i, thickness: i3
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Точка (px, py) лежит строго внутри круга с центром (cx, cy) и радиусом в квадрате r_sq (граница не включается).
|
|
||||||
fn insideCircle(px: i32, py: i32, cx: i32, cy: i32, r_sq: i32) bool {
|
|
||||||
const dx = px - cx;
|
|
||||||
const dy = py - cy;
|
|
||||||
return dx * dx + dy * dy < r_sq;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Заливает круг в буфере (для скруглённых концов отрезка).
|
|
||||||
fn fillCircleAtBuffer(ctx: *DrawContext, cx: i32, cy: i32, radius: i32, color: Color.PMA) void {
|
|
||||||
const bw: i32 = @intCast(ctx.buf_width);
|
|
||||||
const bh: i32 = @intCast(ctx.buf_height);
|
|
||||||
const r_sq = radius * radius;
|
|
||||||
var dy: i32 = -radius;
|
|
||||||
while (dy <= radius) : (dy += 1) {
|
|
||||||
var dx: i32 = -radius;
|
|
||||||
while (dx <= radius) : (dx += 1) {
|
|
||||||
const px = cx + dx;
|
|
||||||
const py = cy + dy;
|
|
||||||
if (!insideCircle(px, py, cx, cy, r_sq)) continue;
|
|
||||||
if (px >= 0 and px < bw and py >= 0 and py < bh) {
|
|
||||||
ctx.blendPixelAtBuffer(@intCast(px), @intCast(py), color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn drawLineInBuffer(ctx: *DrawContext, bx0: i32, by0: i32, bx1: i32, by1: i32, color: Color.PMA, thickness_px: u32) void {
|
fn drawLineInBuffer(ctx: *DrawContext, bx0: i32, by0: i32, bx1: i32, by1: i32, color: Color.PMA, thickness_px: u32) void {
|
||||||
// Коррекция толщины в зависимости от угла линии.
|
// Коррекция толщины в зависимости от угла линии.
|
||||||
var thickness_corrected: u32 = thickness_px;
|
var thickness_corrected: u32 = thickness_px;
|
||||||
@@ -193,8 +167,9 @@ fn drawLineInBuffer(ctx: *DrawContext, bx0: i32, by0: i32, bx1: i32, by1: i32, c
|
|||||||
while (thick <= half_thickness) {
|
while (thick <= half_thickness) {
|
||||||
const x = if (use_vertical) x0 + thick else x0;
|
const x = if (use_vertical) x0 + thick else x0;
|
||||||
const y = if (use_vertical) y0 else y0 + thick;
|
const y = if (use_vertical) y0 else y0 + thick;
|
||||||
if (x >= 0 and y >= 0)
|
if (x >= 0 and y >= 0) {
|
||||||
ctx.blendPixelAtBuffer(@intCast(x), @intCast(y), color);
|
ctx.blendPixelAtBuffer(@intCast(x), @intCast(y), color);
|
||||||
|
}
|
||||||
thick += 1;
|
thick += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user