Magnitude.st
author claus
Mon, 28 Nov 1994 21:34:28 +0100
changeset 213 3b56a17534fd
parent 93 e31220cb391f
child 379 5b5a130ccd09
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1988 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

Object subclass:#Magnitude
       instanceVariableNames:''
       classVariableNames:''
       poolDictionaries:''
       category:'Magnitude-General'
!

Magnitude comment:'
COPYRIGHT (c) 1988 by Claus Gittinger
	      All Rights Reserved

$Header: /cvs/stx/stx/libbasic/Magnitude.st,v 1.8 1994-11-28 20:33:01 claus Exp $
'!

!Magnitude class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1988 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

version
"
$Header: /cvs/stx/stx/libbasic/Magnitude.st,v 1.8 1994-11-28 20:33:01 claus Exp $
"
!

documentation
"
    This is an abstract class definining common methods for
    Objects which can be compared by a kind of greater realation.
"
! !

!Magnitude methodsFor:'comparing'!

> aMagnitude
    "Compare the receiver with the argument and return true if the
     receiver is greater than the argument. Otherwise return false."

    ^ self subclassResponsibility
!

= aMagnitude
    "Compare the receiver with the argument and return true if the
     receiver is equal to the argument. Otherwise return false."

    ^ self subclassResponsibility
!

<= aMagnitude
    "Compare the receiver with the argument and return true if the
     receiver is less than or equal to the argument. Otherwise return false."

    ^ (self > aMagnitude) not
!

< aMagnitude
    "Compare the receiver with the argument and return true if the
     receiver is less than the argument. Otherwise return false."

    ^ (aMagnitude > self)
!

>= aMagnitude
    "Compare the receiver with the argument and return true if the
     receiver is greater than or equal to the argument.
     Otherwise return false."

    ^ (aMagnitude > self) not
!

min:aMagnitude
    "return the receiver or the argument, whichever has lesser magnitude"

    (self < aMagnitude) ifTrue:[^ self].
    ^ aMagnitude

    "
     1 min: 2
     1 min: 2.0
     2.0 min: 1.0
     2.0 min: 2
    "
!

max:aMagnitude
    "return the receiver or the argument, whichever has greater magnitude"

    (self > aMagnitude) ifTrue:[^ self].
    ^ aMagnitude

    "
     1 max: 2
     1 max: 2.0
     2.0 max: 1.0
     2.0 max: 2
    "
! !

!Magnitude methodsFor:'testing'!

between:min and:max
    "return whether the receiver is less than or equal to the argument max
     and greater than or equal to the argument min."

    (self < min) ifTrue:[^ false].
    (self > max) ifTrue:[^ false].
    ^ true

    "
     1.2 between:1 and:2
     (3/2) between:1 and:2
     (3/2) between:0 and:1
    "
!

in:anInterval
    "return whether the receiver is within the interval bounds"

    (self < anInterval start) ifTrue:[^ false].
    (self > anInterval stop) ifTrue:[^ false].
    ^ true

    "
     1.2 in:(1 to: 2)
     (3/2) in:(1 to: 2)
     (3/2) in:(0 to: 1)
    "
! !