-
Notifications
You must be signed in to change notification settings - Fork 0
/
VisualStructure.ts
283 lines (246 loc) · 7.19 KB
/
VisualStructure.ts
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
///<reference path="VipsBlock.ts"/>
///<reference path="Separator.ts"/>
/**
* Class that represents a visual structure.
* @author Tomas Popela
* @author Lars Meyer
*/
class VisualStructure {
private _nestedBlocks: Array<VipsBlock> = null;
private _childrenVisualStructures: Array<VisualStructure> = null;
private _horizontalSeparators: Array<Separator> = null;
private _verticalSeparators: Array<Separator> = null;
private _width: number = 0;
private _height: number = 0;
private _x: number = 0;
private _y: number = 0;
private _doC: number = 12;
private _containImg: number = -1;
private _containP: number = -1;
private _textLength: number = -1;
private _linkTextLength: number = -1;
private _order: number;
private _containTable: boolean = false;
private _id: string = null;
private _tmpSrcIndex: number = 0;
private _srcIndex: number = 0;
private _minimalDoC: number = 0;
constructor() {
this._nestedBlocks = new Array<VipsBlock>();
this._childrenVisualStructures = new Array<VisualStructure>();
this._horizontalSeparators = new Array<Separator>();
this._verticalSeparators = new Array<Separator>();
}
/**
* @return Nested blocks in structure
*/
public getNestedBlocks(): Array<VipsBlock> {
return this._nestedBlocks;
}
/**
* Adds block to nested blocks
* @param nestedBlock New block
*/
public addNestedBlock(nestedBlock: VipsBlock): void {
this._nestedBlocks.push(nestedBlock);
}
/**
* Sets blocks as nested blocks
* @param vipsBlocks
*/
public setNestedBlocks(vipsBlocks: Array<VipsBlock>): void {
this._nestedBlocks = vipsBlocks;
}
/**
* Clears nested blocks list
*/
public clearNestedBlocks(): void {
while (this._nestedBlocks.length > 0) {
this._nestedBlocks.pop();
}
}
/**
* Adds new child to visual structure children
* @param visualStructure New child
*/
public addChild(visualStructure: VisualStructure): void {
this._childrenVisualStructures.push(visualStructure);
}
/**
* Adds new child to visual structure at given index
* @param visualStructure New child
* @param index Index
*/
public addChildAt(visualStructure: VisualStructure, index: number) {
this._childrenVisualStructures.splice(index, 0, visualStructure);
}
/**
* Returns all children structures
* @return Children structures
*/
public getChildrenVisualStructures(): Array<VisualStructure> {
return this._childrenVisualStructures;
}
/**
* Returns all horizontal separators form structure
* @return List of horizontal separators
*/
public getHorizontalSeparators(): Array<Separator> {
return this._horizontalSeparators;
}
/**
* Adds separators to horizontal separators of structure
* @param horizontalSeparators
*/
public addHorizontalSeparators(horizontalSeparators: Array<Separator>) {
for (let sep of horizontalSeparators) {
this._horizontalSeparators.push(sep);
}
}
/**
* Returns structure's X coordinate
* @return X coordinate
*/
public getX(): number {
return this._x;
}
/**
* Returns structure's Y coordinate
* @return Y coordinate
*/
public getY(): number {
return this._y;
}
/**
* Sets X coordinate
* @param x X coordinate
*/
public setX(x: number): void {
this._x = x;
}
/**
* Sets Y coordinate
* @param y Y coordinate
*/
public setY(y: number): void {
this._y = y;
}
/**
* Sets width of visual structure
* @param width Width
*/
public setWidth(width: number): void {
this._width = width;
}
/**
* Sets height of visual structure
* @param height Height
*/
public setHeight(height: number): void {
this._height = height;
}
/**
* Returns width of visual structure
* @return Visual structure's width
*/
public getWidth(): number {
return this._width;
}
/**
* Returns height of visual structure
* @return Visual structure's height
*/
public getHeight(): number {
return this._height;
}
/**
* Returns list of all vertical separators in visual structure
* @return List of vertical separators
*/
public getVerticalSeparators(): Array<Separator> {
return this._verticalSeparators;
}
/**
* Sets id of visual structure
* @param id Id
*/
public setId(id: string): void {
this._id = id;
}
/**
* Returns id of visual structure
* @return Visual structure's id
*/
public getId(): string {
return this._id;
}
/**
* Sets visual structure's degree of coherence DoC
* @param doC Degree of coherence - DoC
*/
public setDoC(doC: number): void {
this._doC = doC;
}
/**
* Returns structure's degree of coherence DoC
* @return Degree of coherence - DoC
*/
public getDoC(): number {
return this._doC;
}
/**
* Finds minimal DoC in all children visual structures
* @param visualStructure Given visual structure
*/
private findMinimalDoC(visualStructure: VisualStructure): void {
if (!(visualStructure.getId() === "1")) {
if (visualStructure.getDoC() < this._minimalDoC)
this._minimalDoC = visualStructure.getDoC();
}
for (let child of visualStructure.getChildrenVisualStructures()) {
this.findMinimalDoC(child);
}
}
/**
* Updates DoC to normalized DoC
*/
public updateToNormalizedDoC(): void {
this._doC = 12;
for (let separator of this._horizontalSeparators) {
if (separator.normalizedWeight < this._doC)
this._doC = separator.normalizedWeight;
}
for (let separator of this._verticalSeparators) {
if (separator.normalizedWeight < this._doC)
this._doC = separator.normalizedWeight;
}
if (this._doC == 12) {
for (let nestedBlock of this._nestedBlocks)
{
if (nestedBlock.getDoC() < this._doC)
this._doC = nestedBlock.getDoC();
}
}
this._minimalDoC = 12;
this.findMinimalDoC(this);
if (this._minimalDoC < this._doC) {
this._doC = this._minimalDoC;
}
}
/**
* Sets visual structure order
* @param order Order
*/
public setOrder(order: number) {
this._order = order;
}
/**
* Adds list of separators to visual structure vertical separators list.
* @param verticalSeparators
*/
public addVerticalSeparators(verticalSeparators: Array<Separator>): void {
for (let sep of verticalSeparators) {
this._verticalSeparators.push(sep);
}
}
}