use crate::data::pointing::KusaPoint;
use crate::paint_tool::Nib;
use crate::piston_wrapper::kusa_image::KusaImage;
use crate::settings::Settings;
pub struct CircleNib {}
impl Nib for CircleNib {
fn put_pixel(&self, settings: &Settings, k_image: &mut KusaImage, center: &KusaPoint) {
let radius = settings.paint_thickness / 2.0;
let left = {
let mut left = (center.x - radius).round() as i16 - 1;
if left < 0 {
left = 0;
}
left
};
let right = {
let mut right = (center.x + radius).round() as i16 + 1;
if settings.image_width as i16 <= right {
right = settings.image_width as i16; }
right as i16
};
let top = {
let mut top = (center.y - radius).round() as i16 - 1;
if top < 0 {
top = 0;
}
top
};
let bottom = {
let mut bottom = (center.y + radius).round() as i16 + 1;
if settings.image_height as i16 <= bottom {
bottom = settings.image_width as i16; }
bottom as i16
};
for y in top..bottom {
let cell_center_y = y as f64; let height = (center.y - cell_center_y).abs();
for x in left..right {
let cell_center_x = x as f64; let width = (center.x - cell_center_x).abs();
let radius2 = (width * width + height * height).sqrt();
if radius2 < radius {
k_image.set_pixel(x as u32, y as u32, &settings.paint_color);
} else {
}
}
}
}
}