@@ -3,13 +3,8 @@ model Shapes
3
3
dataType Point
4
4
operations
5
5
Point(x : Real, y : Real)
6
- pre: x > -1000 and x <= 1000
7
- pre: y > -1000 and y <= 1000
8
-
9
6
translate(dx : Real, dy : Real)(dx) : Point =
10
7
Point(self.x + dx, self.y + dy)
11
-
12
- --move_x(dx:Real):Point = self with {x=self.x + dx}
13
8
end
14
9
15
10
abstract dataType Shape
23
18
dataType Rectangle < Shape
24
19
operations
25
20
Rectangle(position : Point, width : Real, height : Real)(position)
26
- --Rectangle(x:Real, y:Real, position : Point, width : Real, height : Real)(Point(x, y))
27
-
28
21
perimeter() : Real = 2.0 * width + 2.0 * height
29
22
area() : Real = width * height
30
-
31
23
contains(p : Point) : Boolean =
32
24
self.position.x <= p.x and
33
25
self.position.x + width >= p.x and
34
26
self.position.y <= p.y and
35
27
self.position.y + height >= p.y
36
-
37
- --contains_raw(x : Integer, y : Integer) : Boolean =
38
- --self.contains(Point(x, y))
39
28
end
40
29
41
30
dataType Circle < Shape
42
31
operations
43
32
Circle(position : Point, radius : Real)(position)
44
-
45
33
perimeter() : Real = 2.0 * 3.14 * radius
46
34
area() : Real = 3.14 * radius * radius
47
-
48
- foo(r : Real) : Real = radius + Circle(Point(0, 0), r).radius
49
35
end
0 commit comments