#![allow(dead_code)]
use crate::pad::{pad, PadMethod};
use crate::spatial::spatial_NxN;
use crate::traits::NumOps;
#[rustfmt::skip]
fn prewitt_inner_f32<T>(c: &[T; 9]) -> T
where
T: NumOps<T> + Copy + Default,
f32: std::convert::From<T>
{
let mut sum_a = 0.0;
sum_a += (f32::from(c[0]) * 1.) + (f32::from(c[2]) * -1.);
sum_a += (f32::from(c[3]) * 1.) + (f32::from(c[5]) * -1.);
sum_a += (f32::from(c[6]) * 1.) + (f32::from(c[7]) * -1.);
let mut sum_b = 0.0;
sum_b += (f32::from(c[0]) * 1.) + (f32::from(c[1]) * 1.);
sum_b += (f32::from(c[2]) * 1.) + (f32::from(c[6]) * -1.);
sum_b += (f32::from(c[7]) * -1.) + (f32::from(c[8]) * -1.);
T::from_f32(((sum_a * sum_a) + (sum_b * sum_b)).sqrt())
}
#[allow(clippy::neg_multiply, clippy::identity_op, clippy::zero_prefixed_literal)]
#[rustfmt::skip]
fn prewitt_inner_i32<T>(c: &[T; 9]) -> T
where
T: NumOps<T> + Copy + Default,
i32: std::convert::From<T>
{
let mut sum_a = 0;
sum_a += (i32::from(c[0]) * 1) + (i32::from(c[2]) * -1);
sum_a += (i32::from(c[3]) * 1) + (i32::from(c[5]) * -1);
sum_a += (i32::from(c[6]) * 1) + (i32::from(c[7]) * -1);
let mut sum_b = 0;
sum_b += (i32::from(c[0]) * 1) + (i32::from(c[1]) * 1);
sum_b += (i32::from(c[2]) * 1) + (i32::from(c[6]) * -1);
sum_b += (i32::from(c[7]) * -1) + (i32::from(c[8]) * -1);
T::from_f64(f64::from((sum_a * sum_a) + (sum_b * sum_b)).sqrt())
}
pub fn prewitt_float<T>(in_channel: &[T], out_channel: &mut [T], width: usize, height: usize)
where
T: Default + NumOps<T> + Copy,
f32: std::convert::From<T>
{
let padded_input = pad(in_channel, width, height, 1, 1, PadMethod::Replicate);
spatial_NxN::<_, _, 1, 9>(&padded_input, out_channel, width, height, prewitt_inner_f32);
}
pub fn prewitt_int<T>(in_channel: &[T], out_channel: &mut [T], width: usize, height: usize)
where
T: Default + NumOps<T> + Copy,
i32: std::convert::From<T>
{
let padded_input = pad(in_channel, width, height, 1, 1, PadMethod::Replicate);
spatial_NxN::<_, _, 1, 9>(&padded_input, out_channel, width, height, prewitt_inner_i32);
}