| 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 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 4 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 4 | ▶ | use LaTeXML::Global; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 4 | ▶ | use LaTeXML::Common::Object; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 4 | ▶ | use base qw(LaTeXML::Common::Number); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 4 | ▶ | use base qw(Exporter); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 4 | 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
| |||||||||||||
| 33 | 0 | ▶ | $sp = ToString($sp) if ref $sp; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | 0 | ▶ | if ($sp =~ /^(-?\d*\.?\d*)([a-zA-Z][a-zA-Z])$/) { # Dimensions given. | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 0 | $sp = $1 * $STATE->convertUnit($2); } | |||||||||||
| 36 | 0 | ▶ | return bless [$sp || "0"], $class; } | ||||||||||
|
Condition0%0/2
$sp || '0'
MC/DC0%0/1
$sp || '0'
$sp
Truth table0%0/2
A
A= $sp
| |||||||||||||
| 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
| |||||||||||||
| 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 | 4 | 1; | |||||||||||
| 70 | |||||||||||||
| 71 | __END__ | ||||||||||||