lib/LaTeXML/Common/Glue.pm

filter: Statementstmt 27.1% 25 / 92 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 33.3% 5 / 15 Podpod 80.0% 8 / 10 totaltotal 18.9% 38 / 201 CC 37 SCAR 53.1
CC
37
Cov
15%
new
462.0
add
42.0
toString
30.0
CRAP 202.0
« lib/LaTeXML/Core/Token.pm ↑ Summary lib/LaTeXML/Core/State.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Common::Glue | #
3 # | Representation of Stretchy dimensions | #
4 # |=====================================================================| #
5 # | Part of LaTeXML: | #
6 # | Public domain software, produced as part of work done by the | #
7 # | United States Government & not subject to copyright in the US. | #
8 # |---------------------------------------------------------------------| #
9 # | Bruce Miller <bruce.miller@nist.gov> #_# | #
10 # | http://dlmf.nist.gov/LaTeXML/ (o o) | #
11 # \=========================================================ooo==U==ooo=/ #
12 package LaTeXML::Common::Glue;
13 5 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use base qw(LaTeXML::Common::Dimension);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 our @EXPORT = (qw(&Glue));
19  
20 #======================================================================
21 # Exported constructor.
22  
23 sub Glue {
24 0 ▶ my ($scaledpoints, $plus, $pfill, $minus, $mfill) = @_;
Subroutine Glue: not called CC=1 SCAR=6.9
Pod documented
25 0 return LaTeXML::Common::Glue->new($scaledpoints, $plus, $pfill, $minus, $mfill); }
26  
27 #======================================================================
28  
29 5 my %fillcode = (fil => 1, fill => 2, filll => 3); # [CONSTANT]
30 5 my @FILL = ('', 'fil', 'fill', 'filll'); # [CONSTANT]
31  
32 5 my $num_re = qr/\d*\.?\d*/; # [CONSTANT]
33 5 my $unit_re = qr/[a-zA-Z][a-zA-Z]/; # [CONSTANT]
34 5 my $fill_re = qr/fil|fill|filll|[a-zA-Z][a-zA-Z]/; # [CONSTANT]
35 5 my $plus_re = qr/\s+plus\s*($num_re)($fill_re)/; # [CONSTANT]
36 5 my $minus_re = qr/\s+minus\s*($num_re)($fill_re)/; # [CONSTANT]
37 5 our $GLUE_re = qr/(\+?\-?$num_re)($unit_re)($plus_re)?($minus_re)?/; # [CONSTANT]
38  
39 sub new {
40 0 ▶ my ($class, $sp, $plus, $pfill, $minus, $mfill) = @_;
Subroutine new: not called CC=21 SCAR=61.4
Pod undocumented
41 0 ▶ $sp = ToString($sp) if ref $sp;
Branch: 1 branch
BranchTrueFalseTotal
if ref $sp 0 0 0
42 0 ▶ $plus = ToString($plus) if ref $plus;
Branch: 1 branch
BranchTrueFalseTotal
if ref $plus 0 0 0
43 0 ▶ $pfill = ToString($pfill) if ref $pfill;
Branch: 1 branch
BranchTrueFalseTotal
if ref $pfill 0 0 0
44 0 ▶ $minus = ToString($minus) if ref $minus;
Branch: 1 branch
BranchTrueFalseTotal
if ref $minus 0 0 0
45 0 ▶ $mfill = ToString($mfill) if ref $mfill;
Branch: 1 branch
BranchTrueFalseTotal
if ref $mfill 0 0 0
46 0 ▶ if ((!defined $plus) && (!defined $pfill) && (!defined $minus) && (!defined $mfill)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $plus or defined $pfill or defined $minus or defined $mfill) 0 0 0
Condition0%0/9
defined $plus or defined $pfill or defined $minus or defined $mfill
l!l&&r!l&&!r
000
defined $plus or defined $pfill or defined $minus
l!l&&r!l&&!r
000
defined $plus or defined $pfill
l!l&&r!l&&!r
000
MC/DC0%0/4
defined $plus or defined $pfill or defined $minus or defined $mfill
defined $plus defined $pfill defined $minus defined $mfill
Truth table0%0/5
A or B or C or D
A= defined $plusB= defined $pfillC= defined $minusD= defined $mfill
ABCDresult
1XXX1
01XX1
001X1
00011
00000
47 0 ▶ if ($sp =~ /^(\d*\.?\d*)$/) { }
Branch: 2 branches
BranchTrueFalseTotal
if ($sp =~ /^(\d*\.?\d*)$/) { } 0 0 0
elsif ($sp =~ /^$LaTeXML::Common::Glue::GLUE_re$/) { } 0 0 0
48 elsif ($sp =~ /^$GLUE_re$/) {
49 0 my ($f, $u, $p, $pu, $m, $mu) = ($1, $2, $4, $5, $7, $8);
50 0 $sp = $f * $STATE->convertUnit($u);
51 0 ▶ if (!$pu) { }
Branch: 2 branches
BranchTrueFalseTotal
if (not $pu) { } 0 0 0
elsif ($fillcode{$pu}) { } 0 0 0
52 0 elsif ($fillcode{$pu}) { $plus = $p; $pfill = $pu; }
53 0 else { $plus = $p * $STATE->convertUnit($pu); $pfill = 0; }
54 0 ▶ if (!$mu) { }
Branch: 2 branches
BranchTrueFalseTotal
if (not $mu) { } 0 0 0
elsif ($fillcode{$mu}) { } 0 0 0
55 0 elsif ($fillcode{$mu}) { $minus = $m; $mfill = $mu; }
56 0 else { $minus = $m * $STATE->convertUnit($mu); $mfill = 0; }
57 } }
58 0 ▶ return bless [$sp || "0", $plus || "0", $pfill || 0, $minus || "0", $mfill || 0], $class; }
Condition0%0/10
$sp || '0'
l!l
00
$plus || '0'
l!l
00
$pfill || 0
l!l
00
$minus || '0'
l!l
00
$mfill || 0
l!l
00
MC/DC0%0/1
$sp || '0'
$sp
MC/DC0%0/1
$plus || '0'
$plus
MC/DC0%0/1
$pfill || 0
$pfill
MC/DC0%0/1
$minus || '0'
$minus
MC/DC0%0/1
$mfill || 0
$mfill
Truth table0%0/2
A
A= $sp
Aresult
11
00
Truth table0%0/2
A
A= $plus
Aresult
11
00
Truth table0%0/2
A
A= $pfill
Aresult
11
00
Truth table0%0/2
A
A= $minus
Aresult
11
00
Truth table0%0/2
A
A= $mfill
Aresult
11
00
59  
60 #sub getStretch { $_[0]->[1]; }
61 #sub getShrink { $_[0]->[2]; }
62  
63 sub toString {
64 0 ▶ my ($self) = @_;
Subroutine toString: not called CC=5 SCAR=34.0
Pod documented
65 0 my ($sp, $plus, $pfill, $minus, $mfill) = @$self;
66 0 my $string = LaTeXML::Common::Dimension::pointformat($sp);
67 0 ▶ $string .= ' plus ' . ($pfill
Branch: 2 branches
BranchTrueFalseTotal
if $plus != 0 0 0 0
$pfill ? : 0 0 0
68 ? $plus . $FILL[$pfill]
69 : LaTeXML::Common::Dimension::pointformat($plus))
70 if $plus != 0;
71 0 ▶ $string .= ' minus ' . ($mfill
Branch: 2 branches
BranchTrueFalseTotal
if $minus != 0 0 0 0
$mfill ? : 0 0 0
72 ? $minus . $FILL[$mfill]
73 : LaTeXML::Common::Dimension::pointformat($minus))
74 if $minus != 0;
75 0 return $string; }
76  
77 sub toAttribute {
78 0 ▶ my ($self) = @_;
Subroutine toAttribute: not called CC=5 SCAR=34.0
Pod undocumented
79 0 my ($sp, $plus, $pfill, $minus, $mfill) = @$self;
80 0 my $string = LaTeXML::Common::Dimension::attributeformat($sp);
81 0 ▶ $string .= ' plus ' . ($pfill
Branch: 2 branches
BranchTrueFalseTotal
if $plus != 0 0 0 0
$pfill ? : 0 0 0
82 ? $plus . $FILL[$pfill]
83 : LaTeXML::Common::Dimension::attributeformat($plus))
84 if $plus != 0;
85 0 ▶ $string .= ' minus ' . ($mfill
Branch: 2 branches
BranchTrueFalseTotal
if $minus != 0 0 0 0
$mfill ? : 0 0 0
86 ? $minus . $FILL[$mfill]
87 : LaTeXML::Common::Dimension::attributeformat($minus))
88 if $minus != 0;
89 0 return $string; }
90  
91 sub negate {
92 0 ▶ my ($self) = @_;
Subroutine negate: not called CC=1 SCAR=6.9
Pod documented
93 0 my ($pts, $p, $pf, $m, $mf) = @$self;
94 0 return (ref $self)->new(-$pts, -$p, $pf, -$m, $mf); }
95  
96 sub add {
97 0 ▶ my ($self, $other) = @_;
Subroutine add: not called CC=6 SCAR=37.4
Pod documented
98 0 my ($pts, $p, $pf, $m, $mf) = @$self;
99 0 ▶ if (ref $other eq 'LaTeXML::Common::Glue') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $other eq 'LaTeXML::Common::Glue') { } 0 0 0
100 0 my ($pts2, $p2, $pf2, $m2, $mf2) = @$other;
101 0 $pts += $pts2;
102 0 ▶ if ($pf == $pf2) { $p += $p2; }
Branch: 2 branches
BranchTrueFalseTotal
if ($pf == $pf2) { } 0 0 0
elsif ($pf < $pf2) { } 0 0 0
103 0 elsif ($pf < $pf2) { $p = $p2; $pf = $pf2; }
104 0 ▶ if ($mf == $mf2) { $m += $m2; }
Branch: 2 branches
BranchTrueFalseTotal
if ($mf == $mf2) { } 0 0 0
elsif ($mf < $mf2) { } 0 0 0
105 0 elsif ($mf < $mf2) { $m = $m2; $mf = $mf2; }
106 0 return (ref $self)->new($pts, $p, $pf, $m, $mf); }
107 else {
108 0 return (ref $self)->new($pts + $other->valueOf, $p, $pf, $m, $mf); } }
109  
110 sub multiply {
111 0 ▶ my ($self, $other) = @_;
Subroutine multiply: not called CC=2 SCAR=17.9
Pod documented
112 0 my ($pts, $p, $pf, $m, $mf) = @$self;
113 0 ▶ $other = $other->valueOf if ref $other;
Branch: 1 branch
BranchTrueFalseTotal
if ref $other 0 0 0
114 0 return (ref $self)->new($pts * $other, $p * $other, $pf, $m * $other, $mf); }
115  
116 sub divide {
117 0 ▶ my ($self, $other) = @_;
Subroutine divide: not called CC=2 SCAR=17.9
Pod documented
118 0 my ($pts, $p, $pf, $m, $mf) = @$self;
119 0 ▶ $other = $other->valueOf if ref $other;
Branch: 1 branch
BranchTrueFalseTotal
if ref $other 0 0 0
120 0 return (ref $self)->new($pts / $other, $p / $other, $pf, $m / $other, $mf); }
121  
122 sub divideround {
123 0 ▶ my ($self, $other) = @_;
Subroutine divideround: not called CC=2 SCAR=17.9
Pod documented
124 0 my ($pts, $p, $pf, $m, $mf) = @$self;
125 0 ▶ $other = $other->valueOf if ref $other;
Branch: 1 branch
BranchTrueFalseTotal
if ref $other 0 0 0
126 0 return (ref $self)->new($pts / $other, $p / $other, $pf, $m / $other, $mf); }
127  
128 sub stringify {
129 0 ▶ my ($self) = @_;
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
130 0 return "Glue[" . join(',', @$self) . "]"; }
131  
132 #======================================================================
133 5 1;
134  
135 __END__
« lib/LaTeXML/Core/Token.pm ↑ Summary lib/LaTeXML/Core/State.pm »