File: skia_dash.rs

package info (click to toggle)
rust-tiny-skia 0.11.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,352 kB
  • sloc: makefile: 4
file content (45 lines) | stat: -rw-r--r-- 1,669 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use tiny_skia::*;

#[test]
fn crbug_140642() {
    // We used to see this construct, and due to rounding as we accumulated
    // our length, the loop where we apply the phase would run off the end of
    // the array, since it relied on just -= each interval value, which did not
    // behave as "expected". Now the code explicitly checks for walking off the
    // end of that array.
    //
    // A different (better) fix might be to rewrite dashing to do all of its
    // length/phase/measure math using double, but this may need to be
    // coordinated with SkPathMeasure, to be consistent between the two.
    assert!(StrokeDash::new(vec![27734.0, 35660.0, 2157846850.0, 247.0], -248.135982067).is_some());
}

#[test]
fn crbug_124652() {
    // http://code.google.com/p/chromium/issues/detail?id=124652
    // This particular test/bug only applies to the float case, where
    // large values can "swamp" small ones.
    assert!(StrokeDash::new(vec![837099584.0, 33450.0], -10.0).is_some());
}

// Extremely large path_length/dash_length ratios may cause infinite looping
// due to single precision rounding.
#[test]
fn infinite_dash() {
    let mut pb = PathBuilder::new();
    pb.move_to(0.0, 5.0);
    pb.line_to(5000000.0, 5.0);
    let path = pb.finish().unwrap();

    let mut paint = Paint::default();
    paint.set_color_rgba8(50, 127, 150, 200);
    paint.anti_alias = true;

    let mut stroke = Stroke::default();
    stroke.dash = StrokeDash::new(vec![0.2, 0.2], 0.0);

    let mut pixmap = Pixmap::new(100, 100).unwrap();
    pixmap.stroke_path(&path, &paint, &stroke, Transform::identity(), None); // Doesn't draw anything.

    assert!(true);
}