| Filename | /home/ocbnet/domain/ocbnet.ch/vhost/webmerge/htdocs/webmerge/scripts/modules/OCBNET/Spritesets/Canvas/Layout.pm |
| Statements | Executed 47239 statements in 445ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 12 | 1 | 1 | 408ms | 92.7s | OCBNET::Spritesets::Canvas::Layout::layout |
| 9568 | 14 | 2 | 108ms | 108ms | OCBNET::Spritesets::Canvas::Layout::snap |
| 584 | 3 | 1 | 22.9ms | 25.4ms | OCBNET::Spritesets::Canvas::Layout::factors |
| 144 | 12 | 1 | 11.9ms | 29.2ms | OCBNET::Spritesets::Canvas::Layout::lcm |
| 1 | 1 | 1 | 2.81ms | 30.4ms | OCBNET::Spritesets::Canvas::Layout::BEGIN@31 |
| 584 | 1 | 1 | 2.51ms | 2.51ms | OCBNET::Spritesets::Canvas::Layout::CORE:sort (opcode) |
| 1 | 1 | 1 | 1.36ms | 16.6ms | OCBNET::Spritesets::Canvas::Layout::BEGIN@231 |
| 1 | 1 | 1 | 104µs | 203µs | OCBNET::Spritesets::Canvas::Layout::BEGIN@10 |
| 1 | 1 | 1 | 56µs | 87µs | OCBNET::Spritesets::Canvas::Layout::BEGIN@11 |
| 1 | 1 | 1 | 55µs | 55µs | OCBNET::Spritesets::Canvas::Layout::BEGIN@19.1 |
| 1 | 1 | 1 | 26µs | 26µs | OCBNET::Spritesets::Canvas::Layout::BEGIN@22 |
| 1 | 1 | 1 | 26µs | 26µs | OCBNET::Spritesets::Canvas::Layout::BEGIN@25 |
| 1 | 1 | 1 | 24µs | 24µs | OCBNET::Spritesets::Canvas::Layout::BEGIN@19 |
| 1 | 1 | 1 | 21µs | 21µs | OCBNET::Spritesets::Canvas::Layout::BEGIN@16 |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | ################################################################################################### | ||||
| 2 | # Copyright 2013 by Marcel Greter | ||||
| 3 | # This file is part of Webmerge (GPL3) | ||||
| 4 | #################################################################################################### | ||||
| 5 | # static helper functions for canvas | ||||
| 6 | #################################################################################################### | ||||
| 7 | package OCBNET::Spritesets::Canvas::Layout; | ||||
| 8 | #################################################################################################### | ||||
| 9 | |||||
| 10 | 2 | 172µs | 2 | 302µs | # spent 203µs (104+99) within OCBNET::Spritesets::Canvas::Layout::BEGIN@10 which was called:
# once (104µs+99µs) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 10 # spent 203µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@10
# spent 99µs making 1 call to strict::import |
| 11 | 2 | 192µs | 2 | 118µs | # spent 87µs (56+31) within OCBNET::Spritesets::Canvas::Layout::BEGIN@11 which was called:
# once (56µs+31µs) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 11 # spent 87µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@11
# spent 31µs making 1 call to warnings::import |
| 12 | |||||
| 13 | ################################################################################################### | ||||
| 14 | |||||
| 15 | # define our version string | ||||
| 16 | 1 | 157µs | 1 | 21µs | # spent 21µs within OCBNET::Spritesets::Canvas::Layout::BEGIN@16 which was called:
# once (21µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 16 # spent 21µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@16 |
| 17 | |||||
| 18 | # load exporter and inherit from it | ||||
| 19 | 3 | 374µs | 2 | 79µs | # spent 24µs within OCBNET::Spritesets::Canvas::Layout::BEGIN@19 which was called:
# once (24µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 19
# spent 55µs within OCBNET::Spritesets::Canvas::Layout::BEGIN@19.1 which was called:
# once (55µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 19 # spent 55µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@19.1
# spent 24µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@19 |
| 20 | |||||
| 21 | # define our functions to be exported | ||||
| 22 | 1 | 175µs | 1 | 26µs | # spent 26µs within OCBNET::Spritesets::Canvas::Layout::BEGIN@22 which was called:
# once (26µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 22 # spent 26µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@22 |
| 23 | |||||
| 24 | # define our functions to be exported | ||||
| 25 | 1 | 170µs | 1 | 26µs | # spent 26µs within OCBNET::Spritesets::Canvas::Layout::BEGIN@25 which was called:
# once (26µs+0s) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 25 # spent 26µs making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@25 |
| 26 | |||||
| 27 | #################################################################################################### | ||||
| 28 | |||||
| 29 | # load function from core module | ||||
| 30 | # ****************************************************************************** | ||||
| 31 | 2 | 4.35ms | 2 | 31.1ms | # spent 30.4ms (2.81+27.6) within OCBNET::Spritesets::Canvas::Layout::BEGIN@31 which was called:
# once (2.81ms+27.6ms) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 31 # spent 30.4ms making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@31
# spent 700µs making 1 call to Exporter::import |
| 32 | |||||
| 33 | |||||
| 34 | # private helper function | ||||
| 35 | # returns all prime factors | ||||
| 36 | # ****************************************************************************** | ||||
| 37 | sub factors | ||||
| 38 | # spent 25.4ms (22.9+2.51) within OCBNET::Spritesets::Canvas::Layout::factors which was called 584 times, avg 44µs/call:
# 456 times (14.5ms+1.48ms) by OCBNET::Spritesets::Canvas::Layout::lcm at line 73, avg 35µs/call
# 64 times (4.38ms+557µs) by OCBNET::Spritesets::Canvas::Layout::layout at line 145, avg 77µs/call
# 64 times (4.08ms+470µs) by OCBNET::Spritesets::Canvas::Layout::layout at line 131, avg 71µs/call | ||||
| 39 | |||||
| 40 | # hold all factors | ||||
| 41 | 584 | 454µs | my @primes; | ||
| 42 | |||||
| 43 | # get number to factorize | ||||
| 44 | 584 | 1.45ms | my ($number) = @_; | ||
| 45 | |||||
| 46 | # loop from 2 up to number | ||||
| 47 | 584 | 3.50ms | for ( my $y = 2; $y <= $number; $y ++ ) | ||
| 48 | { | ||||
| 49 | # skip if not a factor | ||||
| 50 | 1512 | 2.55ms | next if $number % $y; | ||
| 51 | # divide by factor found | ||||
| 52 | 504 | 721µs | $number /= $y; | ||
| 53 | # store found factor | ||||
| 54 | 504 | 1.08ms | push(@primes, $y); | ||
| 55 | # restart from 2 | ||||
| 56 | 504 | 616µs | redo; | ||
| 57 | } | ||||
| 58 | |||||
| 59 | # sort the prime factors | ||||
| 60 | 584 | 17.4ms | 584 | 2.51ms | return sort @primes; # spent 2.51ms making 584 calls to OCBNET::Spritesets::Canvas::Layout::CORE:sort, avg 4µs/call |
| 61 | |||||
| 62 | }; | ||||
| 63 | # EO sub factors | ||||
| 64 | |||||
| 65 | #################################################################################################### | ||||
| 66 | |||||
| 67 | # private helper function | ||||
| 68 | # least common multiplier | ||||
| 69 | # ****************************************************************************** | ||||
| 70 | sub lcm | ||||
| 71 | # spent 29.2ms (11.9+17.3) within OCBNET::Spritesets::Canvas::Layout::lcm which was called 144 times, avg 203µs/call:
# 12 times (1.52ms+2.80ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 209, avg 360µs/call
# 12 times (1.47ms+2.66ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 218, avg 344µs/call
# 12 times (1.31ms+1.89ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 166, avg 267µs/call
# 12 times (1.18ms+1.80ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 172, avg 248µs/call
# 12 times (1.13ms+1.77ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 195, avg 241µs/call
# 12 times (1.11ms+1.72ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 202, avg 235µs/call
# 12 times (928µs+1.40ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 184, avg 194µs/call
# 12 times (926µs+1.32ms) by OCBNET::Spritesets::Canvas::Layout::layout at line 179, avg 187µs/call
# 12 times (580µs+497µs) by OCBNET::Spritesets::Canvas::Layout::layout at line 190, avg 90µs/call
# 12 times (574µs+499µs) by OCBNET::Spritesets::Canvas::Layout::layout at line 192, avg 89µs/call
# 12 times (573µs+499µs) by OCBNET::Spritesets::Canvas::Layout::layout at line 193, avg 89µs/call
# 12 times (566µs+494µs) by OCBNET::Spritesets::Canvas::Layout::layout at line 191, avg 88µs/call | ||||
| 72 | 144 | 217µs | my $product = 1; $product *= $_ | ||
| 73 | 600 | 9.99ms | 600 | 17.3ms | foreach uniq grep { $_ != 0 } # spent 15.9ms making 456 calls to OCBNET::Spritesets::Canvas::Layout::factors, avg 35µs/call
# spent 1.40ms making 144 calls to List::MoreUtils::uniq, avg 10µs/call |
| 74 | map { factors($_) } @_; | ||||
| 75 | 144 | 2.24ms | return $product; | ||
| 76 | } | ||||
| 77 | # EO sub lcm | ||||
| 78 | |||||
| 79 | #################################################################################################### | ||||
| 80 | |||||
| 81 | # snap value to given multiplier | ||||
| 82 | # ****************************************************************************** | ||||
| 83 | sub snap | ||||
| 84 | # spent 108ms within OCBNET::Spritesets::Canvas::Layout::snap which was called 9568 times, avg 11µs/call:
# 4712 times (54.0ms+0s) by OCBNET::Spritesets::Container::layout at line 159 of webmerge/scripts/modules/OCBNET/Spritesets/Container.pm, avg 11µs/call
# 4712 times (52.2ms+0s) by OCBNET::Spritesets::Container::layout at line 160 of webmerge/scripts/modules/OCBNET/Spritesets/Container.pm, avg 11µs/call
# 12 times (166µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 247, avg 14µs/call
# 12 times (133µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 300, avg 11µs/call
# 12 times (124µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 355, avg 10µs/call
# 12 times (122µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 261, avg 10µs/call
# 12 times (122µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 269, avg 10µs/call
# 12 times (120µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 301, avg 10µs/call
# 12 times (115µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 270, avg 10µs/call
# 12 times (115µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 248, avg 10µs/call
# 12 times (114µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 356, avg 10µs/call
# 12 times (113µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 262, avg 9µs/call
# 12 times (111µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 271, avg 9µs/call
# 12 times (110µs+0s) by OCBNET::Spritesets::Canvas::Layout::layout at line 272, avg 9µs/call | ||||
| 85 | # get rest by modulo divide | ||||
| 86 | 9568 | 32.1ms | my $rest = $_[0] % $_[1]; | ||
| 87 | # add rest to fill up to multipler | ||||
| 88 | 9568 | 170ms | $_[0] += $rest ? $_[1] - $rest : 0; | ||
| 89 | } | ||||
| 90 | # EO sub snap | ||||
| 91 | |||||
| 92 | #################################################################################################### | ||||
| 93 | |||||
| 94 | # layout all child nodes | ||||
| 95 | # updates dimensions and positions | ||||
| 96 | # ****************************************************************************** | ||||
| 97 | sub layout | ||||
| 98 | # spent 92.7s (408ms+92.3) within OCBNET::Spritesets::Canvas::Layout::layout which was called 12 times, avg 7.73s/call:
# 12 times (408ms+92.3s) by OCBNET::Spritesets::CSS::Parser::write at line 410 of webmerge/scripts/modules/OCBNET/Spritesets/CSS/Parser.pm, avg 7.73s/call | ||||
| 99 | |||||
| 100 | # get our object | ||||
| 101 | 12 | 45µs | my ($self) = shift; | ||
| 102 | |||||
| 103 | ########################################################## | ||||
| 104 | # CALL LAYOUT ON EACH AREA | ||||
| 105 | ########################################################## | ||||
| 106 | |||||
| 107 | # call layout method on all areas | ||||
| 108 | 12 | 2.61ms | 168 | 92.0s | $_->layout(@_) foreach ($self->areas); # spent 91.2s making 12 calls to OCBNET::Spritesets::Fit::layout, avg 7.60s/call
# spent 534ms making 48 calls to OCBNET::Spritesets::Edge::layout, avg 11.1ms/call
# spent 192ms making 48 calls to OCBNET::Spritesets::Stack::layout, avg 4.01ms/call
# spent 60.7ms making 48 calls to OCBNET::Spritesets::Corner::layout, avg 1.26ms/call
# spent 663µs making 12 calls to OCBNET::Spritesets::Canvas::areas, avg 55µs/call |
| 109 | |||||
| 110 | ########################################################## | ||||
| 111 | # GET MULTIPLIERS FOR DIMENSIONS AND REPEATING | ||||
| 112 | ########################################################## | ||||
| 113 | |||||
| 114 | # declare repating arrays | ||||
| 115 | 12 | 43µs | my (%repeat_x, %repeat_y); | ||
| 116 | |||||
| 117 | # process all sprites in canvas | ||||
| 118 | 12 | 1.64ms | 12 | 2.67ms | foreach my $sprite ($self->sprites) # spent 2.67ms making 12 calls to OCBNET::Spritesets::Canvas::sprites, avg 222µs/call |
| 119 | { | ||||
| 120 | |||||
| 121 | # skip not distributed sprites | ||||
| 122 | 4928 | 9.92ms | next unless $sprite->{'distributed'}; | ||
| 123 | |||||
| 124 | # assertion for not repeating in both directions | ||||
| 125 | 4744 | 43.5ms | 4976 | 49.7ms | if ($sprite->isRepeatX && $sprite->isRepeatY) # spent 47.3ms making 4744 calls to OCBNET::Spritesets::Sprite::isRepeatX, avg 10µs/call
# spent 2.40ms making 232 calls to OCBNET::Spritesets::Sprite::isRepeatY, avg 10µs/call |
| 126 | { die "fatal: cannot repeat in both directions"; } | ||||
| 127 | |||||
| 128 | # make sure we can repeat this sprite perfectly | ||||
| 129 | 4744 | 44.9ms | 4976 | 52.8ms | if ($sprite->isRepeatX && $sprite->isFlexibleX) # spent 45.1ms making 4744 calls to OCBNET::Spritesets::Sprite::isRepeatX, avg 10µs/call
# spent 7.75ms making 232 calls to OCBNET::Spritesets::Sprite::isFlexibleX, avg 33µs/call |
| 130 | { | ||||
| 131 | 64 | 1.45ms | 128 | 5.23ms | my @factors = factors($sprite->width); # spent 4.55ms making 64 calls to OCBNET::Spritesets::Canvas::Layout::factors, avg 71µs/call
# spent 679µs making 64 calls to OCBNET::Spritesets::Block::width, avg 11µs/call |
| 132 | 128 | 969µs | my %factors; ++ $factors{$_} foreach @factors; | ||
| 133 | 64 | 724µs | foreach (keys %factors) | ||
| 134 | { | ||||
| 135 | 128 | 180µs | $repeat_x{$_} = 0 unless exists $repeat_x{$_}; | ||
| 136 | 128 | 184µs | next if $repeat_x{$_} > $factors{$_}; | ||
| 137 | 128 | 418µs | $repeat_x{$_} = $factors{$_}; | ||
| 138 | } | ||||
| 139 | } | ||||
| 140 | |||||
| 141 | # make sure we can repeat this sprite perfectly | ||||
| 142 | 4744 | 54.9ms | 4976 | 54.0ms | if ($sprite->isRepeatY && $sprite->isFlexibleY) # spent 46.4ms making 4744 calls to OCBNET::Spritesets::Sprite::isRepeatY, avg 10µs/call
# spent 7.62ms making 232 calls to OCBNET::Spritesets::Sprite::isFlexibleY, avg 33µs/call |
| 143 | { | ||||
| 144 | |||||
| 145 | 64 | 1.47ms | 128 | 5.62ms | my @factors = factors($sprite->height); # spent 4.94ms making 64 calls to OCBNET::Spritesets::Canvas::Layout::factors, avg 77µs/call
# spent 676µs making 64 calls to OCBNET::Spritesets::Block::height, avg 11µs/call |
| 146 | 128 | 1.00ms | my %factors; ++ $factors{$_} foreach @factors; | ||
| 147 | 64 | 799µs | foreach (keys %factors) | ||
| 148 | { | ||||
| 149 | 128 | 195µs | $repeat_y{$_} = 0 unless exists $repeat_y{$_}; | ||
| 150 | 128 | 186µs | next if $repeat_y{$_} > $factors{$_}; | ||
| 151 | 128 | 433µs | $repeat_y{$_} = $factors{$_}; | ||
| 152 | } | ||||
| 153 | } | ||||
| 154 | |||||
| 155 | } | ||||
| 156 | # EO each sprite | ||||
| 157 | |||||
| 158 | # calculate the lowest denominator for repeating snaping values | ||||
| 159 | 24 | 343µs | my $repeat_x = 1; $repeat_x *= $_ ** $repeat_x{$_} foreach keys %repeat_x; | ||
| 160 | 24 | 215µs | my $repeat_y = 1; $repeat_y *= $_ ** $repeat_y{$_} foreach keys %repeat_y; | ||
| 161 | |||||
| 162 | ########################################################## | ||||
| 163 | # GET LIMITS FROM SNAPPED ELEMENTS | ||||
| 164 | ########################################################## | ||||
| 165 | |||||
| 166 | 12 | 863µs | 60 | 9.29ms | my $col1_snap_w = lcm( # spent 6.09ms making 48 calls to OCBNET::Spritesets::Container::scaleX, avg 127µs/call
# spent 3.20ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 267µs/call |
| 167 | $self->{'edge-l'}->scaleX, | ||||
| 168 | $self->{'stack-l'}->scaleX, | ||||
| 169 | $self->{'corner-lb'}->scaleX, | ||||
| 170 | $self->{'corner-lt'}->scaleX | ||||
| 171 | ); | ||||
| 172 | 12 | 789µs | 60 | 8.24ms | my $row1_snap_h = lcm( # spent 5.27ms making 48 calls to OCBNET::Spritesets::Container::scaleY, avg 110µs/call
# spent 2.98ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 248µs/call |
| 173 | $self->{'edge-t'}->scaleY, | ||||
| 174 | $self->{'stack-t'}->scaleY, | ||||
| 175 | $self->{'corner-rt'}->scaleY, | ||||
| 176 | $self->{'corner-lt'}->scaleY | ||||
| 177 | ); | ||||
| 178 | |||||
| 179 | 12 | 569µs | 48 | 3.68ms | my $col2_snap_w = lcm( # spent 2.25ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 187µs/call
# spent 1.44ms making 36 calls to OCBNET::Spritesets::Container::scaleX, avg 40µs/call |
| 180 | $self->{'stack-t'}->scaleX, | ||||
| 181 | $self->{'middle'}->scaleX, | ||||
| 182 | $self->{'stack-b'}->scaleX | ||||
| 183 | ); | ||||
| 184 | 12 | 534µs | 48 | 3.66ms | my $row2_snap_h = lcm( # spent 2.32ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 194µs/call
# spent 1.34ms making 36 calls to OCBNET::Spritesets::Container::scaleY, avg 37µs/call |
| 185 | $self->{'stack-l'}->scaleY, | ||||
| 186 | $self->{'middle'}->scaleY, | ||||
| 187 | $self->{'stack-r'}->scaleY | ||||
| 188 | ); | ||||
| 189 | |||||
| 190 | 12 | 277µs | 24 | 1.67ms | my $col3_snap_w = lcm($self->{'edge-t'}->scaleX); # spent 1.08ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 90µs/call
# spent 593µs making 12 calls to OCBNET::Spritesets::Container::scaleX, avg 49µs/call |
| 191 | 12 | 255µs | 24 | 1.62ms | my $row3_snap_h = lcm($self->{'edge-l'}->scaleY); # spent 1.06ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 88µs/call
# spent 560µs making 12 calls to OCBNET::Spritesets::Container::scaleY, avg 47µs/call |
| 192 | 12 | 259µs | 24 | 1.65ms | my $col4_snap_w = lcm($self->{'edge-b'}->scaleX); # spent 1.07ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 89µs/call
# spent 581µs making 12 calls to OCBNET::Spritesets::Container::scaleX, avg 48µs/call |
| 193 | 12 | 244µs | 24 | 1.63ms | my $row4_snap_h = lcm($self->{'edge-r'}->scaleY); # spent 1.07ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 89µs/call
# spent 558µs making 12 calls to OCBNET::Spritesets::Container::scaleY, avg 47µs/call |
| 194 | |||||
| 195 | 12 | 681µs | 60 | 8.35ms | my $col_snap_last_w = lcm( # spent 5.45ms making 48 calls to OCBNET::Spritesets::Container::scaleX, avg 113µs/call
# spent 2.90ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 241µs/call |
| 196 | $self->{'edge-r'}->scaleX, | ||||
| 197 | $self->{'stack-r'}->scaleX, | ||||
| 198 | $self->{'corner-rb'}->scaleX, | ||||
| 199 | $self->{'corner-rt'}->scaleX | ||||
| 200 | ); | ||||
| 201 | |||||
| 202 | 12 | 692µs | 60 | 7.91ms | my $row_snap_last_h = lcm( # spent 5.09ms making 48 calls to OCBNET::Spritesets::Container::scaleY, avg 106µs/call
# spent 2.82ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 235µs/call |
| 203 | $self->{'edge-b'}->scaleY, | ||||
| 204 | $self->{'stack-b'}->scaleY, | ||||
| 205 | $self->{'corner-lb'}->scaleY, | ||||
| 206 | $self->{'corner-rb'}->scaleY | ||||
| 207 | ); | ||||
| 208 | |||||
| 209 | 12 | 140µs | 12 | 4.32ms | my $col_snap_w = lcm( # spent 4.32ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 360µs/call |
| 210 | $repeat_x, | ||||
| 211 | $col1_snap_w, | ||||
| 212 | $col2_snap_w, | ||||
| 213 | $col3_snap_w, | ||||
| 214 | $col4_snap_w, | ||||
| 215 | $col_snap_last_w | ||||
| 216 | ); | ||||
| 217 | |||||
| 218 | 12 | 124µs | 12 | 4.12ms | my $row_snap_h = lcm( # spent 4.12ms making 12 calls to OCBNET::Spritesets::Canvas::Layout::lcm, avg 344µs/call |
| 219 | $repeat_y, | ||||
| 220 | $row1_snap_h, | ||||
| 221 | $row2_snap_h, | ||||
| 222 | $row3_snap_h, | ||||
| 223 | $row4_snap_h, | ||||
| 224 | $row_snap_last_h | ||||
| 225 | ); | ||||
| 226 | |||||
| 227 | ########################################################## | ||||
| 228 | # GET LIMITS FROM SNAPPED ELEMENTS | ||||
| 229 | ########################################################## | ||||
| 230 | |||||
| 231 | 2 | 5.61ms | 2 | 17.0ms | # spent 16.6ms (1.36+15.3) within OCBNET::Spritesets::Canvas::Layout::BEGIN@231 which was called:
# once (1.36ms+15.3ms) by OCBNET::Spritesets::Canvas::BEGIN@18 at line 231 # spent 16.6ms making 1 call to OCBNET::Spritesets::Canvas::Layout::BEGIN@231
# spent 410µs making 1 call to Exporter::import |
| 232 | |||||
| 233 | 12 | 1.00ms | 60 | 4.35ms | my $col1_w = max( # spent 4.23ms making 48 calls to OCBNET::Spritesets::Block::outerWidth, avg 88µs/call
# spent 114µs making 12 calls to List::Util::max, avg 10µs/call |
| 234 | $self->{'edge-l'}->outerWidth, | ||||
| 235 | $self->{'stack-l'}->outerWidth, | ||||
| 236 | $self->{'corner-lb'}->outerWidth, | ||||
| 237 | $self->{'corner-lt'}->outerWidth | ||||
| 238 | ); | ||||
| 239 | |||||
| 240 | 12 | 857µs | 60 | 4.14ms | my $row1_h = max( # spent 4.07ms making 48 calls to OCBNET::Spritesets::Block::outerHeight, avg 85µs/call
# spent 71µs making 12 calls to List::Util::max, avg 6µs/call |
| 241 | $self->{'edge-t'}->outerHeight, | ||||
| 242 | $self->{'stack-t'}->outerHeight, | ||||
| 243 | $self->{'corner-rt'}->outerHeight, | ||||
| 244 | $self->{'corner-lt'}->outerHeight | ||||
| 245 | ); | ||||
| 246 | |||||
| 247 | 12 | 113µs | 12 | 166µs | snap ($col1_w, $col1_snap_w); # spent 166µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 14µs/call |
| 248 | 12 | 89µs | 12 | 115µs | snap ($row1_h, $row1_snap_h); # spent 115µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call |
| 249 | |||||
| 250 | 12 | 678µs | 48 | 2.97ms | my $col2_w = max( # spent 2.90ms making 36 calls to OCBNET::Spritesets::Block::outerWidth, avg 81µs/call
# spent 72µs making 12 calls to List::Util::max, avg 6µs/call |
| 251 | $self->{'stack-t'}->outerWidth, | ||||
| 252 | $self->{'middle'}->outerWidth, | ||||
| 253 | $self->{'stack-b'}->outerWidth | ||||
| 254 | ); | ||||
| 255 | 12 | 650µs | 48 | 2.98ms | my $row2_h = max( # spent 2.91ms making 36 calls to OCBNET::Spritesets::Block::outerHeight, avg 81µs/call
# spent 73µs making 12 calls to List::Util::max, avg 6µs/call |
| 256 | $self->{'stack-l'}->outerHeight, | ||||
| 257 | $self->{'middle'}->outerHeight, | ||||
| 258 | $self->{'stack-r'}->outerHeight | ||||
| 259 | ); | ||||
| 260 | |||||
| 261 | 12 | 92µs | 12 | 122µs | snap ($col2_w, $col2_snap_w); # spent 122µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call |
| 262 | 12 | 92µs | 12 | 113µs | snap ($row2_h, $row2_snap_h); # spent 113µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 9µs/call |
| 263 | |||||
| 264 | 12 | 151µs | 12 | 952µs | my $col3_w = $self->{'edge-t'}->outerWidth; # spent 952µs making 12 calls to OCBNET::Spritesets::Block::outerWidth, avg 79µs/call |
| 265 | 12 | 149µs | 12 | 984µs | my $row3_h = $self->{'edge-l'}->outerHeight; # spent 984µs making 12 calls to OCBNET::Spritesets::Block::outerHeight, avg 82µs/call |
| 266 | 12 | 142µs | 12 | 946µs | my $col4_w = $self->{'edge-b'}->outerWidth; # spent 946µs making 12 calls to OCBNET::Spritesets::Block::outerWidth, avg 79µs/call |
| 267 | 12 | 154µs | 12 | 1.01ms | my $row4_h = $self->{'edge-r'}->outerHeight; # spent 1.01ms making 12 calls to OCBNET::Spritesets::Block::outerHeight, avg 85µs/call |
| 268 | |||||
| 269 | 12 | 97µs | 12 | 122µs | snap ($col3_w, $col3_snap_w); # spent 122µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call |
| 270 | 12 | 88µs | 12 | 115µs | snap ($row3_h, $row3_snap_h); # spent 115µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call |
| 271 | 12 | 87µs | 12 | 111µs | snap ($col4_w, $col4_snap_w); # spent 111µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 9µs/call |
| 272 | 12 | 90µs | 12 | 110µs | snap ($row4_h, $row4_snap_h); # spent 110µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 9µs/call |
| 273 | |||||
| 274 | 12 | 752µs | 60 | 3.82ms | my $col_last_w = max( # spent 3.75ms making 48 calls to OCBNET::Spritesets::Block::outerWidth, avg 78µs/call
# spent 76µs making 12 calls to List::Util::max, avg 6µs/call |
| 275 | $self->{'edge-r'}->outerWidth, | ||||
| 276 | $self->{'stack-r'}->outerWidth, | ||||
| 277 | $self->{'corner-rb'}->outerWidth, | ||||
| 278 | $self->{'corner-rt'}->outerWidth | ||||
| 279 | ); | ||||
| 280 | |||||
| 281 | 12 | 740µs | 60 | 3.85ms | my $row_last_h = max( # spent 3.78ms making 48 calls to OCBNET::Spritesets::Block::outerHeight, avg 79µs/call
# spent 70µs making 12 calls to List::Util::max, avg 6µs/call |
| 282 | $self->{'edge-b'}->outerHeight, | ||||
| 283 | $self->{'stack-b'}->outerHeight, | ||||
| 284 | $self->{'corner-lb'}->outerHeight, | ||||
| 285 | $self->{'corner-rb'}->outerHeight | ||||
| 286 | ); | ||||
| 287 | |||||
| 288 | 12 | 13µs | my $col1_x = $col1_w; | ||
| 289 | 12 | 12µs | my $row1_y = $row1_h; | ||
| 290 | |||||
| 291 | 12 | 32µs | my $col2_x = $col1_x + $col2_w; | ||
| 292 | 12 | 14µs | my $row2_y = $row1_y + $row2_h; | ||
| 293 | |||||
| 294 | # make sure both sides will fit our repeating pattern | ||||
| 295 | # this can blow up the sprite by quite some factor if your image | ||||
| 296 | # dimensions have lots of different factors in it, if they are all | ||||
| 297 | # about the same size and not too big, this should work quite well | ||||
| 298 | 12 | 18µs | my $snap_w = $col2_x + $col3_w + $col4_w + $col_last_w; | ||
| 299 | 12 | 32µs | my $snap_h = $row2_y + $row3_h + $row4_h + $row_last_h; | ||
| 300 | 12 | 109µs | 12 | 133µs | snap(my $snapped_w = $snap_w, $repeat_x); # spent 133µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 11µs/call |
| 301 | 12 | 97µs | 12 | 120µs | snap(my $snapped_h = $snap_h, $repeat_y); # spent 120µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call |
| 302 | 12 | 30µs | $col2_x += $snapped_w - $snap_w; | ||
| 303 | 12 | 17µs | $row2_y += $snapped_h - $snap_h; | ||
| 304 | |||||
| 305 | 12 | 16µs | my $col3_x = $col2_x + $col3_w; | ||
| 306 | 12 | 13µs | my $col4_x = $col3_x + $col4_w; | ||
| 307 | |||||
| 308 | 12 | 13µs | my $row3_y = $row2_y + $row3_h; | ||
| 309 | 12 | 11µs | my $row4_y = $row3_y + $row4_h; | ||
| 310 | |||||
| 311 | ########################################################## | ||||
| 312 | # CALCULATE LAYOUT | ||||
| 313 | ########################################################## | ||||
| 314 | |||||
| 315 | 12 | 8µs | my $width = 0; | ||
| 316 | 12 | 8µs | my $height = 0; | ||
| 317 | |||||
| 318 | ########################################################## | ||||
| 319 | # we have 13 areas, so 26 positions to set | ||||
| 320 | ########################################################## | ||||
| 321 | |||||
| 322 | # leave the first row in place (8) | ||||
| 323 | 12 | 190µs | 12 | 142µs | $self->{'corner-lt'}->top = 0; # spent 142µs making 12 calls to OCBNET::Spritesets::Block::top, avg 12µs/call |
| 324 | 12 | 168µs | 12 | 137µs | $self->{'corner-lt'}->left = 0; # spent 137µs making 12 calls to OCBNET::Spritesets::Block::left, avg 11µs/call |
| 325 | 12 | 151µs | 12 | 115µs | $self->{'stack-t'}->top = 0; # spent 115µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call |
| 326 | 12 | 153µs | 12 | 117µs | $self->{'stack-l'}->left = 0; # spent 117µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call |
| 327 | 12 | 160µs | 12 | 117µs | $self->{'edge-t'}->top = 0; # spent 117µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call |
| 328 | 12 | 146µs | 12 | 118µs | $self->{'edge-l'}->left = 0; # spent 118µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call |
| 329 | 12 | 132µs | 12 | 114µs | $self->{'corner-rt'}->top = 0; # spent 114µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call |
| 330 | 12 | 134µs | 12 | 112µs | $self->{'corner-lb'}->left = 0; # spent 112µs making 12 calls to OCBNET::Spritesets::Block::left, avg 9µs/call |
| 331 | |||||
| 332 | ########################################################## | ||||
| 333 | |||||
| 334 | # move the second row aways (6) | ||||
| 335 | 12 | 138µs | 12 | 113µs | $self->{'stack-l'}->top = $row1_y; # spent 113µs making 12 calls to OCBNET::Spritesets::Block::top, avg 9µs/call |
| 336 | 12 | 155µs | 12 | 114µs | $self->{'middle'}->top = $row1_y; # spent 114µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call |
| 337 | 12 | 133µs | 12 | 111µs | $self->{'stack-r'}->top = $row1_y; # spent 111µs making 12 calls to OCBNET::Spritesets::Block::top, avg 9µs/call |
| 338 | 12 | 136µs | 12 | 113µs | $self->{'stack-t'}->left = $col1_x; # spent 113µs making 12 calls to OCBNET::Spritesets::Block::left, avg 9µs/call |
| 339 | 12 | 149µs | 12 | 115µs | $self->{'middle'}->left = $col1_x; # spent 115µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call |
| 340 | 12 | 137µs | 12 | 112µs | $self->{'stack-b'}->left = $col1_x; # spent 112µs making 12 calls to OCBNET::Spritesets::Block::left, avg 9µs/call |
| 341 | |||||
| 342 | ########################################################## | ||||
| 343 | |||||
| 344 | # move the third row aways (4) | ||||
| 345 | 12 | 136µs | 12 | 112µs | $self->{'edge-l'}->top = $row2_y; # spent 112µs making 12 calls to OCBNET::Spritesets::Block::top, avg 9µs/call |
| 346 | 12 | 132µs | 12 | 110µs | $self->{'edge-r'}->top = $row3_y; # spent 110µs making 12 calls to OCBNET::Spritesets::Block::top, avg 9µs/call |
| 347 | 12 | 134µs | 12 | 115µs | $self->{'edge-t'}->left = $col2_x; # spent 115µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call |
| 348 | 12 | 134µs | 12 | 112µs | $self->{'edge-b'}->left = $col3_x; # spent 112µs making 12 calls to OCBNET::Spritesets::Block::left, avg 9µs/call |
| 349 | |||||
| 350 | ########################################################## | ||||
| 351 | |||||
| 352 | 12 | 154µs | 12 | 123µs | my $w = $width = $self->width = $col4_x + $col_last_w; # spent 123µs making 12 calls to OCBNET::Spritesets::Block::width, avg 10µs/call |
| 353 | 12 | 143µs | 12 | 116µs | my $h = $height = $self->height = $row4_y + $row_last_h; # spent 116µs making 12 calls to OCBNET::Spritesets::Block::height, avg 10µs/call |
| 354 | |||||
| 355 | 12 | 96µs | 12 | 124µs | snap ($w, $repeat_x); # spent 124µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call |
| 356 | 12 | 87µs | 12 | 114µs | snap ($h, $repeat_y); # spent 114µs making 12 calls to OCBNET::Spritesets::Canvas::Layout::snap, avg 10µs/call |
| 357 | |||||
| 358 | 12 | 23µs | die "width invalid: $width $w" if $w != $width; | ||
| 359 | 12 | 11µs | die "height invalid: $height $h" if $h != $height; | ||
| 360 | |||||
| 361 | ########################################################## | ||||
| 362 | |||||
| 363 | # move the fourth row aways (8) | ||||
| 364 | # align them to the right / bottom | ||||
| 365 | 12 | 450µs | 36 | 22.5ms | $self->{'corner-rb'}->top = $self->outerHeight - $self->{'corner-rb'}->outerHeight; # spent 22.4ms making 24 calls to OCBNET::Spritesets::Block::outerHeight, avg 934µs/call
# spent 138µs making 12 calls to OCBNET::Spritesets::Block::top, avg 11µs/call |
| 366 | 12 | 461µs | 36 | 2.11ms | $self->{'corner-rb'}->left = $self->outerWidth - $self->{'corner-rb'}->outerWidth; # spent 1.96ms making 24 calls to OCBNET::Spritesets::Block::outerWidth, avg 82µs/call
# spent 152µs making 12 calls to OCBNET::Spritesets::Block::left, avg 13µs/call |
| 367 | 12 | 380µs | 36 | 2.01ms | $self->{'stack-b'}->top = $self->outerHeight - $self->{'stack-b'}->outerHeight; # spent 1.90ms making 24 calls to OCBNET::Spritesets::Block::outerHeight, avg 79µs/call
# spent 116µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call |
| 368 | 12 | 386µs | 36 | 2.05ms | $self->{'stack-r'}->left = $self->outerWidth - $self->{'stack-r'}->outerWidth; # spent 1.93ms making 24 calls to OCBNET::Spritesets::Block::outerWidth, avg 80µs/call
# spent 118µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call |
| 369 | 12 | 383µs | 36 | 2.03ms | $self->{'edge-b'}->top = $self->outerHeight - $self->{'edge-b'}->outerHeight; # spent 1.91ms making 24 calls to OCBNET::Spritesets::Block::outerHeight, avg 80µs/call
# spent 118µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call |
| 370 | 12 | 387µs | 36 | 2.04ms | $self->{'edge-r'}->left = $self->outerWidth - $self->{'edge-r'}->outerWidth; # spent 1.92ms making 24 calls to OCBNET::Spritesets::Block::outerWidth, avg 80µs/call
# spent 119µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call |
| 371 | 12 | 385µs | 36 | 2.03ms | $self->{'corner-lb'}->top = $self->outerHeight - $self->{'corner-lb'}->outerHeight; # spent 1.92ms making 24 calls to OCBNET::Spritesets::Block::outerHeight, avg 80µs/call
# spent 118µs making 12 calls to OCBNET::Spritesets::Block::top, avg 10µs/call |
| 372 | 12 | 388µs | 36 | 2.05ms | $self->{'corner-rt'}->left = $self->outerWidth - $self->{'corner-rt'}->outerWidth; # spent 1.93ms making 24 calls to OCBNET::Spritesets::Block::outerWidth, avg 80µs/call
# spent 121µs making 12 calls to OCBNET::Spritesets::Block::left, avg 10µs/call |
| 373 | |||||
| 374 | ########################################################## | ||||
| 375 | # RE-ALIGN WIDGETS AFTER SNAPPING | ||||
| 376 | ########################################################## | ||||
| 377 | |||||
| 378 | # layout all children | ||||
| 379 | 12 | 368µs | 12 | 583µs | foreach my $area ($self->areas) # spent 583µs making 12 calls to OCBNET::Spritesets::Canvas::areas, avg 49µs/call |
| 380 | { | ||||
| 381 | |||||
| 382 | # ignore area if it's empty | ||||
| 383 | 156 | 1.65ms | 156 | 2.02ms | next if $area->empty; # spent 2.02ms making 156 calls to OCBNET::Spritesets::Container::empty, avg 13µs/call |
| 384 | |||||
| 385 | # adjust layout only for stacked (repeating) elements | ||||
| 386 | 108 | 2.68ms | 108 | 1.10ms | next unless $area->isa('OCBNET::Spritesets::Stack'); # spent 1.10ms making 108 calls to UNIVERSAL::isa, avg 10µs/call |
| 387 | |||||
| 388 | # re-align the sub area | ||||
| 389 | 64 | 1.51ms | 144 | 1.46ms | if ($area->alignOpp) # spent 650µs making 64 calls to OCBNET::Spritesets::Stack::alignOpp, avg 10µs/call
# spent 339µs making 32 calls to OCBNET::Spritesets::Stack::stackVert, avg 11µs/call
# spent 313µs making 32 calls to OCBNET::Spritesets::Block::width, avg 10µs/call
# spent 162µs making 16 calls to OCBNET::Spritesets::Block::left, avg 10µs/call |
| 390 | { | ||||
| 391 | if ($area->stackVert) | ||||
| 392 | { $area->left = $self->width - $area->width; } | ||||
| 393 | 16 | 470µs | 48 | 463µs | else { $area->top = $self->height - $area->height; } # spent 309µs making 32 calls to OCBNET::Spritesets::Block::height, avg 10µs/call
# spent 154µs making 16 calls to OCBNET::Spritesets::Block::top, avg 10µs/call |
| 394 | } | ||||
| 395 | |||||
| 396 | } | ||||
| 397 | # EO each area | ||||
| 398 | |||||
| 399 | # return success | ||||
| 400 | 12 | 633µs | return $self; | ||
| 401 | |||||
| 402 | } | ||||
| 403 | # EO sub layout | ||||
| 404 | |||||
| 405 | #################################################################################################### | ||||
| 406 | #################################################################################################### | ||||
| 407 | 1 | 13µs | 1; | ||
# spent 2.51ms within OCBNET::Spritesets::Canvas::Layout::CORE:sort which was called 584 times, avg 4µs/call:
# 584 times (2.51ms+0s) by OCBNET::Spritesets::Canvas::Layout::factors at line 60, avg 4µs/call |