kahlo 0.0.2

Optimized software rendering library.
Documentation
use crate::{
    colour::Colour,
    math::{PixelBox, PixelPoint, PixelSideOffsets},
    prelude::*,
    BitmapMut,
};

use super::{GenericUnary, KahloOps, UnaryDispatch, UnaryOpSpec};

pub struct RectangleOp;

type Params<'l> = (PixelBox, usize, Colour);

#[cfg(test)]
const _: () = {
    use super::generate;
    impl generate::UnaryInputSpec for RectangleOp {
        fn gen<'l>() -> impl generate::ValueGeneratorList<'l, OutputTuple = Self::Params<'l>> {
            (
                generate::dst_area,
                generate::uniform(1, 5),
                generate::random_colour,
            )
        }
    }
};

impl UnaryOpSpec for RectangleOp {
    type Params<'l> = Params<'l>;
    fn build<'l>() -> UnaryDispatch<Self::Params<'l>> {
        UnaryDispatch::from_generic::<Self>()
    }
}

impl<'l> GenericUnary<Params<'l>> for RectangleOp {
    fn perform<Format: crate::formats::PixelFormatSpec>(
        write_data: &mut dyn BitmapRawDataMut,
        params: &Params<'l>,
    ) {
        let mut write_data = BitmapMut::new_from_raw(write_data);
        let mut subregion = write_data.make_view_mut(PixelBox::from_size(write_data.size()));
        /*let mut subregion =
        BitmapAccessMut::<Format>::make_view_mut(write_data, );*/
        let (area, width, colour) = params;

        let maxmin = PixelPoint::new(area.max.x, area.min.y);
        let minmax = PixelPoint::new(area.min.x, area.max.y);

        let width = (*width as i32) - 1;

        // top side
        KahloOps::<Format>::fill_region(
            &mut subregion,
            PixelBox::from_points([area.min, maxmin]).outer_box(PixelSideOffsets {
                bottom: width,
                ..Default::default()
            }),
            *colour,
        );
        // bottom side
        KahloOps::<Format>::fill_region(
            &mut subregion,
            PixelBox::from_points([minmax, area.max]).outer_box(PixelSideOffsets {
                top: width,
                ..Default::default()
            }),
            *colour,
        );

        // left side
        KahloOps::<Format>::fill_region(
            &mut subregion,
            PixelBox::from_points([area.min, minmax]).outer_box(PixelSideOffsets {
                right: width,
                ..Default::default()
            }),
            *colour,
        );
        // right side
        KahloOps::<Format>::fill_region(
            &mut subregion,
            PixelBox::from_points([maxmin, area.max]).outer_box(PixelSideOffsets {
                left: width,
                ..Default::default()
            }),
            *colour,
        );
    }
}