UnitConverter.st
author Claus Gittinger <cg@exept.de>
Fri, 10 Mar 2000 18:47:49 +0100
changeset 886 e2f639b6b0f6
parent 884 1345b2f1cf43
child 981 5bbc2823967e
permissions -rw-r--r--
warning added to doc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
884
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     1
"
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     2
 COPYRIGHT (c) 1996 eXept Software AG
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     3
              All Rights Reserved
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     4
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     5
 This software is furnished under a license and may be used
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     6
 only in accordance with the terms of that license and with the
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     8
 be provided or otherwise made available to, or used by, any
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
     9
 other person.  No title to or ownership of the software is
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    10
 hereby transferred.
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    11
"
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    12
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    13
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    14
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
Object subclass:#UnitConverter
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	instanceVariableNames:''
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    17
	classVariableNames:'Conversions Scaling Aliases Constants'
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	poolDictionaries:''
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	category:'Magnitude-General'
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!UnitConverter class methodsFor:'documentation'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
884
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    24
copyright
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    25
"
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    26
 COPYRIGHT (c) 1996 eXept Software AG
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    27
              All Rights Reserved
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    28
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    29
 This software is furnished under a license and may be used
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    30
 only in accordance with the terms of that license and with the
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    32
 be provided or otherwise made available to, or used by, any
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    33
 other person.  No title to or ownership of the software is
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    34
 hereby transferred.
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    35
"
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    36
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    37
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    38
!
1345b2f1cf43 copyrights
Claus Gittinger <cg@exept.de>
parents: 868
diff changeset
    39
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
documentation
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    In order to collect various unit conversions into one central
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    manageable (and especially: browsable) place, all previously
564
9d5d54a11553 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 556
diff changeset
    44
    spread knowledge about metric (and other) conversions has been
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    brought into this class.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    This class is purely functional, abstract and has no instances;
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    all queries are via class protocol.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    Choosing the Magnitudes category as its home is arbitrary.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    51
    The supported units are setup in the classes initialize method;
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
    52
    supported are:
