-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgrammingLanguagesTransHex
More file actions
218 lines (166 loc) · 5.43 KB
/
Copy pathProgrammingLanguagesTransHex
File metadata and controls
218 lines (166 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?xml version="1.0"?>
<st-source>
<time-stamp>From VisualWorks® Personal Use Edition, 8.3 of 28 lipca 2017 on 13 listopada 2022 at 18:57:42</time-stamp>
<component-created>
<name>ProgrammingLanguages</name> <type>package</type>
</component-created><!-- Package ProgrammingLanguages* -->
<component-property>
<name>ProgrammingLanguages</name> <type>package</type>
<property>comment</property> <value>'Programs for the Programming Languages course.'</value>
</component-property>
<class>
<name>Polygon</name>
<environment>Smalltalk</environment>
<super>Core.Object</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars>vertices name </inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>ProgrammingLanguages</category>
<attributes>
<package>ProgrammingLanguages</package>
</attributes>
</class>
<comment>
<class-id>Polygon</class-id>
<body>Generic polygon class with the first vertex in (0,0)Instance Variables name <MessageForwarder | Object | ProtoObject | ProtoObject> description of name vertices <(Array of: Point)> description of vertices</body>
</comment>
<class>
<name>Square</name>
<environment>Smalltalk</environment>
<super>Polygon</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars></inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>ProgrammingLanguages</category>
<attributes>
<package>ProgrammingLanguages</package>
</attributes>
</class>
<comment>
<class-id>Square</class-id>
<body>A square with its first vertex in (0,0)</body>
</comment>
<class>
<name>RegHexagon</name>
<environment>Smalltalk</environment>
<super>Polygon</super>
<private>false</private>
<indexed-type>none</indexed-type>
<inst-vars></inst-vars>
<class-inst-vars></class-inst-vars>
<imports></imports>
<category>ProgrammingLanguages</category>
<attributes>
<package>ProgrammingLanguages</package>
</attributes>
</class>
<comment>
<class-id>RegHexagon</class-id>
<body>A Regualr Hexagon with its first vertex at (0,0). A personalised Polygon with translation bahaviour.</body>
</comment>
<methods>
<class-id>Polygon</class-id> <category>accessing</category>
<body package="ProgrammingLanguages" selector="name:">name: new_name "sets new name of the polygon" name := new_name</body>
<body package="ProgrammingLanguages" selector="print">print "Print the vertices and the area of the polygon (name it too)" Transcript show: name printString; cr. Transcript show: 'Its area: '. Transcript show: self area printString; cr. Transcript show: 'Its vertices x@y'; cr. 1 to: vertices size do: [:i | Transcript show: (vertices at: i) printString; cr]</body>
<body package="ProgrammingLanguages" selector="name">name "gets polygon name" ^name</body>
</methods>
<methods>
<class-id>Polygon</class-id> <category>transformations</category>
<body package="ProgrammingLanguages" selector="translate:">translate: vector "translates the Polygon by a given vector modifying vertices" vertices := vertices collect: [:pt | pt + vector]</body>
</methods>
<methods>
<class-id>Polygon</class-id> <category>initialize-release</category>
<body package="ProgrammingLanguages" selector="initialize:name:">initialize: numberOfVertices name: newName "object constructor" name := newName. vertices := Array new: numberOfVertices. vertices at: 1 put: 0 @ 0</body>
</methods>
<methods>
<class-id>Square</class-id> <category>actions</category>
<body package="ProgrammingLanguages" selector="area">area "compute area of the square - repaired" "side length" | side | side := (vertices at: 1) dist: (vertices at: 2). ^side squared</body>
</methods>
<methods>
<class-id>Square</class-id> <category>arithmetic</category>
<body package="ProgrammingLanguages" selector="+">+ figure "add 2 figures by adding there areas" | a | a := self area + figure area. ^Square new initialize: a sqrt</body>
</methods>
<methods>
<class-id>Square</class-id> <category>initialize-release</category>
<body package="ProgrammingLanguages" selector="initialize:">initialize: side "create a square of the given side length" super initialize: 4 name: 'Square'. vertices at: 2 put: side@0. vertices at: 3 put: side@side. vertices at: 4 put: 0@side.</body>
</methods>
<methods>
<class-id>RegHexagon</class-id> <category>actions</category>
<body package="ProgrammingLanguages" selector="area">area "calculate the area of the regular hexagon" "side length" | side | side := (vertices at: 1) dist: (vertices at: 2). ^3 / 2 * 3 sqrt * side squared</body>
</methods>
<methods>
<class-id>RegHexagon</class-id> <category>arithmetic</category>
<body package="ProgrammingLanguages" selector="+">+ figure "add 2 hexagons by their areas" | a | a := self area + figure area. a := a * 2 / 3 / 3 sqrt. ^RegHexagon new initialize: a sqrt</body>
</methods>
<methods>
<class-id>RegHexagon</class-id> <category>initialize-release</category>
<body package="ProgrammingLanguages" selector="initialize:">initialize: side "create a regular hexagon with the given side length" super initialize: 6 name: 'Hexagon'. vertices at: 2 put: side @ 0. vertices at: 3 put: (3 / 2 * side) @ (3 sqrt / 2 * side). vertices at: 4 put: side @ (3 sqrt * side). vertices at: 5 put: 0 @ (3 sqrt * side). vertices at: 6 put: (side negated / 2) @ (3 sqrt / 2 * side)</body>
</methods>
</st-source>