-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataForClusters.inc
246 lines (215 loc) · 8.35 KB
/
DataForClusters.inc
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
; ==================================================================================================
; Title: DataForClusters.inc
; Author: Héctor S. Enrique
; Version: 1.0.0
; Purpose: Clusters Application Data.
; Notes: Version 1.0.0, January 2024
; - First release.
; ==================================================================================================
Object DataPoint,, Primer
DefineVariable X, real8, 0.0
DefineVariable Y, real8, 0.0
DefineVariable hashx, XWORD, 0
DefineVariable hashy, XWORD, 0
VirtualMethod ComputeDistance, $ObjPtr(DataPoint)
VirtualMethod Equals, $ObjPtr(DataPoint)
VirtualMethod GetHashCode
ObjectEnd
Object DataSet,, Collection
VirtualMethod LoadDS, PSTRING
ObjectEnd
Object DataCluster,, Collection
DefineVariable Cluster, XWORD, 0
DefineVariable avgx, real8, 0.0
DefineVariable avgy, real8, 0.0
RedefineMethod Init, POINTER, XWORD
VirtualMethod CalculateCentroid
VirtualMethod GetCentroid
VirtualMethod Equals, $ObjPtr(DataCluster)
VirtualMethod GetHashCode
Embed centroid, DataPoint
ObjectEnd
if IMPLEMENT
Method DataPoint.ComputeDistance, uses xsi, other:$ObjPtr(DataPoint)
local X0 : real8, Y0 : real8
local temp1 : REAL8
SetObject xsi
mov xax, other
fSlv8 X0 = [xax].$Obj(DataPoint).X
fSlv8 Y0 = [xax].$Obj(DataPoint).Y
fSlv8 = (([xsi].X-X0)^2 + ([xsi].Y-Y0)^2)^0.5
MethodEnd
Method DataPoint.Equals, uses xsi, other:$ObjPtr(DataPoint)
local X0 : real8, Y0 : real8
local fSlvTLS()
SetObject xsi
mov xcx, other
fSlv8 X0 = [xcx].$Obj(DataPoint).X
fSlv8 Y0 = [xcx].$Obj(DataPoint).Y
mov xax, 0
.if other != NULL
.if fEQ([xsi].X,[xcx].$Obj(DataPoint).X)
.if fEQ([xsi].Y,[xcx].$Obj(DataPoint).Y)
mov xax, 1
.endif
.endif
.endif
MethodEnd
Method DataPoint.GetHashCode, uses xsi
SetObject xsi
fSlv xax = [xsi].hashx ^ [xsi].hashy
MethodEnd
Method DataSet.LoadDS, uses xsi, filename : PSTRING
local DskStream : $ObjPtr(DiskStream)
local pMemBlock : POINTER
local inicio : XWORD, final:XWORD
local line[248]:byte, number1[32]:byte, number2[32]:byte
local stored : XWORD, pos : XWORD, pos2 : XWORD
local x:real8, y:real8
local fregTLS()
SetObject xsi
New DiskStream
mov DskStream, xax
OCall DskStream::DiskStream.Init, xsi, filename , GENERIC_READ or GENERIC_WRITE, \
0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
mov xbx, $OCall(DskStream::Stream.GetSize)
;DbgDec xbx
.if eax != -1
MemAlloc ebx
.if xax != NULL
mov pMemBlock, xax
OCall DskStream::Stream.BinRead, pMemBlock, ebx
.if eax != 0
mov inicio, 0
mov final, 0
; lee------------------------
mov xdx, pMemBlock
mov xdi, -1
.repeat
mov al, [xdx]
.if inicio == 0 ; omite la primer línea
.if al == 0Dh
mov inicio, 1
mov xcx, 0
.endif
.else
.if al == 0Dh
@linea:
mov line[xcx], 0
mov pos, 0
mov stored, xdx
lea xdx, line
@loop1:
mov al, [xdx]
.if al == ";"
freg_push xcx
mov xcx, pos
mov number1[xcx], 0
freg_pop xcx
inc xdx
inc pos
mov pos2, 0
jmp @loop2
.else
freg_push xcx
mov xcx, pos
mov number1[xcx], al
freg_pop xcx
.endif
inc xdx
inc pos
jmp @loop1
@loop2:
mov al, [xdx]
.if al == ";"
.else
freg_push xcx
mov xcx, pos2
mov number2[xcx], al
freg_pop xcx
.endif
inc xdx
inc pos
inc pos2
cmp xcx, pos
jne @loop2
freg_push xcx
mov xcx, pos2
mov number2[xcx], 0
freg_pop xcx
invoke StrToSt0A, addr number1
fstp x
invoke StrToSt0A, addr number2
fstp y
New DataPoint
fSlv8 [xax].$Obj(DataPoint).X = x
fSlv8 [xax].$Obj(DataPoint).Y = y
OCall xsi.Insert, xax
.if final == 1
jmp termina
.endif
mov xdx, stored
mov xcx, 0
.elseif al == 0Ah
.else
mov line[xcx], al
inc xcx
.endif
.endif
inc xdx
inc xdi
.until xdi == xbx
mov final, 1
jmp @linea
;-----------------------
termina:
MemFree pMemBlock
.endif
.endif
.endif
Destroy DskStream
MethodEnd
Method DataCluster.Init, uses xsi, pOwner:POINTER, nc : XWORD
SetObject xsi
m2m [xsi].Cluster, nc, @if64bits(xax)
ACall xsi.Init, xsi, 100, 50, COL_MAX_CAPACITY
MethodEnd
Method DataCluster.CalculateCentroid, uses xsi
local count: XWORD
SetObject xsi
fSlv8 [xsi].avgx = 0
fSlv8 [xsi].avgy = 0
mov ecx, [xsi].dCount
.while xcx > 0
lea xax, [sizeof(POINTER)*xcx - sizeof(POINTER)]
add xax, [xsi].pItems
mov xax, POINTER ptr [xax]
fSlv8 [xsi].avgx = [xsi].avgx + [xax].$Obj(DataPoint).X
fSlv8 [xsi].avgy = [xsi].avgy + [xax].$Obj(DataPoint).Y
dec xcx
.endw
fSlv8 [xsi].avgx = [xsi].avgx / [xsi].dCount
fSlv8 [xsi].avgy = [xsi].avgy / [xsi].dCount
fSlv8 [xsi].centroid.X = [xsi].avgx
fSlv8 [xsi].centroid.Y = [xsi].avgy
MethodEnd
Method DataCluster.GetCentroid, uses xsi
SetObject xsi
lea xax, [xsi].centroid
MethodEnd
Method DataCluster.Equals, uses xsi, other : $ObjPtr(DataCluster)
SetObject xsi
mov xax, 0
.if other != NULL
mov xcx, other
mov xcx, [xcx].$Obj(DataCluster).Cluster
.if [xsi].Cluster == xcx
mov xax, 1
.endif
.endif
MethodEnd
Method DataCluster.GetHashCode, uses xsi
SetObject xsi
mov xax, [xsi].Cluster
MethodEnd
endif