1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Object subclass:#Magnitude
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Magnitude-General'
|
|
18 |
!
|
|
19 |
|
|
20 |
Magnitude comment:'
|
88
|
21 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
|
22 |
All Rights Reserved
|
93
|
23 |
|
|
24 |
$Header: /cvs/stx/stx/libbasic/Magnitude.st,v 1.7 1994-08-05 00:58:54 claus Exp $
|
88
|
25 |
'!
|
1
|
26 |
|
88
|
27 |
!Magnitude class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
32 |
All Rights Reserved
|
|
33 |
|
88
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
1
|
42 |
|
88
|
43 |
version
|
|
44 |
"
|
93
|
45 |
$Header: /cvs/stx/stx/libbasic/Magnitude.st,v 1.7 1994-08-05 00:58:54 claus Exp $
|
88
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
This is an abstract class definining common methods for
|
|
52 |
Objects which can be compared by a kind of greater realation.
|
|
53 |
"
|
|
54 |
! !
|
1
|
55 |
|
|
56 |
!Magnitude methodsFor:'comparing'!
|
|
57 |
|
|
58 |
> aMagnitude
|
|
59 |
"Compare the receiver with the argument and return true if the
|
|
60 |
receiver is greater than the argument. Otherwise return false."
|
|
61 |
|
|
62 |
^ self subclassResponsibility
|
|
63 |
!
|
|
64 |
|
|
65 |
= aMagnitude
|
|
66 |
"Compare the receiver with the argument and return true if the
|
|
67 |
receiver is equal to the argument. Otherwise return false."
|
|
68 |
|
|
69 |
^ self subclassResponsibility
|
|
70 |
!
|
|
71 |
|
|
72 |
<= aMagnitude
|
|
73 |
"Compare the receiver with the argument and return true if the
|
|
74 |
receiver is less than or equal to the argument. Otherwise return false."
|
|
75 |
|
|
76 |
^ (self > aMagnitude) not
|
|
77 |
!
|
|
78 |
|
|
79 |
< aMagnitude
|
|
80 |
"Compare the receiver with the argument and return true if the
|
|
81 |
receiver is less than the argument. Otherwise return false."
|
|
82 |
|
|
83 |
^ (aMagnitude > self)
|
|
84 |
!
|
|
85 |
|
|
86 |
>= aMagnitude
|
|
87 |
"Compare the receiver with the argument and return true if the
|
|
88 |
receiver is greater than or equal to the argument.
|
|
89 |
Otherwise return false."
|
|
90 |
|
|
91 |
^ (aMagnitude > self) not
|
|
92 |
! !
|
|
93 |
|
|
94 |
!Magnitude methodsFor:'testing'!
|
|
95 |
|
|
96 |
between:min and:max
|
|
97 |
"return whether the receiver is less than or equal to the argument max
|
|
98 |
and greater than or equal to the argument min."
|
|
99 |
|
|
100 |
(self < min) ifTrue:[^ false].
|
|
101 |
(self > max) ifTrue:[^ false].
|
|
102 |
^ true
|
56
|
103 |
|
|
104 |
"1.2 between:1 and:2"
|
|
105 |
"(3/2) between:1 and:2"
|
|
106 |
"(3/2) between:0 and:1"
|
1
|
107 |
!
|
|
108 |
|
|
109 |
in:anInterval
|
|
110 |
"return whether the receiver is within the interval bounds"
|
|
111 |
|
|
112 |
(self < anInterval start) ifTrue:[^ false].
|
|
113 |
(self > anInterval stop) ifTrue:[^ false].
|
|
114 |
^ true
|
56
|
115 |
|
|
116 |
"1.2 in:(1 to: 2)"
|
|
117 |
"(3/2) in:(1 to: 2)"
|
|
118 |
"(3/2) in:(0 to: 1)"
|
1
|
119 |
! !
|
|
120 |
|
|
121 |
!Magnitude methodsFor:'misc'!
|
|
122 |
|
|
123 |
min:aMagnitude
|
|
124 |
"return the receiver or the argument, whichever has lesser magnitude"
|
|
125 |
|
|
126 |
(self < aMagnitude) ifTrue:[^ self].
|
|
127 |
^ aMagnitude
|
56
|
128 |
|
|
129 |
"1 min: 2"
|
|
130 |
"1 min: 2.0"
|
|
131 |
"2.0 min: 1.0"
|
|
132 |
"2.0 min: 2"
|
1
|
133 |
!
|
|
134 |
|
|
135 |
max:aMagnitude
|
|
136 |
"return the receiver or the argument, whichever has greater magnitude"
|
|
137 |
|
|
138 |
(self > aMagnitude) ifTrue:[^ self].
|
|
139 |
^ aMagnitude
|
56
|
140 |
|
|
141 |
"1 max: 2"
|
|
142 |
"1 max: 2.0"
|
|
143 |
"2.0 max: 1.0"
|
|
144 |
"2.0 max: 2"
|
1
|
145 |
! !
|