/tutorial/triangle/version4/triangle.e

http://github.com/tybor/Liberty · Specman e · 87 lines · 65 code · 14 blank · 8 comment · 2 complexity · d80152ce2dce8a31730faf0650606a2a MD5 · raw file

  1. class TRIANGLE
  2. -- Description of TRIANGLEs objects.
  3. inherit
  4. ANY
  5. redefine is_equal, copy
  6. end
  7. creation {ANY}
  8. make
  9. feature {ANY}
  10. p1: POINT
  11. -- First point.
  12. p2: POINT
  13. -- Second point.
  14. p3: POINT
  15. -- Third point.
  16. translate (dx, dy: REAL) is
  17. -- To translate `Current' using `dx' and `dy'.
  18. do
  19. p1.translate(dx, dy)
  20. p2.translate(dx, dy)
  21. p3.translate(dx, dy)
  22. end
  23. display_on (stream: OUTPUT_STREAM) is
  24. -- To display `Current' on the `stream'.
  25. require
  26. stream.is_connected
  27. do
  28. stream.put_string("TRIANGLE[%N%T")
  29. p1.display_on(stream)
  30. stream.put_string("%N%T")
  31. p2.display_on(stream)
  32. stream.put_string("%N%T")
  33. p3.display_on(stream)
  34. stream.put_string("%T]%N")
  35. ensure
  36. stream.is_connected
  37. end
  38. is_equal (other: TRIANGLE): BOOLEAN is
  39. do
  40. if p1.is_equal(other.p1) then
  41. if p2.is_equal(other.p2) then
  42. Result := p3.is_equal(other.p3)
  43. end
  44. end
  45. end
  46. copy (other: TRIANGLE) is
  47. -- Modify `Current' in order to become like `other'.
  48. do
  49. p1 := other.p1.twin
  50. p2 := other.p2.twin
  51. p3 := other.p3.twin
  52. end
  53. feature {}
  54. make (a, b, c: POINT) is
  55. -- To create a new TRIANGLE.
  56. require
  57. a /= Void
  58. b /= Void
  59. c /= Void
  60. do
  61. p1 := a
  62. p2 := b
  63. p3 := c
  64. ensure
  65. p1 = a
  66. p2 = b
  67. p3 = c
  68. end
  69. invariant
  70. p1 /= Void
  71. p2 /= Void
  72. p3 /= Void
  73. end -- class TRIANGLE