6 # this script tests an internal set of functions for Imager, they
7 # aren't intended to be used at the perl level.
8 # these functions aren't present in all Imager builds
10 unless (Imager::Internal::Hlines::testing()) {
11 plan skip_all => 'Imager not built to run this test';
16 my $hline = Imager::Internal::Hlines::new(0, 100, 0, 100);
17 my $base_text = 'start_y: 0 limit_y: 100 start_x: 0 limit_x: 100';
18 ok($hline, "made hline");
19 is($hline->dump, "$base_text\n", "check values");
20 $hline->add(5, -5, 7);
21 is($hline->dump, <<EOS, "check (-5, 7) added");
26 is($hline->dump, <<EOS, "check (8, 4) added");
31 is($hline->dump, <<EOS, "check (3, 3) added");
33 5 (3): [0, 2) [3, 6) [8, 12)
36 is($hline->dump, <<EOS, "check (2, 6) added");
40 # adding out of range should do nothing
45 $hline->add(6, -5, 5);
46 is($hline->dump, $current, "check (6, -5, 5) not added");
47 $hline->add(6, 100, 5);
48 is($hline->dump, $current, "check (6, 100, 5) not added");
49 $hline->add(-1, 5, 2);
50 is($hline->dump, $current, "check (-1, 5, 2) not added");
51 $hline->add(100, 5, 2);
52 is($hline->dump, $current, "check (10, 5, 2) not added");
54 # overlapped add check
57 is($hline->dump, <<EOS, "check internal overlap merged");
63 # white box test: try to force reallocation of an entry
65 $hline->add(7, $i*2, 1);
67 is($hline->dump, <<EOS, "lots of segments");
71 7 (21): [0, 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)
74 $hline->add(7, 1, 39);
75 is($hline->dump, <<EOS, "merge lots of segments");
83 $hline = Imager::Internal::Hlines::new(50, 50, 50, 50);
84 $base_text = 'start_y: 50 limit_y: 100 start_x: 50 limit_x: 100';
87 $hline->add(51, 45, 10);
88 $hline->add(51, 55, 4);
89 is($hline->dump, <<EOS, "left merge");
95 $hline->add(52, 90, 5);
96 $hline->add(52, 87, 5);
97 is($hline->dump, <<EOS, "right merge");