lib/LaTeXML/Common/Dimension.pm

filter: Statementstmt 48.7% 20 / 41 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 46.1% 6 / 13 Podpod 42.8% 3 / 7 totaltotal 40.2% 29 / 72 CC 6 SCAR 22.9
CC
6
Cov
39%
new
30.0
pointformat
6.0
Dimension
2.0
CRAP 9.9
« lib/LaTeXML/Post/Manifest.pm ↑ Summary lib/LaTeXML/Post/PictureImages.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Common::Dimension | #
3 # | Representation of 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::Dimension;
13 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use LaTeXML::Common::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use base qw(LaTeXML::Common::Number);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 our @EXPORT = (qw(&Dimension));
20  
21 #======================================================================
22 # Exported constructor.
23  
24 sub Dimension {
25 0 ▶ my ($scaledpoints) = @_;
Subroutine Dimension: not called CC=1 SCAR=6.9
Pod documented
26 0 return LaTeXML::Common::Dimension->new($scaledpoints); }
27  
28 #======================================================================
29  
30 sub new {
31 0 ▶ my ($class, $sp) = @_;
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
32 0 ▶ $sp = "0" unless $sp;
Branch: 1 branch
BranchTrueFalseTotal
unless $sp 0 0 0
33 0 ▶ $sp = ToString($sp) if ref $sp;
Branch: 1 branch
BranchTrueFalseTotal
if ref $sp 0 0 0
34 0 ▶ if ($sp =~ /^(-?\d*\.?\d*)([a-zA-Z][a-zA-Z])$/) { # Dimensions given.
Branch: 1 branch
BranchTrueFalseTotal
if ($sp =~ /^(-?\d*\.?\d*)([a-zA-Z][a-zA-Z])$/) 0 0 0
35 0 $sp = $1 * $STATE->convertUnit($2); }
36 0 ▶ return bless [$sp || "0"], $class; }
Condition0%0/2
$sp || '0'
l!l
00
MC/DC0%0/1
$sp || '0'
$sp
Truth table0%0/2
A
A= $sp
Aresult
11
00
37  
38 sub toString {
39 0 ▶ my ($self) = @_;
Subroutine toString: not called CC=1 SCAR=6.9
Pod documented
40 0 return pointformat($$self[0]); }
41  
42 sub toAttribute {
43 0 ▶ my ($self) = @_;
Subroutine toAttribute: not called CC=1 SCAR=6.9
Pod undocumented
44 0 return attributeformat($$self[0]); }
45  
46 sub stringify {
47 0 ▶ my ($self) = @_;
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
48 0 return "Dimension[" . $$self[0] . "]"; }
49  
50 # Utility for formatting scaled points sanely.
51 sub pointformat {
52 0 ▶ my ($sp) = @_;
Subroutine pointformat: not called CC=2 SCAR=17.9
Pod undocumented
53 # As much as I'd like to make this more friendly & readable
54 # there's TeX code that depends on getting enough precision
55 # If you use %.5f, tikz (for example) will sometimes hang trying to do arithmetic!
56 # But see toAttribute for friendlier forms....
57 # [do we need the juggling in attributeFormat to be reproducible?]
58 0 my $s = sprintf("%.6f", ($sp / 65536));
59 0 ▶ $s =~ s/0+$// if $s =~ /\./;
Branch: 1 branch
BranchTrueFalseTotal
if $s =~ /\./ 0 0 0
60 # $s =~ s/\.$//;
61 0 $s =~ s/\.$/.0/; # Seems TeX prints .0 which in odd corner cases, people use?
62 0 return $s . 'pt'; }
63  
64 sub attributeformat {
65 0 ▶ my ($sp) = @_;
Subroutine attributeformat: not called CC=1 SCAR=6.9
Pod undocumented
66 0 return sprintf('%.1fpt', LaTeXML::Common::Number::roundto($sp / 65536, 1)); }
67  
68 #======================================================================
69 5 1;
70  
71 __END__
« lib/LaTeXML/Post/Manifest.pm ↑ Summary lib/LaTeXML/Post/PictureImages.pm »