fix: 修复斜线刷子连线的空白问题

This commit is contained in:
2026-02-28 02:08:36 +08:00
parent 6f6e6f326b
commit ae095946f0
3 changed files with 29 additions and 26 deletions

View File

@@ -88,8 +88,8 @@ impl MSCanvas {
return self.pixels.clone();
}
let dst_width = self.width * scale;
let dst_height = self.width * scale;
let mut dst = vec![0; (self.width * self.width * 4) as usize]; // RGBA
let dst_height = self.height * scale;
let mut dst = vec![0; (dst_width * dst_height * 4) as usize]; // RGBA
for y in 0..self.height {
for x in 0..self.width {
@@ -262,21 +262,28 @@ impl MSCanvas {
pub fn brush_slash(&mut self, center: Point) {
let r = self.line_width / 2;
let l = self.line_width - r;
// for dx in -1..1 {
// for d in -l..r {
// self.draw_pixel_at(Point::new(center.x - (d as f32) + (dx as f32), center.y - d as f32));
// }
// }
for d in -l..r {
self.draw_pixel_at(Point::new(center.x - (d as f32), center.y - d as f32));
// 左右扩展,填补线条的空白
for dx in 0..2 {
for d in -l..r {
self.draw_pixel_at(Point::new(
center.x - (d as f32) + (dx as f32),
center.y - d as f32,
));
}
}
}
pub fn brush_backslash(&mut self, center: Point) {
let r = self.line_width / 2;
let l = self.line_width - r;
for d in -l..r {
self.draw_pixel_at(Point::new(center.x + d as f32, center.y - d as f32));
// 左右扩展,填补线条的空白
for dx in 0..2 {
for d in -l..r {
self.draw_pixel_at(Point::new(
center.x + d as f32 + (dx as f32),
center.y - d as f32,
));
}
}
}