jrmuizel / raqote

Rust 2D graphics library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MatrixFixedPoint::transform panics at a large scale

RazrFalcon opened this issue · comments

use raqote::*;

fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.move_to(200., 200.);
    pb.line_to(300., 300.);
    pb.line_to(200., 300.);

    let path = pb.finish();

    let gradient = Source::LinearGradient(
        Gradient {
            stops: vec![
                GradientStop {
                    position: 0.0,
                    color: Color::new(0xff, 0x00, 0xff, 0x00),
                },
            ],
        },
        Spread::Pad,
        Transform::create_scale(1000.0, 1.0),
    );
    dt.fill(&path, &gradient, &DrawOptions::new());

    dt.write_png("out.png").unwrap();
}
thread 'main' panicked at 'attempt to multiply with overflow', /home/razr/.cargo/registry/src/github.com-1ecc6299db9ec823/sw-composite-0.7.10/src/lib.rs:629:16

This issue is performance-sensitive, so I'm not sure how it should be implemented.

I'm inclined to just overflow. That's what pixman is going to end up doing.

The problem is that C/C++ will overflow silently, which is fine, but Rust will panic in debug, which is annoying.

I meant that we could just switch to using wrapping_mul/wrapping_add to avoid the debug panics.

Does wrapping zero cost in release?

I see. Looks like I've mistaken it with saturating.