| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package UnitConverter; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
27
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
336
|
use unit; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
518
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
|
9
|
111
|
|
|
111
|
|
231
|
my ( $class, $scale, $offset, $inverse ) = @_; |
|
10
|
111
|
|
33
|
|
|
264
|
$class = ref($class) || $class; |
|
11
|
111
|
|
|
|
|
164
|
my $this = {}; |
|
12
|
111
|
|
|
|
|
155
|
bless($this, $class); |
|
13
|
111
|
|
|
|
|
222
|
$this->{SCALE} = $scale; |
|
14
|
111
|
|
100
|
|
|
271
|
$this->{OFFSET} = $offset ||= 0.; |
|
15
|
111
|
100
|
100
|
|
|
302
|
$this->{INVERSE} = $inverse |
|
|
|
100
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
? $inverse |
|
17
|
|
|
|
|
|
|
: ($scale == 1.000000000000000000 && $offset == 0.000000000000000000) |
|
18
|
|
|
|
|
|
|
? $this # si on détecte l'identité, elle est son propre inverse |
|
19
|
|
|
|
|
|
|
: UnitConverter->new(1. / $scale, -$offset / $scale, $this); |
|
20
|
111
|
|
|
|
|
274
|
return $this; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub scale { |
|
24
|
144
|
|
|
144
|
|
168
|
my $this = shift; |
|
25
|
144
|
|
|
|
|
301
|
return $this->{SCALE}; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub offset { |
|
29
|
113
|
|
|
113
|
|
135
|
my $this = shift; |
|
30
|
113
|
|
|
|
|
268
|
return $this->{OFFSET}; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub inverse { |
|
34
|
15
|
|
|
15
|
|
22
|
my $this = shift; |
|
35
|
15
|
|
|
|
|
49
|
return $this->{INVERSE}; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub linear { |
|
39
|
0
|
|
|
0
|
|
0
|
my $this = shift; |
|
40
|
|
|
|
|
|
|
# comparaison volontaire avec un double |
|
41
|
0
|
0
|
|
|
|
0
|
if ($this->offset == 0.000000000000000000) { |
|
42
|
0
|
|
|
|
|
0
|
return $this; |
|
43
|
|
|
|
|
|
|
} else { |
|
44
|
0
|
|
|
|
|
0
|
return UnitConverter->new($this->scale); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub linearPow { |
|
49
|
18
|
|
|
18
|
|
29
|
my ( $this, $pow ) = @_; |
|
50
|
|
|
|
|
|
|
# comparaison volontaire avec des doubles |
|
51
|
18
|
100
|
100
|
|
|
28
|
if ($this->offset == 0.00000000000000000 and $pow == 1.00000000000000000) { |
|
52
|
7
|
|
|
|
|
17
|
return $this; |
|
53
|
|
|
|
|
|
|
} else { |
|
54
|
11
|
|
|
|
|
20
|
return UnitConverter->new($this->scale ** $pow); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub convert { |
|
59
|
54
|
|
|
54
|
|
103
|
my ( $this, $value ) = @_; |
|
60
|
54
|
|
|
|
|
119
|
return $value * $this->scale + $this->offset; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub concatenate { |
|
64
|
39
|
|
|
39
|
|
60
|
my ( $this, $converter ) = @_; |
|
65
|
39
|
|
|
|
|
56
|
return UnitConverter->new($converter->scale * $this->scale, $this->convert($converter->offset)); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# static |
|
69
|
|
|
|
|
|
|
sub newLinear { |
|
70
|
12
|
|
|
12
|
|
22
|
my ( $class, $scale ) = @_; |
|
71
|
12
|
|
|
|
|
21
|
return UnitConverter->new($scale, 0.); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# static |
|
75
|
|
|
|
|
|
|
sub newTranslation { |
|
76
|
1
|
|
|
1
|
|
2
|
my ( $class, $offset ) = @_; |
|
77
|
1
|
|
|
|
|
3
|
return UnitConverter->new(1., $offset); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# static |
|
81
|
|
|
|
|
|
|
my $identity = UnitConverter->newLinear(1.0); |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# static |
|
84
|
|
|
|
|
|
|
sub identity { |
|
85
|
32
|
|
|
32
|
|
61
|
return $identity; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 NAME |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
UnitConverter - representation of an unit converter |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This module maps a conceptual class that represents an unit converter. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 AUTHOR |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Samuel Andres |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 LICENSE |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
UnLicense |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |