optimize tri (wtf)

This commit is contained in:
bendn 2023-09-25 14:04:46 +07:00
parent 829cfa680e
commit 5af9c16dc7
No known key found for this signature in database
GPG key ID: 0D9D3A2A3B2A93D6

View file

@ -21,14 +21,14 @@ impl<const CHANNELS: usize> Image<&mut [u8], CHANNELS> {
// TODO optimize
for y in y1.min(y2).min(y3) as u32..y1.max(y2).max(y3) as u32 {
for x in x1.min(x2).min(x3) as u32..x1.max(x2).max(x3) as u32 {
let s = (x1 - x3) * (y as f32 - y3) - (y1 - y2) * (x as f32 - x3);
let t = (x2 - x1) * (y as f32 - y1) - (y2 - y1) * (x as f32 - x1);
let s = (x1 - x3).mul_add(y as f32 - y3, -(y1 - y2) * (x as f32 - x3));
let t = (x2 - x1).mul_add(y as f32 - y1, -(y2 - y1) * (x as f32 - x1));
if (s < 0.0) != (t < 0.0) && s != 0.0 && t != 0.0 {
continue;
}
let d = (x3 - x2) * (y as f32 - y2) - (y3 - y2) * (x as f32 - x2);
let d = (x3 - x2).mul_add(y as f32 - y2, -(y3 - y2) * (x as f32 - x2));
if (d == 0.0 || (d < 0.0) == (s + t <= 0.0))
&& x < self.width()
&& y < self.height()