UnitConverter.st
author Claus Gittinger <cg@exept.de>
Sat, 29 Mar 1997 19:13:14 +0100
changeset 516 973e10f68449
parent 515 d7fedc8d697a
child 550 72ca4b0e5e5c
permissions -rw-r--r--
calorie factor was wrong
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]
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    or, how many square-meters an acre is:
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
                                                                [exBegin]
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
        Transcript showCR:
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    54
            (UnitConverter convert:1 from:#acre to:#'meter^2')
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
                                                                [exEnd]
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    57
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    58
    or europeans might want to know, what those
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    59
    fahrenheit numbers mean in an US weather report ;-):
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    60
                                                                [exBegin]
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    61
        Transcript showCR:(
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    62
            (UnitConverter convert:80 from:#fahrenheit to:#celsius)
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    63
                asFixedPoint:1)
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    64
                                                                [exEnd]
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
    65
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    66
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    67
    how fast do I drive ?
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    68
                                                                [exBegin]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    69
        Transcript showCR:(
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    70
                UnitConverter convert:200 from:#'km/hr' to:#'mile/hr')
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    71
                                                                [exEnd]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    72
                                                                [exBegin]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    73
        Transcript showCR:(
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    74
                UnitConverter convert:65 from:#'mile/hr' to:#'km/hr')
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    75
                                                                [exEnd]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    76
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    77
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    78
    calories or joule ?
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    79
                                                                [exBegin]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    80
        Transcript showCR:(
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    81
                UnitConverter convert:0.18 from:#'kilocalorie' to:#'kilojoule')
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    82
                                                                [exEnd]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    83
                                                                [exBegin]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    84
        Transcript showCR:(
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    85
                UnitConverter convert:2000 from:#'kilocalorie' to:#'kilojoule')
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    86
                                                                [exEnd]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    87
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    88
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    real estate buyers might want to know, how many acres
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    a german ar is:
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
                                                                [exBegin]
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
        Transcript showCR:
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
            (UnitConverter convert:1 from:#'german-ar' to:#acre)
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    95
    - 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
    96
                                                                [exBegin]
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
    97
        Transcript showCR:
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
    98
            (UnitConverter convert:100 from:#'meter^2' to:#'foot^2')   
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
    99
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   100
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   101
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   102
    how wide is a US page in inches:
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   103
                                                                [exBegin]
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   104
        Transcript showCR:
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   105
            (UnitConverter convert:1 from:#'letterW' to:#inch)   
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   106
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   107
    - in millimeter:
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   108
                                                                [exBegin]
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   109
        Transcript showCR:
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   110
            (UnitConverter convert:1 from:#'letterW' to:#mm)   
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   111
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   112
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   113
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   114
    the height of a US page in inches:
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   115
                                                                [exBegin]
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   116
        Transcript showCR:
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   117
            (UnitConverter convert:1 from:#'letterH' to:#inch)   
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   118
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   119
    - in millimeter:
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   120
                                                                [exBegin]
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   121
        Transcript showCR:
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   122
            (UnitConverter convert:1 from:#'letterH' to:#mm)   
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   123
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   124
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   125
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   126
    the same for european A4 standard page:
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   127
                                                                [exBegin]
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   128
        Transcript showCR:
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   129
            (UnitConverter convert:1 from:#'a4H' to:#mm)   
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   130
                                                                [exEnd]
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   131
                                                                [exBegin]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   132
        Transcript showCR:
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   133
            (UnitConverter convert:1 from:#'a4H' to:#inch)   
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   134
                                                                [exEnd]
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
!UnitConverter class methodsFor:'initialization'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
initialize
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    "initialize common conversions"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    Scaling := IdentityDictionary new.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    Conversions := IdentityDictionary new.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    Aliases := IdentityDictionary new.
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   146
    Constants := IdentityDictionary new.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   148
    Scaling at:#exa   put:1000000000000000000.
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   149
    Scaling at:#peta  put:1000000000000000.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    Scaling at:#tera  put:1000000000000.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
    Scaling at:#giga  put:1000000000.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
    Scaling at:#mega  put:1000000.
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   153
    Scaling at:#myria put:10000.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
    Scaling at:#kilo  put:1000.
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   155
    Scaling at:#hecto put:100.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
    Scaling at:#deci  put:(1/10).
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    Scaling at:#centi put:(1/100).
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
    Scaling at:#milli put:(1/1000).
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
    Scaling at:#micro put:(1/1000000).
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
    Scaling at:#nano  put:(1/1000000000).
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
    Scaling at:#pico  put:(1/1000000000000).
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   162
    Scaling at:#femto put:(1/1000000000000000).
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   163
    Scaling at:#atto  put:(1/1000000000000000000).
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   165
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
    "/ -------------- length -------------
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
    Aliases at:#km       put:#kilometer.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
    Aliases at:#m        put:#meter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
    Aliases at:#dm       put:#decimeter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
    Aliases at:#cm       put:#centimeter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
    Aliases at:#mm       put:#millimeter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
    Aliases at:#micron   put:#micrometer.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
    Aliases at:#nm       put:#nanometer.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
    Aliases at:#angstrom put:#decinanometer.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
    "/ US
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
    self addConversion:12       from:#foot to:#inch.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
    self addConversion:3        from:#yard to:#foot.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
    self addConversion:5280     from:#mile to:#foot.
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   181
    self addConversion:0.001    from:#inch to:#mil.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
    Aliases at:#feet put:#foot.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
    Aliases at:#ft   put:#foot.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
    Aliases at:#yd   put:#yard.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
    Aliases at:#mi   put:#mile.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
    "/ inch to millimeter
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
    self addConversion:(25.4/1000) from:#inch to:#meter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   191
    "/ nautic
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   192
    self addConversion:1852        from:#'nautical-mile' to:#meter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   193
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   194
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   195
    "/ ---------- time -------------
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   196
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   197
    self addConversion:60           from:#min to:#s.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   198
    self addConversion:60           from:#hr  to:#min.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   199
    self addConversion:24           from:#dy  to:#hr.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   200
    self addConversion:365.24219879 from:#yr  to:#dy.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   201
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   202
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   203
    "/ ---------- velocity -------------
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   204
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   205
    Constants at:#lightSpeed   put:#(2.997925E8   #'m/s').
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   206
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   207
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   208
    "/ ---------- printing -------------
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   209
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    "/ inch to (roughly) a typesetter point
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
    self addConversion:(1/72)      from:#point to:#inch.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
    "/ point to twips; 20 twips (as in Rich-Text-Format) make a point
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
    self addConversion:(1/20)      from:#twip  to:#point.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   216
    "/ US paper
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   217
    self addConversion:11          from:#'letter-page-height' to:#inch.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   218
    self addConversion:8.5         from:#'letter-page-width'  to:#inch.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   219
    self addConversion:8.5         from:#'letter-landscape-page-height'  to:#inch.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   220
    self addConversion:11          from:#'letter-landscape-page-width' to:#inch.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   221
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   222
    self addConversion:14          from:#'legal-page-height' to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   223
    self addConversion:8.5         from:#'legal-page-width'  to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   224
    self addConversion:8.5         from:#'legal-landscape-page-height'  to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   225
    self addConversion:14          from:#'legal-landscape-page-width' to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   226
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   227
    self addConversion:11          from:#'ledger-page-height' to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   228
    self addConversion:17          from:#'ledger-page-width'  to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   229
    self addConversion:17          from:#'ledger-landscape-page-height'  to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   230
    self addConversion:11          from:#'ledger-landscape-page-width' to:#inch.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   231
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   232
    "/ European paper
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   233
    self addConversion:840         from:#'a1-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   234
    self addConversion:592         from:#'a1-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   235
    self addConversion:592         from:#'a1-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   236
    self addConversion:840         from:#'a1-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   237
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   238
    self addConversion:592         from:#'a2-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   239
    self addConversion:420         from:#'a2-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   240
    self addConversion:420         from:#'a2-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   241
    self addConversion:592         from:#'a2-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   242
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   243
    self addConversion:420         from:#'a3-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   244
    self addConversion:296         from:#'a3-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   245
    self addConversion:296         from:#'a3-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   246
    self addConversion:420         from:#'a3-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   247
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   248
    self addConversion:296         from:#'a4-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   249
    self addConversion:210         from:#'a4-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   250
    self addConversion:210         from:#'a4-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   251
    self addConversion:296         from:#'a4-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   252
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   253
    self addConversion:210         from:#'a5-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   254
    self addConversion:148         from:#'a5-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   255
    self addConversion:148         from:#'a5-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   256
    self addConversion:210         from:#'a5-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   257
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   258
    self addConversion:148         from:#'a6-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   259
    self addConversion:105         from:#'a6-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   260
    self addConversion:105         from:#'a6-landscape-page-height' to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   261
    self addConversion:148         from:#'a6-landscape-page-width'  to:#millimeter.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   262
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   263
    self addConversion:257         from:#'b5-page-height' to:#millimeter.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   264
    self addConversion:182         from:#'b5-page-width'  to:#millimeter.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   265
    self addConversion:182         from:#'b5-landscape-page-height' to:#millimeter.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   266
    self addConversion:257         from:#'b5-landscape-page-width'  to:#millimeter.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   267
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   268
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   269
    Aliases at:#letterW    put:#'letter-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   270
    Aliases at:#letterH    put:#'letter-page-height'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   271
    Aliases at:#legalW     put:#'legal-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   272
    Aliases at:#legalH     put:#'legal-page-height'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   273
    Aliases at:#ledgerW    put:#'ledger-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   274
    Aliases at:#ledgerH    put:#'ledger-page-height'.
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   275
    Aliases at:#a1W        put:#'a1-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   276
    Aliases at:#a1H        put:#'a1-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   277
    Aliases at:#a2W        put:#'a2-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   278
    Aliases at:#a2H        put:#'a2-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   279
    Aliases at:#a3W        put:#'a3-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   280
    Aliases at:#a3H        put:#'a3-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   281
    Aliases at:#a4W        put:#'a4-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   282
    Aliases at:#a4H        put:#'a4-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   283
    Aliases at:#a5W        put:#'a5-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   284
    Aliases at:#a5H        put:#'a5-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   285
    Aliases at:#a6W        put:#'a6-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   286
    Aliases at:#a6H        put:#'a6-page-height'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   287
    Aliases at:#b5W        put:#'b5-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   288
    Aliases at:#b5H        put:#'b5-page-height'.
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   289
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   290
    Aliases at:#letterlW   put:#'letter-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   291
    Aliases at:#letterlH   put:#'letter-landscape-page-height'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   292
    Aliases at:#legallW    put:#'legal-landscape-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   293
    Aliases at:#legallH    put:#'legal-landscape-page-height'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   294
    Aliases at:#ledgerlW   put:#'ledger-landscape-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   295
    Aliases at:#ledgerlH   put:#'ledger-landscape-page-height'.
365
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   296
    Aliases at:#a1lW       put:#'a1-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   297
    Aliases at:#a1lH       put:#'a1-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   298
    Aliases at:#a2lW       put:#'a2-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   299
    Aliases at:#a2lH       put:#'a2-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   300
    Aliases at:#a3lW       put:#'a3-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   301
    Aliases at:#a3lH       put:#'a3-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   302
    Aliases at:#a4lW       put:#'a4-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   303
    Aliases at:#a4lH       put:#'a4-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   304
    Aliases at:#a5lW       put:#'a5-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   305
    Aliases at:#a5lH       put:#'a5-landscape-page-height'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   306
    Aliases at:#a6lW       put:#'a6-landscape-page-width'.
12af10e01409 added page conversions
Claus Gittinger <cg@exept.de>
parents: 364
diff changeset
   307
    Aliases at:#a6lH       put:#'a6-landscape-page-height'.
385
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   308
    Aliases at:#b5lW       put:#'b5-landscape-page-width'.
67ac6014097c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 369
diff changeset
   309
    Aliases at:#b5lH       put:#'b5-landscape-page-height'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   311
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
    "/ ---------------- area -------------------
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
    "/ US
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   315
    self addConversion:4840        from:#acre  to:#'yard^2'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   317
    self addConversion:100         from:#are      to:#'meter^2'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
    self addConversion:100         from:#hectare  to:#are.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
    "/ german area - add your countries, and return to me ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
    Aliases at:#'german-ar'      put:#are.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
    Aliases at:#'german-hektar'  put:#hectare.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   324
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
    "/ ---------------- liquid ---------------- 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   327
    self addConversion:231      from:#gallon to:#'inch^3'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
    self addConversion:(1/4)    from:#quart to:#gallon.  "/ well - at least here,
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
                                                         "/ thats also 1/4th of a good wine ;-)
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
    self addConversion:(1/2)    from:#pint to:#quart.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
    self addConversion:(1/16)   from:#floz to:#pint.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
    self addConversion:(1/8)    from:#fldr to:#floz.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
    self addConversion:42       from:#barrel to:#gallon.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   336
    Aliases at:#cc    put:#'cm^3'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
    Aliases at:#liter put:#kilocc.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
    Aliases at:#ml    put:#milliliter.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
    Aliases at:#gal   put:#gallon.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
    Aliases at:#qt    put:#quart.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   342
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
    "/ ---------------- mass ---------------- 
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   344
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
    self addConversion:453.59237 from:#lb to:#gram.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
    self addConversion:205       from:#carat to:#milligram.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
    Aliases at:#oz put:#ounce.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
    Aliases at:#gm put:#gram.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
    Aliases at:#kg put:#kilogram.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
    "/ well, a pint of beer is not always:
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   354
    self addConversion:277.420 from:#'british-gallon'  to:#'in^3'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
    self addConversion:(1/4)   from:#'british-quart'   to:#'british-gallon'.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
    self addConversion:(1/2)   from:#'british-pint'    to:#'british-quart'.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
    self addConversion:(1/16)  from:#'british-floz'    to:#'british-pint'.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   359
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
    "/ ---------------- energy ---------------- 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
    Aliases at:#cal     put:#calorie.
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   363
    Aliases at:#nt      put:#newton.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   364
    Aliases at:#joule   put:#'nt*m'.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   366
    self addConversion:4.1868 from:#calorie  to:#joule.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   367
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
    "/ ---------------- cooking ---------------- 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
    self addConversion:4      from:#tablespoon   to:#fldr.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
    self addConversion:(4/3)  from:#teaspoon     to:#fldr.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   374
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   375
    "/ ---------------- temperature ---------------- 
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   376
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   377
    self addConversion:[:d | d * 1.8 + 32] from:#celsius    to:#fahrenheit.
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   378
    self addConversion:[:f | f - 32 / 1.8] from:#fahrenheit to:#celsius.
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   379
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
     UnitConverter initialize
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   384
    "Modified: 29.3.1997 / 19:11:52 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
!UnitConverter class methodsFor:'conversions'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
convert:howMany from:sourceUnit to:destUnit
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
    "given a value in sourceUnit (symbolic), try to convert it
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
     to destUnit (symbolic); return nil, if the conversion is
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
     unknown."
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   394
    |u conversions alias rslt sU dU const val unit 
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   395
     i suNumerator suDenominator duNumerator duDenominator uN uD
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   396
     sF1 sF2 dF1 dF2
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   397
     s d|
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
    "/ somehow, recursion must end ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
    sourceUnit == destUnit ifTrue:[
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
        ^ howMany
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
369
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   404
    sourceUnit isSymbol ifFalse:[
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   405
        s := sourceUnit withoutSeparators.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   406
        sU := s asSymbolIfInterned.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   407
        sU isNil ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   408
            (s startsWith:$() ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   409
                (s endsWith:$)) ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   410
                    s := s copyFrom:2 to:(s size - 1).
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   411
                    ^ self convert:howMany from:s to:destUnit
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   412
                ]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   413
            ].
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   414
            ^ nil
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   415
        ].
369
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   416
        ^ self convert:howMany from:sU to:destUnit
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   417
    ].
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   418
    destUnit isSymbol ifFalse:[
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   419
        d := destUnit withoutSeparators.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   420
        dU := d asSymbolIfInterned.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   421
        dU isNil ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   422
            (d startsWith:$() ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   423
                (d endsWith:$)) ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   424
                    d := d copyFrom:2 to:(d size - 1).
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   425
                    ^ self convert:howMany from:sourceUnit to:d
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   426
                ]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   427
            ].
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   428
            ^ nil
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   429
        ].
369
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   430
        ^ self convert:howMany from:sourceUnit to:dU
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   431
    ].
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   432
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
    "/ first, get rid of scalers ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
    u := self unscaled:sourceUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
    u notNil ifTrue:[
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
        ^ self convert:(howMany*(u value)) from:(u key) to:destUnit
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
    u := self unscaled:destUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
    u notNil ifTrue:[
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
        ^ self convert:(howMany/(u value)) from:sourceUnit to:(u key)
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
    "/ and of aliases ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
    alias := Aliases at:sourceUnit ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
    alias notNil ifTrue:[
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
        ^ self convert:howMany from:alias to:destUnit
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
    alias := Aliases at:destUnit ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
    alias notNil ifTrue:[
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
        ^ self convert:howMany from:sourceUnit to:alias
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   456
    "/ any constants ?
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   457
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   458
    (Constants includesKey:sourceUnit) ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   459
        const := Constants at:sourceUnit.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   460
        val := const at:1.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   461
        unit := const at:2.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   462
        ^ self convert:(howMany*val) from:unit to:destUnit
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   463
    ].
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   464
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
    "/ working with squares or cubics ?
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   467
    ((sourceUnit endsWith:'^2') and:[destUnit endsWith:'^2']) ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   468
        sU := (sourceUnit copyWithoutLast:2) asSymbolIfInterned.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   469
        dU := (destUnit copyWithoutLast:2) asSymbolIfInterned.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
        (sU notNil and:[dU notNil]) ifTrue:[
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
            ^ (self convert:(howMany sqrt) from:sU to:dU) squared
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
        ].
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   473
        ^ self noConversionFrom:sourceUnit to:destUnit.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
    ].
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   475
    ((sourceUnit endsWith:'^3') and:[destUnit endsWith:'^3']) ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   476
        sU := (sourceUnit copyWithoutLast:2) asSymbolIfInterned.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   477
        dU := (destUnit copyWithoutLast:2) asSymbolIfInterned.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
        (sU notNil and:[dU notNil]) ifTrue:[
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
            ^ (self convert:(howMany raisedTo:(1/3)) from:sU to:dU) raisedTo:3
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
        ].
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   481
        ^ self noConversionFrom:sourceUnit to:destUnit.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   482
    ].
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   483
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   484
    "/ working with fractions ?
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   485
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   486
    ((sourceUnit includes:$/) and:[destUnit includes:$/]) ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   487
        "/ look for a constant conversion factor
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   488
        i := sourceUnit indexOf:$/.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   489
        suNumerator := sourceUnit copyTo:(i - 1).
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   490
        suDenominator := sourceUnit copyFrom:(i + 1).
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   491
        i := destUnit indexOf:$/.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   492
        duNumerator := destUnit copyTo:(i - 1).
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   493
        duDenominator := destUnit copyFrom:(i + 1).
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   494
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   495
        uN := self convert:howMany from:suNumerator to:duNumerator.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   496
        uN notNil ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   497
            uD := self convert:1 from:suDenominator to:duDenominator.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   498
            uD notNil ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   499
                ^ uN / uD
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   500
            ]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   501
        ].
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   502
    ].
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   503
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   504
    "/ working with products ?
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
    ((sourceUnit includes:$*) and:[destUnit includes:$*]) ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   507
        i := sourceUnit indexOf:$*.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   508
        sF1 := sourceUnit copyTo:(i - 1).
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   509
        sF2 := sourceUnit copyFrom:(i + 1).
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   510
        i := destUnit indexOf:$*.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   511
        dF1 := destUnit copyTo:(i - 1).
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   512
        dF2 := destUnit copyFrom:(i + 1).
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   513
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   514
        u := self convert:howMany from:sF1 to:dF1.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   515
        u notNil ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   516
            u := self convert:u from:sF2 to:dF2.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   517
            u notNil ifTrue:[
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   518
                ^ u
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   519
            ]
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   520
        ].
363
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
    "/ the real work comes here ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
    "/ is there a direct conversion in the dataBase ?
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
    rslt := self convertDirect:howMany from:sourceUnit to:destUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
    rslt notNil ifTrue:[^ rslt].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
    "/ try inverse conversion ...
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
    rslt := self convertDirect:1 from:destUnit to:sourceUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
    rslt notNil ifTrue:[ ^ howMany / rslt].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   535
    "/ here's the deep recursion ...
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
    "/ try indirect conversion from source
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   540
    conversions := Conversions at:sourceUnit ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   541
    conversions notNil ifTrue:[
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
        conversions keysAndValuesDo:[:intermediateUnit :factor1 |
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   543
            |factor2|
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   544
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
            factor2 := self convert:factor1 from:intermediateUnit to:destUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   546
            factor2 notNil ifTrue:[^ factor2 * howMany].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
        ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   548
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   549
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
    "/ try indirect conversion from dest
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   551
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
    conversions := Conversions at:destUnit ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
    conversions notNil ifTrue:[
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   554
        conversions keysAndValuesDo:[:intermediateUnit :factor1 |
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
            |factor2|
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
            factor2 := self convert:(factor1) from:intermediateUnit to:sourceUnit.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
            factor2 notNil ifTrue:[^ howMany / factor2].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
        ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   562
    ^ self noConversionFrom:sourceUnit to:destUnit.
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   563
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   564
    "direct - how many meters are there in two inches:
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   565
     UnitConverter convert:2 from:#inch to:#meter     
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   566
     UnitConverter convert:37 from:#degrees to:#fahrenheit     
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   567
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   568
     reverse - how many inches are there in one meter
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   569
     UnitConverter convert:1 from:#meter to:#inch   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   570
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   571
     with alias:
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   572
     UnitConverter convert:1 from:#inch to:#m    
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   573
     UnitConverter convert:1 from:#inch to:#mm          
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   574
     UnitConverter convert:1 from:#inch to:#millimeter   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   575
     UnitConverter convert:1 from:#inch to:#nanometer 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   576
     UnitConverter convert:1 from:#mm to:#km  
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   577
     UnitConverter convert:1 from:#km to:#foot   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   578
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   579
     indirect:
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   580
     UnitConverter convert:1 from:#mm   to:#twip  
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   581
     UnitConverter convert:1 from:#inch to:#twip  
369
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   582
     UnitConverter convert:1 from:'letterH' to:#point  
eba5bf03291a handle nonSymbols
Claus Gittinger <cg@exept.de>
parents: 365
diff changeset
   583
     UnitConverter convert:1 from:'letterlH' to:#point  
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   584
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   585
     UnitConverter convert:5 from:#barrel to:#liter  
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   586
     UnitConverter convert:10 from:#kilogram to:#carat  
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   587
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   588
     UnitConverter convert:1 from:#liter to:#floz  
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   589
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   590
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   591
    "Created: 31.5.1996 / 16:23:38 / cg"
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   592
    "Modified: 29.3.1997 / 19:04:40 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   593
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   594
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   595
inchToMillimeter:inches
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   596
    "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
   597
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   598
    ^ inches * 25.4
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   599
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   600
    "Created: 31.5.1996 / 13:37:31 / cg"
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   601
    "Modified: 31.5.1996 / 18:08:14 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   602
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   603
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   604
millimeterToInch:mm
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   605
    "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
   606
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   607
    ^ mm / 25.4
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   608
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   609
    "Created: 31.5.1996 / 13:37:48 / cg"
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   610
    "Modified: 31.5.1996 / 18:08:20 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   612
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   613
!UnitConverter class methodsFor:'missing conversion'!
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   614
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   615
noConversionFrom:sourceUnit to:destUnit
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   616
    Transcript showCR:'no conversion ' , sourceUnit printString , ' -> ' , destUnit printString.
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   617
    ^ nil
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   618
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   619
    "Created: 29.3.1997 / 17:56:03 / cg"
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   620
! !
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   621
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   622
!UnitConverter class methodsFor:'private'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   623
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   624
addConversion:factor from:sourceMetric to:destMetric
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   625
    "add a conversion"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   626
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   627
    |conversion|
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   628
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   629
    conversion := Conversions at:sourceMetric ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   630
    conversion isNil ifTrue:[
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   631
        conversion := IdentityDictionary new.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   632
        Conversions at:sourceMetric put:conversion
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   633
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   634
    conversion at:destMetric put:factor.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   635
    ^ conversion
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   636
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   637
    "Created: 31.5.1996 / 13:51:25 / cg"
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   638
    "Modified: 29.3.1997 / 17:19:31 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   639
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   640
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   641
convertDirect:howMany from:sourceMetric to:destMetric
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   642
    "given a value in sourceMetric (symbolic), try to convert it
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   643
     to destMetric (symbolic); 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   644
     Only direct conversions are tried; return nil, if the conversion is unknown."
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   645
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   646
    |conversion factor|
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   647
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   648
    conversion := Conversions at:sourceMetric ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
    conversion isNil ifTrue:[^ nil].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   650
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   651
    factor := conversion at:destMetric ifAbsent:nil.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   652
    factor isNil ifTrue:[^ nil].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   653
364
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   654
    factor isNumber ifTrue:[
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   655
        ^ howMany * factor
5482dd3adb76 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 363
diff changeset
   656
    ].
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   657
    ^ factor value:howMany
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   658
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   659
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   660
     UnitConverter convertDirect:1 from:#inch to:#meter 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   661
     UnitConverter convertDirect:1 from:#inch to:#millimeter 
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   662
     UnitConverter convertDirect:1 from:#degrees to:#fahrenheit 
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   663
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   664
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   665
    "Created: 31.5.1996 / 13:54:33 / cg"
515
d7fedc8d697a celsius -> fahrenheit
Claus Gittinger <cg@exept.de>
parents: 453
diff changeset
   666
    "Modified: 29.3.1997 / 17:13:27 / cg"
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   667
!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   668
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   669
unscaled:what
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   670
    "given a unit, return the base and a factor as assoc,
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   671
     or nil if not found"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   672
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   673
    Scaling keysAndValuesDo:[:name :factor |
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   674
        |rest|
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   675
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   676
        (what startsWith:name) ifTrue:[
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   677
            rest := what copyFrom:(name size+1).
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   678
            rest := rest asSymbolIfInterned.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   679
            rest notNil ifTrue:[
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   680
                ^ rest -> factor.
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   681
            ]        
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   682
        ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   683
    ].
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   684
    ^ nil
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   685
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   686
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   687
     UnitConverter unscaled:#millimeter
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   688
     UnitConverter unscaled:#nanometer 
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   689
     UnitConverter unscaled:#kilometer   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   690
     UnitConverter unscaled:#fuzzymeter   
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   691
    "
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   692
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   693
    "Modified: 31.5.1996 / 14:57:25 / cg"
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   694
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   695
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   696
!UnitConverter class methodsFor:'documentation'!
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   697
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   698
version
516
973e10f68449 calorie factor was wrong
Claus Gittinger <cg@exept.de>
parents: 515
diff changeset
   699
    ^ '$Header: /cvs/stx/stx/libbasic2/UnitConverter.st,v 1.9 1997-03-29 18:13:14 cg Exp $'
363
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   700
! !
0fb59dabb315 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   701
UnitConverter initialize!