lib/LaTeXML/Common/Glue.pm

filter: Statementstmt 27.8% 34 / 122 Branchbran 0.0% 0 / 74 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 42.1% 8 / 19 Podpod 80.0% 8 / 10 totaltotal 19.7% 50 / 253 CC 46 SCAR 61.0
CC
46
Cov
16%
new
930.0
add
42.0
toString
30.0
CRAP 445.4
« lib/LaTeXML/Core/Mouth.pm ↑ Summary lib/LaTeXML/Core/Gullet.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 LaTeXML::Common::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use LaTeXML::Common::Number;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use LaTeXML::Common::Dimension;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use base qw(LaTeXML::Common::Dimension);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 our @EXPORT = (qw(&Glue));
22  
23 #======================================================================
24 # Exported constructor.
25  
26 # Create a new Glue, given EITHER a string with units, fills,etc,
27 # OR separate args, wiith $spec, $plus, $minus being fixed point,
28 # and $pfill, $mfill being 0 (sp) or a fillcode
29 0 ▶sub Glue {
Subroutine Glue: not called CC=1 SCAR=6.9
Pod documented
30 0 my ($spec, $plus, $pfill, $minus, $mfill) = @_;
31 0 return LaTeXML::Common::Glue->new($spec, $plus, $pfill, $minus, $mfill); }
32  
33 # ======================================================================
34 0 ▶sub _unit { return 'pt'; }
Subroutine _unit: not called CC=1 SCAR=6.9
35  
36 5 my %fillcode = (fil => 1, fill => 2, filll => 3); # [CONSTANT]
37 5 my @FILL = ('', 'fil', 'fill', 'filll'); # [CONSTANT]
38  
39 5 my $num_re = qr/\d*\.?\d*/; # [CONSTANT]
40 5 my $unit_re = qr/[a-zA-Z][a-zA-Z]/; # [CONSTANT]
41 5 my $fill_re = qr/fil|fill|filll|[a-zA-Z][a-zA-Z]/; # [CONSTANT]
42 5 my $plus_re = qr/\s+plus\s*($num_re)($fill_re)/; # [CONSTANT]
43 5 my $minus_re = qr/\s+minus\s*($num_re)($fill_re)/; # [CONSTANT]
44 5 our $GLUE_re = qr/(\+?\-?$num_re)($unit_re)($plus_re)?($minus_re)?/; # [CONSTANT]
45  
46 # Create a new Glue, given $sp, $plus, $minus being fixed point,
47 # and $pfill, $mfill being 0 (sp) or a fillcode
48 # OR, with spec being a string with units, plus, minus, etc.
49 0 ▶sub new {
Subroutine new: not called CC=30 SCAR=68.4
Pod undocumented
50 0 my ($class, $spec, $plus, $pfill, $minus, $mfill) = @_;
51 0 ▶ $spec = ToString($spec) if ref $spec;
Branch: 1 branch
BranchTrueFalseTotal
if ref $spec 0 0 0
52 0 ▶ if ($spec !~ /[a-zA-Z][a-zA-Z]+/) { # If no units, expect fixedpoint values
Branch: 1 branch
BranchTrueFalseTotal
if (not $spec =~ /[a-zA-Z][a-zA-Z]+/) { } 0 0 0
53 0 ▶ $plus = ToString($plus) if ref $plus;
Branch: 1 branch
BranchTrueFalseTotal
if ref $plus 0 0 0
54 0 ▶ $pfill = ToString($pfill) if ref $pfill;
Branch: 1 branch
BranchTrueFalseTotal
if ref $pfill 0 0 0
55 0 ▶ $minus = ToString($minus) if ref $minus;
Branch: 1 branch
BranchTrueFalseTotal
if ref $minus 0 0 0
56 0 ▶ $mfill = ToString($mfill) if ref $mfill;
Branch: 1 branch
BranchTrueFalseTotal
if ref $mfill 0 0 0
57 # See comment in Dimension for why kround rather than int
58 0 ▶ return bless [kround($spec) || "0",
Condition0%0/10
kround($spec) || '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
kround($spec) || '0'
kround($spec)
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= kround($spec)
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 kround($plus || 0), $pfill || 0,
60 kround($minus || 0), $mfill || 0], $class; }
61 else {
62 0 my $mu = $class->_unit eq 'mu';
63 0 ▶ if ((defined $plus) || (defined $pfill) || (defined $minus) || (defined $mfill)) {
Branch: 1 branch
BranchTrueFalseTotal
if (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
64 0 ▶ Warn('unexpected', 'fill', undef,
Branch: 1 branch
BranchTrueFalseTotal
$mu ? : 0 0 0
65 "You should not create " . ($mu ? "MuGlue" : "Glue") . " with both units and stretch"); }
66 0 ▶ if ($spec =~ /^$GLUE_re$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec =~ /^$LaTeXML::Common::Glue::GLUE_re$/) { } 0 0 0
67 0 my ($f, $unit, $p, $punit, $m, $munit) = ($1, $2, $4, $5, $7, $8);
68 0 ▶ if (!$unit) { $f = int($f); }
Branch: 2 branches
BranchTrueFalseTotal
if (not $unit) { } 0 0 0
elsif ($mu) { } 0 0 0
69 0 elsif ($mu) { $f = fixpoint($f); # in mu
70 0 ▶ Warn('unexpected', $unit, undef, "Assumed mu") unless $unit eq 'mu'; }
Branch: 1 branch
BranchTrueFalseTotal
unless $unit eq "mu" 0 0 0
71 0 else { $f = fixpoint($f, $STATE->convertUnit($unit)); }
72 0 ▶ if (!$punit) { $plus = $punit = $pfill = 0; }
Branch: 3 branches
BranchTrueFalseTotal
if (not $punit) { } 0 0 0
elsif ($fillcode{$punit}) { } 0 0 0
elsif ($mu) { } 0 0 0
73 0 elsif ($fillcode{$punit}) { $plus = fixpoint($p); $pfill = $punit; }
74 0 elsif ($mu) { $plus = fixpoint($p); $pfill = 0;
75 0 ▶ Warn('unexpected', $punit, undef, "Assumed mu") unless $punit eq 'mu'; }
Branch: 1 branch
BranchTrueFalseTotal
unless $punit eq "mu" 0 0 0
76 0 else { $plus = fixpoint($p, $STATE->convertUnit($punit)); $pfill = 0; }
77 0 ▶ if (!$munit) { $minus = $munit = $mfill = 0; }
Branch: 3 branches
BranchTrueFalseTotal
if (not $munit) { } 0 0 0
elsif ($fillcode{$munit}) { } 0 0 0
elsif ($mu) { } 0 0 0
78 0 elsif ($fillcode{$munit}) { $minus = fixpoint($m); $mfill = $munit; }
79 0 elsif ($mu) { $minus = fixpoint($m); $mfill = 0;
80 0 ▶ Warn('unexpected', $munit, undef, "Assumed mu") unless $munit eq 'mu'; }
Branch: 1 branch
BranchTrueFalseTotal
unless $munit eq "mu" 0 0 0
81 0 else { $minus = fixpoint($m, $STATE->convertUnit($munit)); $mfill = 0; }
82 0 return bless [$f, $plus, $pfill, $minus, $mfill], $class; }
83 else {
84 0 ▶ Warn('unexpected', $spec, undef,
Branch: 1 branch
BranchTrueFalseTotal
$mu ? : 0 0 0
85 "Missing " . ($mu ? "MuGlue" : "Glue") . " specification assuming 0pt"); }
86 0 return bless [0, 0, 0, 0, 0], $class; } }
87  
88 #sub getStretch { $_[0]->[1]; }
89 #sub getShrink { $_[0]->[2]; }
90  
91 0 ▶sub toString {
Subroutine toString: not called CC=5 SCAR=34.0
Pod documented
92 0 my ($self) = @_;
93 0 my ($sp, $plus, $pfill, $minus, $mfill) = @$self;
94 0 my $u = $self->_unit;
95 0 my $string = fixedformat($sp, $u);
96 0 ▶ $string .= ' plus ' . fixedformat($plus, ($pfill ? $FILL[$pfill] : $u)) if $plus != 0;
Branch: 2 branches
BranchTrueFalseTotal
if $plus != 0 0 0 0
$pfill ? : 0 0 0
97 0 ▶ $string .= ' minus ' . fixedformat($minus, ($mfill ? $FILL[$mfill] : $u)) if $minus != 0;
Branch: 2 branches
BranchTrueFalseTotal
if $minus != 0 0 0 0
$mfill ? : 0 0 0
98 0 return $string; }
99  
100 0 ▶sub toAttribute {
Subroutine toAttribute: not called CC=5 SCAR=34.0
Pod undocumented
101 0 my ($self) = @_;
102 0 my ($sp, $plus, $pfill, $minus, $mfill) = @$self;
103 0 my $u = $self->_unit;
104 0 my $string = LaTeXML::Common::Dimension::attributeformat($sp, $u);
105 0 ▶ $string .= ' plus '
Branch: 2 branches
BranchTrueFalseTotal
if $plus != 0 0 0 0
$pfill ? : 0 0 0
106 . LaTeXML::Common::Dimension::attributeformat($plus, ($pfill ? $FILL[$pfill] : $u))
107 if $plus != 0;
108 0 ▶ $string .= ' minus '
Branch: 2 branches
BranchTrueFalseTotal
if $minus != 0 0 0 0
$mfill ? : 0 0 0
109 . LaTeXML::Common::Dimension::attributeformat($minus, ($mfill ? $FILL[$mfill] : $u))
110  
111 if $minus != 0;
112 0 return $string; }
113  
114 0 ▶sub negate {
Subroutine negate: not called CC=1 SCAR=6.9
Pod documented
115 0 my ($self) = @_;
116 0 my ($pts, $p, $pf, $m, $mf) = @$self;
117 0 return (ref $self)->new(-$pts, -$p, $pf, -$m, $mf); }
118  
119 0 ▶sub add {
Subroutine add: not called CC=6 SCAR=37.4
Pod documented
120 0 my ($self, $other) = @_;
121 0 my ($pts, $p, $pf, $m, $mf) = @$self;
122 0 ▶ if (ref $other eq 'LaTeXML::Common::Glue') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $other eq 'LaTeXML::Common::Glue') { } 0 0 0
123 0 my ($pts2, $p2, $pf2, $m2, $mf2) = @$other;
124 0 $pts += $pts2;
125 0 ▶ if ($pf == $pf2) { $p += $p2; }
Branch: 2 branches
BranchTrueFalseTotal
if ($pf == $pf2) { } 0 0 0
elsif ($pf < $pf2) { } 0 0 0
126 0 elsif ($pf < $pf2) { $p = $p2; $pf = $pf2; }
127 0 ▶ if ($mf == $mf2) { $m += $m2; }
Branch: 2 branches
BranchTrueFalseTotal
if ($mf == $mf2) { } 0 0 0
elsif ($mf < $mf2) { } 0 0 0
128 0 elsif ($mf < $mf2) { $m = $m2; $mf = $mf2; }
129 0 return (ref $self)->new($pts, $p, $pf, $m, $mf); }
130 else {
131 0 return (ref $self)->new($pts + $other->valueOf, $p, $pf, $m, $mf); } }
132  
133 0 ▶sub multiply {
Subroutine multiply: not called CC=2 SCAR=17.9
Pod documented
134 0 my ($self, $other) = @_;
135 0 my ($pts, $p, $pf, $m, $mf) = @$self;
136 0 ▶ $other = $other->valueOf if ref $other;
Branch: 1 branch
BranchTrueFalseTotal
if ref $other 0 0 0
137 0 return (ref $self)->new($pts * $other, $p * $other, $pf, $m * $other, $mf); }
138  
139 0 ▶sub divide {
Subroutine divide: not called CC=2 SCAR=17.9
Pod documented
140 0 my ($self, $other) = @_;
141 0 my ($pts, $p, $pf, $m, $mf) = @$self;
142 0 ▶ $other = $other->valueOf if ref $other;
Branch: 1 branch
BranchTrueFalseTotal
if ref $other 0 0 0
143 0 return (ref $self)->new($pts / $other, $p / $other, $pf, $m / $other, $mf); }
144  
145 0 ▶sub divideround {
Subroutine divideround: not called CC=2 SCAR=17.9
Pod documented
146 0 my ($self, $other) = @_;
147 0 my ($pts, $p, $pf, $m, $mf) = @$self;
148 0 ▶ $other = $other->valueOf if ref $other;
Branch: 1 branch
BranchTrueFalseTotal
if ref $other 0 0 0
149 0 return (ref $self)->new($pts / $other, $p / $other, $pf, $m / $other, $mf); }
150  
151 0 ▶sub stringify {
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
152 0 my ($self) = @_;
153 0 return "Glue[" . join(',', @$self) . "]"; }
154  
155 #======================================================================
156 5 1;
157  
158 __END__
« lib/LaTeXML/Core/Mouth.pm ↑ Summary lib/LaTeXML/Core/Gullet.pm »