PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

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