886
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    53
        meter - inch - feet - foot - yard
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    54
        meter2 - acre - 'german-ar' 'german-hektar' are
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    55
        liter - gallon - barrel - floz
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    56
        celsius - fahrenheit
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
    57
    and many others.
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
    58
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    59
    The converter does a recursive search for a conversion;
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    60
    thus, if there is a conversion from #inch to #millimeter and another 
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    61
    from #millimeter to #kilometer, conversion from #inch to #kilometer
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    62
    is found automatically.
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    63
886
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    64
    No Warranty:
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    65
        The numbers and conversion factors were obtained from the Unix
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    66
        units command. Please check before using it - there might be
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    67
        typos or wrong conversions in the setup code.
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    68
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    69
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    [author:]
886
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    71
        Claus Gittinger
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    see also:
886
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    74
        examples
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
    75
        /usr/share/lib/unittab (if present on your system)
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
examples
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    ever wanted to know, how many floz's are there in a european
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    Coce bottle ?
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    83
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    84
	Transcript showCR:
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    85
	    (UnitConverter convert:1 from:#liter to:#floz)
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    86
								[exEnd]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
    87
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    or, how many square-meters an acre is:
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    89
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    90
	Transcript showCR:
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    91
	    (UnitConverter convert:1 from:#acre to:#'meter^2')
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    92
								[exEnd]
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    94
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    95
    or europeans might want to know, what those
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    96
    fahrenheit numbers mean in an US weather report ;-):
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    97
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    98
	Transcript showCR:(
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    99
	    (UnitConverter convert:80 from:#fahrenheit to:#celsius)
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   100
		asFixedPoint:1)
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   101
								[exEnd]
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   102
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   103
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   104
    how fast do I drive ? :-)
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   105
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   106
	Transcript showCR:(
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   107
		UnitConverter convert:200 from:#'km/hr' to:#'mile/hr')
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   108
								[exEnd]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   109
    how fast does Chris drive ? :-)
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   110
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   111
	Transcript showCR:(
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   112
		UnitConverter convert:65 from:#'mile/hr' to:#'km/hr')
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   113
								[exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   114
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   115
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   116
    calories or joule ?
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   117
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   118
	Transcript showCR:(
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   119
		UnitConverter convert:0.18 from:#'kilocalorie' to:#'kilojoule')
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   120
								[exEnd]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   121
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   122
	Transcript showCR:(
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   123
		UnitConverter convert:2000 from:#'kilocalorie' to:#'kilojoule')
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   124
								[exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   125
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   126
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   127
    distances:
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   128
        
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   129
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   130
	Transcript showCR:(
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   131
	    UnitConverter convert:1 from:#'lightsecond' to:#'kilometer') 
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   132
								[exEnd]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   133
    thats the same:
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   134
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   135
	Transcript showCR:(
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   136
	    UnitConverter convert:1 from:#'lightspeed*s' to:#'kilometer') 
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   137
								[exEnd]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   138
    a days travel ...
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   139
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   140
	Transcript showCR:(
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   141
	    UnitConverter convert:1 from:#'lightspeed*dy' to:#'kilometer') 
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   142
								[exEnd]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   143
    a year travel ...
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   144
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   145
	Transcript showCR:(
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   146
	    UnitConverter convert:1 from:#'lightyear' to:#'kilometer') 
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   147
								[exEnd]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   148
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   149
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    real estate buyers might want to know, how many acres
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
    a german ar is:
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   152
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   153
	Transcript showCR:
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   154
	    (UnitConverter convert:1 from:#'german-ar' to:#acre)
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   155
								[exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   156
    - or how many square-feet are there in your living room:
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   157
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   158
	Transcript showCR:
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   159
	    (UnitConverter convert:100 from:#'meter^2' to:#'foot^2')   
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   160
								[exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   161
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   162
    how many tea spoons are there in a cubic meter ?
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   163
    (roughly, since a teaspoon is not a standard unit)
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   164
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   165
	Transcript showCR:
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   166
	    (UnitConverter convert:1 from:#'meter^3' to:#teaspoon)
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   167
								[exEnd]
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   168
    how wide is a US page in inches:
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   169
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   170
	Transcript showCR:
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   171
	    (UnitConverter convert:1 from:#'letterW' to:#inch)   
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   172
								[exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   173
    - in millimeter:
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   174
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   175
	Transcript showCR:
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   176
	    (UnitConverter convert:1 from:#'letterW' to:#mm)   
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   177
								[exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   178
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   179
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   180
    the height of a US page in inches:
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   181
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   182
	Transcript showCR:
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   183
	    (UnitConverter convert:1 from:#'letterH' to:#inch)   
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   184
								[exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   185
    - in millimeter:
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   186
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   187
	Transcript showCR:
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   188
	    (UnitConverter convert:1 from:#'letterH' to:#mm)   
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   189
								[exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   190
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   191
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   192
    the same for european A4 standard page:
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   193
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   194
	Transcript showCR:
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   195
	    (UnitConverter convert:1 from:#'a4H' to:#mm)   
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   196
								[exEnd]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   197
								[exBegin]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   198
	Transcript showCR:
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   199
	    (UnitConverter convert:1 from:#'a4H' to:#inch)   
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   200
								[exEnd]
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
!UnitConverter class methodsFor:'initialization'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   206
initializeConversions
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
    "initialize common conversions"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    Scaling := IdentityDictionary new.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    Conversions := IdentityDictionary new.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
    Aliases := IdentityDictionary new.
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   212
    Constants := IdentityDictionary new.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   214
    Scaling at:#exa   put:1000000000000000000.
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   215
    Scaling at:#peta  put:1000000000000000.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    Scaling at:#tera  put:1000000000000.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
    Scaling at:#giga  put:1000000000.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
    Scaling at:#mega  put:1000000.
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   219
    Scaling at:#myria put:10000.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
    Scaling at:#kilo  put:1000.
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   221
    Scaling at:#hecto put:100.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
    Scaling at:#deci  put:(1/10).
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    Scaling at:#centi put:(1/100).
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    Scaling at:#milli put:(1/1000).
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    Scaling at:#micro put:(1/1000000).
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
    Scaling at:#nano  put:(1/1000000000).
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
    Scaling at:#pico  put:(1/1000000000000).
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   228
    Scaling at:#femto put:(1/1000000000000000).
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   229
    Scaling at:#atto  put:(1/1000000000000000000).
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   231
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   232
    "/ ---------- velocity -------------
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   233
556
fdf0932239a0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   234
    Constants at:#lightspeed   put:#(2.997925E8   #'m/s').
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   235
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   236
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
    "/ -------------- length -------------
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    Aliases at:#km       put:#kilometer.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
    Aliases at:#m        put:#meter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
    Aliases at:#dm       put:#decimeter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    Aliases at:#cm       put:#centimeter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
    Aliases at:#mm       put:#millimeter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
    Aliases at:#micron   put:#micrometer.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
    Aliases at:#nm       put:#nanometer.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    Aliases at:#angstrom put:#decinanometer.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
    "/ US
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    self addConversion:12       from:#foot to:#inch.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
    self addConversion:3        from:#yard to:#foot.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
    self addConversion:5280     from:#mile to:#foot.
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   252
    self addConversion:0.001    from:#inch to:#mil.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
    Aliases at:#feet put:#foot.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
    Aliases at:#ft   put:#foot.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
    Aliases at:#yd   put:#yard.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
    Aliases at:#mi   put:#mile.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
    "/ inch to millimeter
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
    self addConversion:(25.4/1000) from:#inch to:#meter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   262
    "/ nautic
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   263
    self addConversion:1852        from:#'nautical-mile' to:#meter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   264
556
fdf0932239a0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   265
    Aliases at:#lightsecond put:#'lightspeed*s'.
fdf0932239a0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   266
    Aliases at:#lightyear   put:#'lightspeed*yr'.
fdf0932239a0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   267
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   268
    self addConversion:((Constants at:#lightspeed) at:1) from:#'lightspeed*s' to:#'meter'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   269
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   270
    "/ ---------- time -------------
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   271
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   272
    self addConversion:60           from:#min to:#s.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   273
    self addConversion:60           from:#hr  to:#min.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   274
    self addConversion:24           from:#dy  to:#hr.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   275
    self addConversion:365.24219879 from:#yr  to:#dy.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   276
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   277
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   278
    "/ ---------- printing -------------
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   279
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
    "/ inch to (roughly) a typesetter point
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
    self addConversion:(1/72)      from:#point to:#inch.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
    "/ point to twips; 20 twips (as in Rich-Text-Format) make a point
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
    self addConversion:(1/20)      from:#twip  to:#point.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   286
    "/ US paper
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   287
    self addConversion:11          from:#'letter-page-height' to:#inch.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   288
    self addConversion:8.5         from:#'letter-page-width'  to:#inch.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   289
    self addConversion:8.5         from:#'letter-landscape-page-height'  to:#inch.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   290
    self addConversion:11          from:#'letter-landscape-page-width' to:#inch.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   291
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   292
    self addConversion:14          from:#'legal-page-height' to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   293
    self addConversion:8.5         from:#'legal-page-width'  to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   294
    self addConversion:8.5         from:#'legal-landscape-page-height'  to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   295
    self addConversion:14          from:#'legal-landscape-page-width' to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   296
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   297
    self addConversion:11          from:#'ledger-page-height' to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   298
    self addConversion:17          from:#'ledger-page-width'  to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   299
    self addConversion:17          from:#'ledger-landscape-page-height'  to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   300
    self addConversion:11          from:#'ledger-landscape-page-width' to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   301
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   302
    "/ European paper
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   303
    self addConversion:840         from:#'a1-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   304
    self addConversion:592         from:#'a1-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   305
    self addConversion:592         from:#'a1-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   306
    self addConversion:840         from:#'a1-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   307
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   308
    self addConversion:592         from:#'a2-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   309
    self addConversion:420         from:#'a2-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   310
    self addConversion:420         from:#'a2-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   311
    self addConversion:592         from:#'a2-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   312
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   313
    self addConversion:420         from:#'a3-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   314
    self addConversion:296         from:#'a3-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   315
    self addConversion:296         from:#'a3-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   316
    self addConversion:420         from:#'a3-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   317
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   318
    self addConversion:296         from:#'a4-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   319
    self addConversion:210         from:#'a4-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   320
    self addConversion:210         from:#'a4-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   321
    self addConversion:296         from:#'a4-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   322
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   323
    self addConversion:210         from:#'a5-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   324
    self addConversion:148         from:#'a5-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   325
    self addConversion:148         from:#'a5-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   326
    self addConversion:210         from:#'a5-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   327
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   328
    self addConversion:148         from:#'a6-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   329
    self addConversion:105         from:#'a6-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   330
    self addConversion:105         from:#'a6-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   331
    self addConversion:148         from:#'a6-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   332
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   333
    self addConversion:257         from:#'b5-page-height' to:#millimeter.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   334
    self addConversion:182         from:#'b5-page-width'  to:#millimeter.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   335
    self addConversion:182         from:#'b5-landscape-page-height' to:#millimeter.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   336
    self addConversion:257         from:#'b5-landscape-page-width'  to:#millimeter.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   337
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   338
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   339
    Aliases at:#letterW    put:#'letter-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   340
    Aliases at:#letterH    put:#'letter-page-height'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   341
    Aliases at:#legalW     put:#'legal-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   342
    Aliases at:#legalH     put:#'legal-page-height'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   343
    Aliases at:#ledgerW    put:#'ledger-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   344
    Aliases at:#ledgerH    put:#'ledger-page-height'.
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   345
    Aliases at:#a1W        put:#'a1-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   346
    Aliases at:#a1H        put:#'a1-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   347
    Aliases at:#a2W        put:#'a2-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   348
    Aliases at:#a2H        put:#'a2-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   349
    Aliases at:#a3W        put:#'a3-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   350
    Aliases at:#a3H        put:#'a3-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   351
    Aliases at:#a4W        put:#'a4-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   352
    Aliases at:#a4H        put:#'a4-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   353
    Aliases at:#a5W        put:#'a5-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   354
    Aliases at:#a5H        put:#'a5-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   355
    Aliases at:#a6W        put:#'a6-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   356
    Aliases at:#a6H        put:#'a6-page-height'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   357
    Aliases at:#b5W        put:#'b5-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   358
    Aliases at:#b5H        put:#'b5-page-height'.
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   359
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   360
    Aliases at:#letterlW   put:#'letter-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   361
    Aliases at:#letterlH   put:#'letter-landscape-page-height'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   362
    Aliases at:#legallW    put:#'legal-landscape-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   363
    Aliases at:#legallH    put:#'legal-landscape-page-height'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   364
    Aliases at:#ledgerlW   put:#'ledger-landscape-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   365
    Aliases at:#ledgerlH   put:#'ledger-landscape-page-height'.
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   366
    Aliases at:#a1lW       put:#'a1-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   367
    Aliases at:#a1lH       put:#'a1-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   368
    Aliases at:#a2lW       put:#'a2-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   369
    Aliases at:#a2lH       put:#'a2-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   370
    Aliases at:#a3lW       put:#'a3-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   371
    Aliases at:#a3lH       put:#'a3-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   372
    Aliases at:#a4lW       put:#'a4-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   373
    Aliases at:#a4lH       put:#'a4-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   374
    Aliases at:#a5lW       put:#'a5-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   375
    Aliases at:#a5lH       put:#'a5-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   376
    Aliases at:#a6lW       put:#'a6-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   377
    Aliases at:#a6lH       put:#'a6-landscape-page-height'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   378
    Aliases at:#b5lW       put:#'b5-landscape-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   379
    Aliases at:#b5lH       put:#'b5-landscape-page-height'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   381
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
    "/ ---------------- area -------------------
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
    "/ US
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   385
    self addConversion:4840        from:#acre  to:#'yard^2'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   387
    self addConversion:100         from:#are      to:#'meter^2'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
    self addConversion:100         from:#hectare  to:#are.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
    "/ german area - add your countries, and return to me ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
    Aliases at:#'german-ar'      put:#are.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
    Aliases at:#'german-hektar'  put:#hectare.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   394
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
    "/ ---------------- liquid ---------------- 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   397
    self addConversion:231      from:#gallon to:#'inch^3'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
    self addConversion:(1/4)    from:#quart to:#gallon.  "/ well - at least here,
868
4e5ee397a268 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 601
diff changeset
   399
                                                         "/ thats also 1/4th of a good wine ;-)
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
    self addConversion:(1/2)    from:#pint to:#quart.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
    self addConversion:(1/16)   from:#floz to:#pint.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
    self addConversion:(1/8)    from:#fldr to:#floz.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
    self addConversion:42       from:#barrel to:#gallon.
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   405
    self addConversion:35.23907 from:#bushel to:#liter.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   407
    Aliases at:#cc    put:#'cm^3'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
    Aliases at:#liter put:#kilocc.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
    Aliases at:#ml    put:#milliliter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
    Aliases at:#gal   put:#gallon.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
    Aliases at:#qt    put:#quart.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   413
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
    "/ ---------------- mass ---------------- 
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   415
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
    self addConversion:453.59237 from:#lb to:#gram.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
    self addConversion:205       from:#carat to:#milligram.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   419
    Aliases at:#oz put:#ounce.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
    Aliases at:#gm put:#gram.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
    Aliases at:#kg put:#kilogram.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
    "/ well, a pint of beer is not always:
868
4e5ee397a268 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 601
diff changeset
   425
    self addConversion:277.420 from:#'british-gallon'  to:#'inch^3'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
    self addConversion:(1/4)   from:#'british-quart'   to:#'british-gallon'.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
    self addConversion:(1/2)   from:#'british-pint'    to:#'british-quart'.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
    self addConversion:(1/16)  from:#'british-floz'    to:#'british-pint'.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
    "/ ---------------- energy ---------------- 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
    Aliases at:#cal     put:#calorie.
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   433
    Aliases at:#nt      put:#newton.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   434
    Aliases at:#joule   put:#'nt*m'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   436
    self addConversion:4.1868 from:#calorie  to:#joule.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   437
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
    "/ ---------------- cooking ---------------- 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
    self addConversion:4      from:#tablespoon   to:#fldr.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
    self addConversion:(4/3)  from:#teaspoon     to:#fldr.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   444
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   445
    "/ ---------------- temperature ---------------- 
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   446
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   447
    self addConversion:[:d | d * 1.8 + 32] from:#celsius    to:#fahrenheit.
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   448
    self addConversion:[:f | f - 32 / 1.8] from:#fahrenheit to:#celsius.
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   449
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
     UnitConverter initialize
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
868
4e5ee397a268 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 601
diff changeset
   454
    "Created: / 22.7.1997 / 13:56:40 / cg"
4e5ee397a268 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 601
diff changeset
   455
    "Modified: / 18.1.2000 / 16:19:38 / cg"
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   456
! !
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   457
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   458
!UnitConverter class methodsFor:'accessing'!
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   459
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   460
scalings
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   461
    "return the set of known scaling prefixes"
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   462
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   463
    ^ Scaling keys
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   464
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   465
    "
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   466
     UnitConverter scalings
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   467
    "
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   468
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   469
    "Created: 6.8.1997 / 16:53:19 / cg"
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   470
    "Modified: 6.8.1997 / 16:58:11 / cg"
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   471
!
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   472
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   473
units
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   474
    "return the set of known units"
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   475
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   476
    |setOfUnits|
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   477
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   478
    setOfUnits := IdentitySet new.
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   479
    Conversions keysAndValuesDo:[:srcUnit :conversionInfo |
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   480
	setOfUnits add:srcUnit.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   481
	conversionInfo keysDo:[:targetUnit |
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   482
	    setOfUnits add:targetUnit
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   483
	]
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   484
    ].
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   485
    ^ setOfUnits
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   486
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   487
    "
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   488
     UnitConverter units
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   489
    "
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   490
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   491
    "Created: 6.8.1997 / 16:57:08 / cg"
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   492
    "Modified: 6.8.1997 / 16:57:47 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
!UnitConverter class methodsFor:'conversions'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
convert:howMany from:sourceUnit to:destUnit
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
    "given a value in sourceUnit (symbolic), try to convert it
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
     to destUnit (symbolic); return nil, if the conversion is
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
     unknown."
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   502
    |u conversions alias rslt sU dU const val unit 
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   503
     i suNumerator suDenominator duNumerator duDenominator uN uD
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   504
     sF1 sF2 dF1 dF2
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   505
     s d|
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   507
"/ Transcript showCR:('try ' , sourceUnit , '->' , destUnit).
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   508
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   509
    Conversions isNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   510
	self initializeConversions
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   511
    ].
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   512
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
    "/ somehow, recursion must end ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
    sourceUnit == destUnit ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   515
	^ howMany
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
369
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   518
    sourceUnit isSymbol ifFalse:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   519
	s := sourceUnit withoutSeparators.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   520
	sU := s asSymbolIfInterned.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   521
	sU isNil ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   522
	    (s startsWith:$() ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   523
		(s endsWith:$)) ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   524
		    s := s copyFrom:2 to:(s size - 1).
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   525
		    ^ self convert:howMany from:s to:destUnit
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   526
		]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   527
	    ].
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   528
	    ^ nil
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   529
	].
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   530
	^ self convert:howMany from:sU to:destUnit
369
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   531
    ].
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   532
    destUnit isSymbol ifFalse:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   533
	d := destUnit withoutSeparators.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   534
	dU := d asSymbolIfInterned.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   535
	dU isNil ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   536
	    (d startsWith:$() ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   537
		(d endsWith:$)) ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   538
		    d := d copyFrom:2 to:(d size - 1).
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   539
		    ^ self convert:howMany from:sourceUnit to:d
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   540
		]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   541
	    ].
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   542
	    ^ nil
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   543
	].
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   544
	^ self convert:howMany from:sourceUnit to:dU
369
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   545
    ].
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   546
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
    "/ first, get rid of scalers ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   548
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   549
    u := self unscaled:sourceUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
    u notNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   551
	^ self convert:(howMany*(u value)) from:(u key) to:destUnit
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   554
    u := self unscaled:destUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
    u notNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   556
	^ self convert:(howMany/(u value)) from:sourceUnit to:(u key)
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
    "/ and of aliases ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
    alias := Aliases at:sourceUnit ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   562
    alias notNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   563
	^ self convert:howMany from:alias to:destUnit
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   564
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   565
    alias := Aliases at:destUnit ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   566
    alias notNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   567
	^ self convert:howMany from:sourceUnit to:alias
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   568
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   569
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   570
    "/ any constants ?
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   571
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   572
    (Constants includesKey:sourceUnit) ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   573
	const := Constants at:sourceUnit.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   574
	val := const at:1.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   575
	unit := const at:2.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   576
	^ self convert:(howMany*val) from:unit to:destUnit
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   577
    ].
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   578
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   579
    "/ compounds (^ , / or *) are very naively parsed
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   580
    "/ need a full expression parser (tree) for full power.
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   581
    "/ I leave that as an excercise to you ...
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   582
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   583
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   584
    "/ working with squares or cubics ?
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   585
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   586
    ((sourceUnit endsWith:'^2') and:[destUnit endsWith:'^2']) ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   587
	sU := (sourceUnit copyWithoutLast:2) asSymbolIfInterned.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   588
	dU := (destUnit copyWithoutLast:2) asSymbolIfInterned.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   589
	(sU notNil and:[dU notNil]) ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   590
	    ^ (self convert:(howMany sqrt) from:sU to:dU) squared
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   591
	].
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   592
	^ self noConversionFrom:sourceUnit to:destUnit.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   593
    ].
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   594
    ((sourceUnit endsWith:'^3') and:[destUnit endsWith:'^3']) ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   595
	sU := (sourceUnit copyWithoutLast:2) asSymbolIfInterned.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   596
	dU := (destUnit copyWithoutLast:2) asSymbolIfInterned.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   597
	(sU notNil and:[dU notNil]) ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   598
	    ^ (self convert:(howMany raisedTo:(1/3)) from:sU to:dU) raisedTo:3
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   599
	].
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   600
	^ self noConversionFrom:sourceUnit to:destUnit.
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   601
    ].
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   602
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   603
    "/ working with fractions ?
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   604
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   605
    ((sourceUnit includes:$/) and:[destUnit includes:$/]) ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   606
	"/ look for a constant conversion factor
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   607
	i := sourceUnit indexOf:$/.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   608
	suNumerator := sourceUnit copyTo:(i - 1).
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   609
	suDenominator := sourceUnit copyFrom:(i + 1).
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   610
	i := destUnit indexOf:$/.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   611
	duNumerator := destUnit copyTo:(i - 1).
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   612
	duDenominator := destUnit copyFrom:(i + 1).
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   613
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   614
	uN := self convert:howMany from:suNumerator to:duNumerator.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   615
	uN notNil ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   616
	    uD := self convert:1 from:suDenominator to:duDenominator.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   617
	    uD notNil ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   618
		^ uN / uD
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   619
	    ]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   620
	].
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   621
    ].
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   622
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   623
    "/ working with products ?
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   624
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   625
    ((sourceUnit includes:$*) and:[destUnit includes:$*]) ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   626
	i := sourceUnit indexOf:$*.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   627
	sF1 := sourceUnit copyTo:(i - 1).
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   628
	sF2 := sourceUnit copyFrom:(i + 1).
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   629
	i := destUnit indexOf:$*.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   630
	dF1 := destUnit copyTo:(i - 1).
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   631
	dF2 := destUnit copyFrom:(i + 1).
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   632
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   633
	u := self convert:howMany from:sF1 to:dF1.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   634
	u notNil ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   635
	    u := self convert:u from:sF2 to:dF2.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   636
	    u notNil ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   637
		^ u
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   638
	    ]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   639
	].
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   640
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   641
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   642
    "/ the real work comes here ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   643
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   644
    "/ is there a direct conversion in the dataBase ?
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   645
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   646
    rslt := self convertDirect:howMany from:sourceUnit to:destUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
    rslt notNil ifTrue:[^ rslt].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
    "/ try inverse conversion ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   650
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   651
    rslt := self convertDirect:1 from:destUnit to:sourceUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   652
    rslt notNil ifTrue:[ ^ howMany / rslt].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   653
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   654
    "/ here's the deep recursion ...
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   655
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   656
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   657
    "/ try indirect conversion from source
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   658
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   659
    conversions := Conversions at:sourceUnit ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   660
    conversions notNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   661
	conversions keysAndValuesDo:[:intermediateUnit :factor1 |
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   662
	    |factor2|
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   663
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   664
	    factor2 := self convert:factor1 from:intermediateUnit to:destUnit.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   665
	    factor2 notNil ifTrue:[^ factor2 * howMany].
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   666
	].
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   667
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   668
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   669
    "/ try indirect conversion from dest
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   670
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   671
    conversions := Conversions at:destUnit ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   672
    conversions notNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   673
	conversions keysAndValuesDo:[:intermediateUnit :factor1 |
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   674
	    |factor2|
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   675
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   676
	    factor2 := self convert:(factor1) from:intermediateUnit to:sourceUnit.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   677
	    factor2 notNil ifTrue:[^ howMany / factor2].
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   678
	].
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   679
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   680
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   681
    "/ if working with a product, try each component
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   682
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   683
    (sourceUnit includes:$*) ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   684
	i := sourceUnit indexOf:$*.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   685
	sF1 := sourceUnit copyTo:(i - 1).
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   686
	sF2 := sourceUnit copyFrom:(i + 1).
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   687
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   688
	"/ see what we have ...
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   689
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   690
	self units do:[:aUnit |
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   691
	    |pref iUnit factor2 rslt|
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   692
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   693
	    pref := sF1 , '*'.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   694
	    (aUnit startsWith:pref) ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   695
		"/ ok; want a/b -> x
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   696
		"/ found a/c -> any
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   697
		"/ what about c->b ?
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   698
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   699
		iUnit := aUnit copyFrom:pref size + 1.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   700
		factor2 := self convert:1 from:sF2 to:iUnit.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   701
		factor2 notNil ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   702
		    "/ good ...
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   703
		    rslt := self convert:(factor2 * howMany)
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   704
				    from:aUnit to:destUnit.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   705
		    rslt notNil ifTrue:[^ rslt].
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   706
		]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   707
	    ]
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   708
	].
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   709
    ].
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   710
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   711
    ^ self noConversionFrom:sourceUnit to:destUnit.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   712
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   713
    "direct - how many meters are there in two inches:
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   714
     UnitConverter convert:2 from:#inch to:#meter     
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   715
     UnitConverter convert:37 from:#degrees to:#fahrenheit     
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   716
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   717
     reverse - how many inches are there in one meter
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   718
     UnitConverter convert:1 from:#meter to:#inch   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   719
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   720
     with alias:
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
     UnitConverter convert:1 from:#inch to:#m    
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   722
     UnitConverter convert:1 from:#inch to:#mm          
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   723
     UnitConverter convert:1 from:#inch to:#millimeter   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   724
     UnitConverter convert:1 from:#inch to:#nanometer 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   725
     UnitConverter convert:1 from:#mm to:#km  
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   726
     UnitConverter convert:1 from:#km to:#foot   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   727
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   728
     indirect:
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   729
     UnitConverter convert:1 from:#mm   to:#twip  
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   730
     UnitConverter convert:1 from:#inch to:#twip  
369
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   731
     UnitConverter convert:1 from:'letterH' to:#point  
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   732
     UnitConverter convert:1 from:'letterlH' to:#point  
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   733
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   734
     UnitConverter convert:5 from:#barrel to:#liter  
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   735
     UnitConverter convert:10 from:#kilogram to:#carat  
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   736
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   737
     UnitConverter convert:1 from:#liter to:#floz  
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
    "Created: 31.5.1996 / 16:23:38 / cg"
555
14f0caf53e2f more examples; added conversion rule (product expansion)
Claus Gittinger <cg@exept.de>
parents: 550
diff changeset
   741
    "Modified: 6.8.1997 / 18:10:22 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   743
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   744
inchToMillimeter:inches
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   745
    "convert inches to mm. Made this an extra method, since its so common."
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   746
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   747
    ^ inches * 25.4
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   748
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   749
    "Created: 31.5.1996 / 13:37:31 / cg"
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   750
    "Modified: 31.5.1996 / 18:08:14 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   751
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   752
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   753
millimeterToInch:mm
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   754
    "convert mm to inches. Made this an extra method, since its so common."
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   755
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   756
    ^ mm / 25.4
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   757
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   758
    "Created: 31.5.1996 / 13:37:48 / cg"
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   759
    "Modified: 31.5.1996 / 18:08:20 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   760
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   761
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   762
!UnitConverter class methodsFor:'missing conversion'!
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   763
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   764
noConversionFrom:sourceUnit to:destUnit
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   765
    Transcript showCR:'no conversion ' , sourceUnit printString , ' -> ' , destUnit printString.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   766
    ^ nil
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   767
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   768
    "Created: 29.3.1997 / 17:56:03 / cg"
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   769
! !
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   770
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   771
!UnitConverter class methodsFor:'private'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   772
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   773
addConversion:factor from:sourceMetric to:destMetric
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   774
    "add a conversion"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   775
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   776
    |conversion|
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   777
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   778
    conversion := Conversions at:sourceMetric ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   779
    conversion isNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   780
	conversion := IdentityDictionary new.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   781
	Conversions at:sourceMetric put:conversion
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   782
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   783
    conversion at:destMetric put:factor.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   784
    ^ conversion
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   785
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   786
    "Created: 31.5.1996 / 13:51:25 / cg"
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   787
    "Modified: 29.3.1997 / 17:19:31 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   788
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   789
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   790
convertDirect:howMany from:sourceMetric to:destMetric
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   791
    "given a value in sourceMetric (symbolic), try to convert it
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   792
     to destMetric (symbolic); 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   793
     Only direct conversions are tried; return nil, if the conversion is unknown."
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   794
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   795
    |conversion factor|
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   796
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   797
    Conversions isNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   798
	self initializeConversions
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   799
    ].
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   800
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   801
    conversion := Conversions at:sourceMetric ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   802
    conversion isNil ifTrue:[^ nil].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   803
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   804
    factor := conversion at:destMetric ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   805
    factor isNil ifTrue:[^ nil].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   806
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   807
    factor isNumber ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   808
	^ howMany * factor
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   809
    ].
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   810
    ^ factor value:howMany
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   812
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
     UnitConverter convertDirect:1 from:#inch to:#meter 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   814
     UnitConverter convertDirect:1 from:#inch to:#millimeter 
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   815
     UnitConverter convertDirect:1 from:#degrees to:#fahrenheit 
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   816
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   817
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   818
    "Created: 31.5.1996 / 13:54:33 / cg"
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   819
    "Modified: 22.7.1997 / 13:57:52 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   821
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   822
unscaled:what
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
    "given a unit, return the base and a factor as assoc,
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   824
     or nil if not found"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   825
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   826
    Conversions isNil ifTrue:[
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   827
	self initializeConversions
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   828
    ].
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   829
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   830
    Scaling keysAndValuesDo:[:name :factor |
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   831
	|rest|
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   832
601
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   833
	(what startsWith:name) ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   834
	    rest := what copyFrom:(name size+1).
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   835
	    rest := rest asSymbolIfInterned.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   836
	    rest notNil ifTrue:[
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   837
		^ rest -> factor.
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   838
	    ]        
9f043e153af4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   839
	].
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   840
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   841
    ^ nil
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   842
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   843
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   844
     UnitConverter unscaled:#millimeter
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   845
     UnitConverter unscaled:#nanometer 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   846
     UnitConverter unscaled:#kilometer   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   847
     UnitConverter unscaled:#fuzzymeter   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   848
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   849
550
72ca4b0e5e5c lazy initialization
Claus Gittinger <cg@exept.de>
parents: 516
diff changeset
   850
    "Modified: 22.7.1997 / 13:57:46 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   851
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   852
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   853
!UnitConverter class methodsFor:'documentation'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   854
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   855
version
886
e2f639b6b0f6 warning added to doc
Claus Gittinger <cg@exept.de>
parents: 884
diff changeset
   856
    ^ '$Header: /cvs/stx/stx/libbasic2/UnitConverter.st,v 1.17 2000-03-10 17:47:49 cg Exp $'
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   857
! !