| 1 | package TUI::App::DeskTop; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: TDeskTop manages the screen area, owning different views. | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 38 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 38 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 38 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 38 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 38 | our $VERSION = '2.000002'; | |||||||||||||||||||||||||||
| 10 | 38 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 11 | 38 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 38 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 38 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 15 | TDeskTop | ||||||||||||||||||||||||||||
| 16 | new_TDeskTop | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 38 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 38 | ▶ | use Encode qw( encode ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 38 | ▶ | use Scalar::Util qw( weaken ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 38 | ▶ | use TUI::toolkit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 38 | ▶ | use TUI::toolkit::Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | :is | ||||||||||||||||||||||||||||
| 25 | Object | ||||||||||||||||||||||||||||
| 26 | 38 | ); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 38 | ▶ | use TUI::App::Background; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 38 | ▶ | use TUI::App::DeskInit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 38 | ▶ | use TUI::Drivers::Const qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | evCommand | ||||||||||||||||||||||||||||
| 32 | 38 | ); | |||||||||||||||||||||||||||
| 33 | 38 | ▶ | use TUI::Objects::Point; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 38 | ▶ | use TUI::Objects::Rect; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 38 | ▶ | use TUI::Views::Const qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | :cmXXXX | ||||||||||||||||||||||||||||
| 37 | :gfXXXX | ||||||||||||||||||||||||||||
| 38 | ofTileable | ||||||||||||||||||||||||||||
| 39 | sfVisible | ||||||||||||||||||||||||||||
| 40 | 38 | ); | |||||||||||||||||||||||||||
| 41 | 38 | ▶ | use TUI::Views::Group; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub TDeskTop() { __PACKAGE__ } | ||||||||||||||||||||||||||||
| 44 | sub name() { 'TDeskTop' } | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub new_TDeskTop { __PACKAGE__->from(@_) } | ||||||||||||||||||||||||||
|
Subroutine
new_TDeskTop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 38 | extends ( TGroup, TDeskInit ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # Moo does not inherit attributes from secondary extends() classes. | ||||||||||||||||||||||||||||
| 50 | # Redeclare attribute provided by TDeskInit. | ||||||||||||||||||||||||||||
| 51 | 38 | ▶ | if ( TUI::toolkit::is_Moo ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | has createBackground => ( is => 'bare', default => sub { die 'required' } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # declare global variables | ||||||||||||||||||||||||||||
| 56 | 38 | our $defaultBkgrnd = encode( cp437 => "░" ); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # protected attributes | ||||||||||||||||||||||||||||
| 59 | 38 | has background => ( is => 'ro' ); | |||||||||||||||||||||||||||
| 60 | 38 | has tileColumnsFirst => ( is => 'ro' ); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub BUILDARGS { # \%args (%args) | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 64 | method => 1, | ||||||||||||||||||||||||||||
| 65 | named => [ | ||||||||||||||||||||||||||||
| 66 | bounds => Object, | ||||||||||||||||||||||||||||
| 67 | ], | ||||||||||||||||||||||||||||
| 68 | caller_level => +1, | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | 0 | my ( $class, $args1 ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 71 | 0 | local $Carp::CarpLevel = $Carp::CarpLevel + 1; | |||||||||||||||||||||||||||
| 72 | 0 | my $args2 = TDeskInit->BUILDARGS( | |||||||||||||||||||||||||||
| 73 | cBackground => $class->can( 'initBackground' ), | ||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | 0 | return { %$args1, %$args2 }; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub BUILD { # void (\%args) | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 0 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | $self->{growMode} = gfGrowHiX | gfGrowHiY; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ( $self->{createBackground} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"createBackground"} and $self->{"background"} = $self->createBackground($self->getExtent)
MC/DC0%0/2
$self->{"createBackground"} and $self->{"background"} = $self->createBackground($self->getExtent)
$self->{"createBackground"}
$self->{"background"} = $self->createBackground($self->getExtent)
Truth table0%0/3
A and B
A= $self->{"createBackground"}B= $self->{"background"} = $self->createBackground($self->getExtent)
| |||||||||||||||||||||||||||||
| 85 | && ( $self->{background} = $self->createBackground( $self->getExtent() ) ) | ||||||||||||||||||||||||||||
| 86 | ) { | ||||||||||||||||||||||||||||
| 87 | 0 | $self->insert( $self->{background} ); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 0 | return; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub from { # $obj ($bounds) | ||||||||||||||||||||||||||
|
Subroutine
from: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 93 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 94 | method => 1, | ||||||||||||||||||||||||||||
| 95 | pos => [Object], | ||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||
| 97 | 0 | my ( $class, $bounds ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 98 | 0 | return $class->new( bounds => $bounds ); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $Tileable = sub { # void ($p) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 102 | 0 | my ( $p ) = @_; | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | assert ( is_Object $p ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | return ( $p->{options} & ofTileable ) && ( $p->{state} & sfVisible ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$p->{'options'} & 128 && $p->{'state'} & 1
MC/DC0%0/2
$p->{'options'} & 128 && $p->{'state'} & 1
$p->{'options'} & 128
$p->{'state'} & 1
Truth table0%0/3
A && B
A= $p->{'options'} & 128B= $p->{'state'} & 1
| |||||||||||||||||||||||||||||
| 106 | 38 | }; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 38 | my $cascadeNum; | |||||||||||||||||||||||||||
| 109 | my $lastView; | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my $doCount = sub { # void ($p, @) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 112 | 0 | my ( $p ) = @_; | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | assert ( @_ >= 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | assert ( is_Object $p ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ( $p->$Tileable() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | $cascadeNum++; | |||||||||||||||||||||||||||
| 117 | 0 | weaken( $lastView = $p ); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 0 | return; | |||||||||||||||||||||||||||
| 120 | 38 | }; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my $doCascade = sub { # void ($p, $r) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 123 | 0 | my ( $p, $r ) = @_; | |||||||||||||||||||||||||||
| 124 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | assert ( is_Object $p ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | assert ( is_Object $r ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ( $p->$Tileable() && $cascadeNum >= 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p->$Tileable and $cascadeNum >= 0
MC/DC0%0/2
$p->$Tileable and $cascadeNum >= 0
$p->$Tileable
$cascadeNum >= 0
Truth table0%0/3
A and B
A= $p->$TileableB= $cascadeNum >= 0
| |||||||||||||||||||||||||||||
| 128 | 0 | my $NR = $r->clone(); | |||||||||||||||||||||||||||
| 129 | 0 | $NR->{a}{x} += $cascadeNum; | |||||||||||||||||||||||||||
| 130 | 0 | $NR->{a}{y} += $cascadeNum; | |||||||||||||||||||||||||||
| 131 | 0 | $p->locate( $NR ); | |||||||||||||||||||||||||||
| 132 | 0 | $cascadeNum--; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 0 | return; | |||||||||||||||||||||||||||
| 135 | 38 | }; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub cascade { # void ($r) | ||||||||||||||||||||||||||
|
Subroutine
cascade: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 139 | method => Object, | ||||||||||||||||||||||||||||
| 140 | pos => [Object], | ||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||
| 142 | 0 | my ( $self, $r ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 143 | 0 | my $min = TPoint->new(); | |||||||||||||||||||||||||||
| 144 | 0 | my $max = TPoint->new(); | |||||||||||||||||||||||||||
| 145 | 0 | $cascadeNum = 0; | |||||||||||||||||||||||||||
| 146 | 0 | $self->forEach( $doCount, undef ); | |||||||||||||||||||||||||||
| 147 | 0 | ▶ | if ( $cascadeNum > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | $lastView->sizeLimits( $min, $max ); | |||||||||||||||||||||||||||
| 149 | 0 | ▶ | if ( ( $min->{x} > $r->{b}{x} - $r->{a}{x} - $cascadeNum ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$min->{"x"} > $r->{"b"}{"x"} - $r->{"a"}{"x"} - $cascadeNum or $min->{"y"} > $r->{"b"}{"y"} - $r->{"a"}{"y"} - $cascadeNum
MC/DC0%0/2
$min->{"x"} > $r->{"b"}{"x"} - $r->{"a"}{"x"} - $cascadeNum or $min->{"y"} > $r->{"b"}{"y"} - $r->{"a"}{"y"} - $cascadeNum
$min->{"x"} > $r->{"b"}{"x"} - $r->{"a"}{"x"} - $cascadeNum
$min->{"y"} > $r->{"b"}{"y"} - $r->{"a"}{"y"} - $cascadeNum
Truth table0%0/3
A or B
A= $min->{"x"} > $r->{"b"}{"x"} - $r->{"a"}{"x"} - $cascadeNumB= $min->{"y"} > $r->{"b"}{"y"} - $r->{"a"}{"y"} - $cascadeNum
| |||||||||||||||||||||||||||||
| 150 | || ( $min->{y} > $r->{b}{y} - $r->{a}{y} - $cascadeNum ) ) | ||||||||||||||||||||||||||||
| 151 | { | ||||||||||||||||||||||||||||
| 152 | 0 | $self->tileError(); | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | else { | ||||||||||||||||||||||||||||
| 155 | 0 | $cascadeNum--; | |||||||||||||||||||||||||||
| 156 | 0 | $self->lock(); | |||||||||||||||||||||||||||
| 157 | 0 | $self->forEach( $doCascade, $r ); | |||||||||||||||||||||||||||
| 158 | 0 | $self->unlock(); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub handleEvent { # void ($event) | ||||||||||||||||||||||||||
|
Subroutine
handleEvent: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 164 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 165 | method => Object, | ||||||||||||||||||||||||||||
| 166 | pos => [Object], | ||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||
| 168 | 0 | my ( $self, $event ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 169 | 0 | $self->SUPER::handleEvent( $event ); | |||||||||||||||||||||||||||
| 170 | 0 | ▶ | if ( $event->{what} == evCommand ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | SWITCH: for ( $event->{message}{command} ) { | |||||||||||||||||||||||||||
| 172 | 0 | ▶ | cmNext == $_ and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 0 | ▶ | $self->selectNext( false ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | if $self->valid( cmReleasedFocus ); # <-- Check valid. | ||||||||||||||||||||||||||||
| 175 | 0 | last; | |||||||||||||||||||||||||||
| 176 | }; | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | cmPrev == $_ and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | $self->{current}->putInFrontOf( $self->{background} ) | ||||||||||||||||||||||||||||
| 179 | 0 | ▶ | if $self->valid( cmReleasedFocus ); # <-- Check valid. | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 0 | last; | |||||||||||||||||||||||||||
| 181 | }; | ||||||||||||||||||||||||||||
| 182 | DEFAULT: { | ||||||||||||||||||||||||||||
| 183 | 0 | return; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | 0 | $self->clearEvent( $event ); | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub initBackground { # $background ($r) | ||||||||||||||||||||||||||
|
Subroutine
initBackground: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 191 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 192 | method => 1, | ||||||||||||||||||||||||||||
| 193 | pos => [Object], | ||||||||||||||||||||||||||||
| 194 | ); | ||||||||||||||||||||||||||||
| 195 | 0 | my ( $class, $r ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 196 | 0 | return TBackground->new( bounds => $r, pattern => $defaultBkgrnd ); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 38 | my ( $numCols, $numRows, $numTileable, $leftOver, $tileNum ); | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | my $iSqr = sub { # void ($i) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 202 | 0 | my ( $i ) = @_; | |||||||||||||||||||||||||||
| 203 | 0 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 0 | ▶ | assert ( is_Int $i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 0 | my ( $res1, $res2 ) = ( 2, int( $i / 2 ) ); | |||||||||||||||||||||||||||
| 206 | 0 | ▶ | while ( abs( $res1 - $res2 ) > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | $res1 = int( ( $res1 + $res2 ) / 2 ); | |||||||||||||||||||||||||||
| 208 | 0 | $res2 = int( $i / $res1 ); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | 0 | ▶ | return $res1 < $res2 ? $res1 : $res2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 38 | }; | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my $mostEqualDivisors = sub { # void ($n, $x, $y, $favorY) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||
| 214 | 0 | my ( $n, $x, $y, $favorY ) = @_; | |||||||||||||||||||||||||||
| 215 | 0 | ▶ | assert ( @_ == 4 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | ▶ | assert ( is_Int $n ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 0 | ▶ | assert ( is_Int $x ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 0 | ▶ | assert ( is_Int $y ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | 0 | ▶ | assert ( is_Bool $favorY ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 0 | alias: for $x ( $_[1] ) { | |||||||||||||||||||||||||||
| 221 | 0 | alias: for $y ( $_[2] ) { | |||||||||||||||||||||||||||
| 222 | 0 | my $i = &$iSqr( $n ); | |||||||||||||||||||||||||||
| 223 | 0 | ▶ | $i++ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$n % $i != 0 and $n % ($i + 1) == 0
MC/DC0%0/2
$n % $i != 0 and $n % ($i + 1) == 0
$n % $i != 0
$n % ($i + 1) == 0
Truth table0%0/3
A and B
A= $n % $i != 0B= $n % ($i + 1) == 0
| |||||||||||||||||||||||||||||
| 224 | if $n % $i != 0 && $n % ( $i + 1 ) == 0; | ||||||||||||||||||||||||||||
| 225 | 0 | ▶ | $i = int( $n / $i ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | if $i < int( $n / $i ); | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if ( $favorY ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 0 | $x = int( $n / $i ); | |||||||||||||||||||||||||||
| 230 | 0 | $y = $i; | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | else { | ||||||||||||||||||||||||||||
| 233 | 0 | $y = int( $n / $i ); | |||||||||||||||||||||||||||
| 234 | 0 | $x = $i; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | 0 | return; | |||||||||||||||||||||||||||
| 237 | }} # /alias | ||||||||||||||||||||||||||||
| 238 | 38 | }; #/ $mostEqualDivisors = sub | |||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 0 | ▶ | my $doCountTileable = sub { # void ($p, @) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 241 | 0 | my ( $p ) = @_; | |||||||||||||||||||||||||||
| 242 | 0 | ▶ | assert ( @_ >= 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 243 | 0 | ▶ | assert ( is_Object $p ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 0 | ▶ | $numTileable++ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | if $p->$Tileable(); | ||||||||||||||||||||||||||||
| 246 | 0 | return; | |||||||||||||||||||||||||||
| 247 | 38 | }; | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | my $dividerLoc = sub { # $int ($lo, $hi, $num, $pos) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 250 | 0 | my ( $lo, $hi, $num, $pos ) = @_; | |||||||||||||||||||||||||||
| 251 | 0 | ▶ | assert ( @_ == 4 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | 0 | ▶ | assert ( is_Int $lo ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | 0 | ▶ | assert ( is_Int $hi ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 0 | ▶ | assert ( is_Int $num ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | 0 | ▶ | assert ( is_Int $pos ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 0 | return int( ( $hi - $lo ) * $pos / $num + $lo ); | |||||||||||||||||||||||||||
| 257 | 38 | }; | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | ▶ | my $calcTileRect = sub { # $rect ($pos, $r) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 260 | 0 | my ( $pos, $r ) = @_; | |||||||||||||||||||||||||||
| 261 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 0 | ▶ | assert ( is_Int $pos ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 0 | ▶ | assert ( is_Object $r ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 0 | my ( $x, $y ); | |||||||||||||||||||||||||||
| 265 | 0 | my $nRect = TRect->new(); | |||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 0 | my $d = ( $numCols - $leftOver ) * $numRows; | |||||||||||||||||||||||||||
| 268 | 0 | ▶ | if ( $pos < $d ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 0 | $x = int( $pos / $numRows ); | |||||||||||||||||||||||||||
| 270 | 0 | $y = $pos % $numRows; | |||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | else { | ||||||||||||||||||||||||||||
| 273 | 0 | $x = int( ( $pos - $d ) / ( $numRows + 1 ) ) + ( $numCols - $leftOver ); | |||||||||||||||||||||||||||
| 274 | 0 | $y = ( $pos - $d ) % ( $numRows + 1 ); | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | 0 | $nRect->{a}{x} = &$dividerLoc( $r->{a}{x}, $r->{b}{x}, $numCols, $x ); | |||||||||||||||||||||||||||
| 277 | 0 | $nRect->{b}{x} = &$dividerLoc( $r->{a}{x}, $r->{b}{x}, $numCols, $x + 1 ); | |||||||||||||||||||||||||||
| 278 | 0 | ▶ | if ( $pos >= $d ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | 0 | $nRect->{a}{y} = &$dividerLoc( $r->{a}{y}, $r->{b}{y}, $numRows + 1, $y ); | |||||||||||||||||||||||||||
| 280 | 0 | $nRect->{b}{y} = &$dividerLoc( $r->{a}{y}, $r->{b}{y}, $numRows + 1, $y+1); | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | else { | ||||||||||||||||||||||||||||
| 283 | 0 | $nRect->{a}{y} = &$dividerLoc( $r->{a}{y}, $r->{b}{y}, $numRows, $y ); | |||||||||||||||||||||||||||
| 284 | 0 | $nRect->{b}{y} = &$dividerLoc( $r->{a}{y}, $r->{b}{y}, $numRows, $y + 1 ); | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | 0 | return $nRect; | |||||||||||||||||||||||||||
| 287 | 38 | }; #/ $calcTileRect = sub | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 0 | ▶ | my $doTile = sub { # void ($p, $r) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 290 | 0 | my ( $p, $r ) = @_; | |||||||||||||||||||||||||||
| 291 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 0 | ▶ | assert ( is_Object $p ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | 0 | ▶ | assert ( is_Object $r ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if ( $p->$Tileable() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 0 | my $rect = &$calcTileRect( $tileNum, $r ); | |||||||||||||||||||||||||||
| 296 | 0 | $p->locate( $rect ); | |||||||||||||||||||||||||||
| 297 | 0 | $tileNum--; | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | 0 | return; | |||||||||||||||||||||||||||
| 300 | 38 | }; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 0 | ▶ | sub tile { # void ($r) | ||||||||||||||||||||||||||
|
Subroutine
tile: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 303 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 304 | method => Object, | ||||||||||||||||||||||||||||
| 305 | pos => [Object], | ||||||||||||||||||||||||||||
| 306 | ); | ||||||||||||||||||||||||||||
| 307 | 0 | my ( $self, $r ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 308 | 0 | $numTileable = 0; | |||||||||||||||||||||||||||
| 309 | 0 | $self->forEach( $doCountTileable, undef ); | |||||||||||||||||||||||||||
| 310 | 0 | ▶ | if ( $numTileable > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | &$mostEqualDivisors( $numTileable, $numCols, $numRows, | ||||||||||||||||||||||||||||
| 312 | 0 | !$self->{tileColumnsFirst} ); | |||||||||||||||||||||||||||
| 313 | 0 | ▶ | if ( ( ( $r->{b}{x} - $r->{a}{x} ) / $numCols == 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
($r->{"b"}{"x"} - $r->{"a"}{"x"}) / $numCols == 0 or ($r->{"b"}{"y"} - $r->{"a"}{"y"}) / $numRows == 0
MC/DC0%0/2
($r->{"b"}{"x"} - $r->{"a"}{"x"}) / $numCols == 0 or ($r->{"b"}{"y"} - $r->{"a"}{"y"}) / $numRows == 0
($r->{"b"}{"x"} - $r->{"a"}{"x"}) / $numCols == 0
($r->{"b"}{"y"} - $r->{"a"}{"y"}) / $numRows == 0
Truth table0%0/3
A or B
A= ($r->{"b"}{"x"} - $r->{"a"}{"x"}) / $numCols == 0B= ($r->{"b"}{"y"} - $r->{"a"}{"y"}) / $numRows == 0
| |||||||||||||||||||||||||||||
| 314 | || ( ( $r->{b}{y} - $r->{a}{y} ) / $numRows == 0 ) ) | ||||||||||||||||||||||||||||
| 315 | { | ||||||||||||||||||||||||||||
| 316 | 0 | $self->tileError(); | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | else { | ||||||||||||||||||||||||||||
| 319 | 0 | $leftOver = $numTileable % $numCols; | |||||||||||||||||||||||||||
| 320 | 0 | $tileNum = $numTileable - 1; | |||||||||||||||||||||||||||
| 321 | 0 | $self->lock(); | |||||||||||||||||||||||||||
| 322 | 0 | $self->forEach( $doTile, $r ); | |||||||||||||||||||||||||||
| 323 | 0 | $self->unlock(); | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | } #/ if ( $numTileable > 0 ) | ||||||||||||||||||||||||||||
| 326 | 0 | return; | |||||||||||||||||||||||||||
| 327 | } #/ sub tile | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 0 | ▶ | sub tileError { # void () | ||||||||||||||||||||||||||
|
Subroutine
tileError: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 330 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 331 | method => Object, | ||||||||||||||||||||||||||||
| 332 | pos => [], | ||||||||||||||||||||||||||||
| 333 | ); | ||||||||||||||||||||||||||||
| 334 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 335 | # Handle tile error | ||||||||||||||||||||||||||||
| 336 | 0 | return; | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 0 | ▶ | sub shutDown { # void () | ||||||||||||||||||||||||||
|
Subroutine
shutDown: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 340 | 0 | state $sig = signature( | |||||||||||||||||||||||||||
| 341 | method => Object, | ||||||||||||||||||||||||||||
| 342 | pos => [], | ||||||||||||||||||||||||||||
| 343 | ); | ||||||||||||||||||||||||||||
| 344 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 345 | 0 | $self->{background} = undef; | |||||||||||||||||||||||||||
| 346 | 0 | $self->SUPER::shutDown(); | |||||||||||||||||||||||||||
| 347 | 0 | return; | |||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 38 | 1 | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | __END__ | ||||||||||||||||||||||||||||