home *** CD-ROM | disk | FTP | other *** search
/ Really Useful CD 1 / ReallyUsefulCD1.iso / extras / languages / smalltalk / _smalltalk / prelude / point < prev    next >
Encoding:
Text File  |  1987-12-30  |  1.5 KB  |  71 lines

  1. Class Point :Magnitude
  2. | xvalue yvalue |
  3. [
  4.      < aPoint
  5.           ^ (xvalue < aPoint x) and: [yvalue < aPoint y]
  6. |
  7.      <= aPoint
  8.           ^ (xvalue <= aPoint x) and: [yvalue < aPoint y]
  9. |
  10.      >= aPoint
  11.           ^ (xvalue >= aPoint x) and: [yvalue >= aPoint y]
  12. |
  13.      = aPoint
  14.           ^ (xvalue = aPoint x) and: [yvalue = aPoint y]
  15. |
  16.      * scale
  17.           ^ (Point new x: (xvalue * scale)) y: (yvalue * scale)
  18. |
  19.      + delta
  20.           ^ (Point new x: (xvalue + delta x)) y: (yvalue + delta y)
  21. |
  22.      - delta
  23.           ^ (Point new x: (xvalue - delta x)) y: (yvalue - delta y)
  24. |
  25.      / scale
  26.           ^ (Point new x: (xvalue / scale)) y: (yvalue / scale)
  27. |
  28.      // scale
  29.           ^ (Point new x: (xvalue // scale)) y: (yvalue // scale)
  30. |
  31.      abs
  32.           ^ (Point new x: xvalue abs) y: (yvalue abs)
  33. |
  34.      asString
  35.           ^ xvalue asString , ' @ ' , (yvalue asString)
  36. |
  37.      dist: aPoint
  38.           ^ ((xvalue - aPoint x) squared + 
  39.                (yvalue - aPoint y) squared) sqrt
  40. |
  41.      max: aPoint
  42.           ^ (Point new x: (xvalue max: aPoint x))
  43.                y: (yvalue max: aPoint y)
  44. |
  45.      min: aPoint
  46.           ^ (Point new x: (xvalue min: aPoint x))
  47.                y: (yvalue min: aPoint y)
  48. |
  49.      printString
  50.           ^ xvalue printString , ' @ ' , (yvalue printString)
  51. |
  52.      transpose
  53.           ^ (Point new x: yvalue) y: xvalue
  54. |
  55.      x
  56.           ^ xvalue
  57. |
  58.      x: aValue
  59.           xvalue <- aValue
  60. |
  61.      x: xValue y: yValue
  62.           xvalue <- xValue.
  63.           yvalue <- yValue
  64. |
  65.      y
  66.           ^ yvalue
  67. |
  68.      y: aValue
  69.           yvalue <- aValue
  70. ]
  71.