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