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