A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
fast-clipping.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008 INESC Porto
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Gustavo Carneiro <gjc@inescporto.pt>
7
*/
8
9
#include "
fast-clipping.h
"
10
11
namespace
ns3
12
{
13
namespace
visualizer
14
{
15
16
FastClipping::FastClipping
(
Vector2
clipMin,
Vector2
clipMax)
17
:
m_clipMin
(clipMin),
18
m_clipMax
(clipMax)
19
{
20
}
21
22
void
23
FastClipping::ClipStartTop
(
Line
& line)
const
24
{
25
line.
start
.
x
+= line.
dx
* (
m_clipMin
.y - line.
start
.
y
) / line.
dy
;
26
line.
start
.
y
=
m_clipMin
.y;
27
}
28
29
void
30
FastClipping::ClipStartBottom
(
Line
& line)
const
31
{
32
line.
start
.
x
+= line.
dx
* (
m_clipMax
.y - line.
start
.
y
) / line.
dy
;
33
line.
start
.
y
=
m_clipMax
.y;
34
}
35
36
void
37
FastClipping::ClipStartRight
(
Line
& line)
const
38
{
39
line.
start
.
y
+= line.
dy
* (
m_clipMax
.x - line.
start
.
x
) / line.
dx
;
40
line.
start
.
x
=
m_clipMax
.x;
41
}
42
43
void
44
FastClipping::ClipStartLeft
(
Line
& line)
const
45
{
46
line.
start
.
y
+= line.
dy
* (
m_clipMin
.x - line.
start
.
x
) / line.
dx
;
47
line.
start
.
x
=
m_clipMin
.x;
48
}
49
50
void
51
FastClipping::ClipEndTop
(
Line
& line)
const
52
{
53
line.
end
.
x
+= line.
dx
* (
m_clipMin
.y - line.
end
.
y
) / line.
dy
;
54
line.
end
.
y
=
m_clipMin
.y;
55
}
56
57
void
58
FastClipping::ClipEndBottom
(
Line
& line)
const
59
{
60
line.
end
.
x
+= line.
dx
* (
m_clipMax
.y - line.
end
.
y
) / line.
dy
;
61
line.
end
.
y
=
m_clipMax
.y;
62
}
63
64
void
65
FastClipping::ClipEndRight
(
Line
& line)
const
66
{
67
line.
end
.
y
+= line.
dy
* (
m_clipMax
.x - line.
end
.
x
) / line.
dx
;
68
line.
end
.
x
=
m_clipMax
.x;
69
}
70
71
void
72
FastClipping::ClipEndLeft
(
Line
& line)
const
73
{
74
line.
end
.
y
+= line.
dy
* (
m_clipMin
.x - line.
end
.
x
) / line.
dx
;
75
line.
end
.
x
=
m_clipMin
.x;
76
}
77
78
bool
79
FastClipping::ClipLine
(
Line
& line)
80
{
81
uint8_t lineCode = 0;
82
83
if
(line.
end
.
y
<
m_clipMin
.y)
84
{
85
lineCode |= 8;
86
}
87
else
if
(line.
end
.
y
>
m_clipMax
.y)
88
{
89
lineCode |= 4;
90
}
91
92
if
(line.
end
.
x
>
m_clipMax
.x)
93
{
94
lineCode |= 2;
95
}
96
else
if
(line.
end
.
x
<
m_clipMin
.x)
97
{
98
lineCode |= 1;
99
}
100
101
if
(line.
start
.
y
<
m_clipMin
.y)
102
{
103
lineCode |= 128;
104
}
105
else
if
(line.
start
.
y
>
m_clipMax
.y)
106
{
107
lineCode |= 64;
108
}
109
110
if
(line.
start
.
x
>
m_clipMax
.x)
111
{
112
lineCode |= 32;
113
}
114
else
if
(line.
start
.
x
<
m_clipMin
.x)
115
{
116
lineCode |= 16;
117
}
118
119
// 9 - 8 - A
120
// | | |
121
// 1 - 0 - 2
122
// | | |
123
// 5 - 4 - 6
124
switch
(lineCode)
125
{
126
// center
127
case
0x00:
128
return
true
;
129
130
case
0x01:
131
ClipEndLeft
(line);
132
return
true
;
133
134
case
0x02:
135
ClipEndRight
(line);
136
return
true
;
137
138
case
0x04:
139
ClipEndBottom
(line);
140
return
true
;
141
142
case
0x05:
143
ClipEndLeft
(line);
144
if
(line.
end
.
y
>
m_clipMax
.y)
145
{
146
ClipEndBottom
(line);
147
}
148
return
true
;
149
150
case
0x06:
151
ClipEndRight
(line);
152
if
(line.
end
.
y
>
m_clipMax
.y)
153
{
154
ClipEndBottom
(line);
155
}
156
return
true
;
157
158
case
0x08:
159
ClipEndTop
(line);
160
return
true
;
161
162
case
0x09:
163
ClipEndLeft
(line);
164
if
(line.
end
.
y
<
m_clipMin
.y)
165
{
166
ClipEndTop
(line);
167
}
168
return
true
;
169
170
case
0x0A:
171
ClipEndRight
(line);
172
if
(line.
end
.
y
<
m_clipMin
.y)
173
{
174
ClipEndTop
(line);
175
}
176
return
true
;
177
178
// left
179
case
0x10:
180
ClipStartLeft
(line);
181
return
true
;
182
183
case
0x12:
184
ClipStartLeft
(line);
185
ClipEndRight
(line);
186
return
true
;
187
188
case
0x14:
189
ClipStartLeft
(line);
190
if
(line.
start
.
y
>
m_clipMax
.y)
191
{
192
return
false
;
193
}
194
ClipEndBottom
(line);
195
return
true
;
196
197
case
0x16:
198
ClipStartLeft
(line);
199
if
(line.
start
.
y
>
m_clipMax
.y)
200
{
201
return
false
;
202
}
203
ClipEndBottom
(line);
204
if
(line.
end
.
x
>
m_clipMax
.x)
205
{
206
ClipEndRight
(line);
207
}
208
return
true
;
209
210
case
0x18:
211
ClipStartLeft
(line);
212
if
(line.
start
.
y
<
m_clipMin
.y)
213
{
214
return
false
;
215
}
216
ClipEndTop
(line);
217
return
true
;
218
219
case
0x1A:
220
ClipStartLeft
(line);
221
if
(line.
start
.
y
<
m_clipMin
.y)
222
{
223
return
false
;
224
}
225
ClipEndTop
(line);
226
if
(line.
end
.
x
>
m_clipMax
.x)
227
{
228
ClipEndRight
(line);
229
}
230
return
true
;
231
232
// right
233
case
0x20:
234
ClipStartRight
(line);
235
return
true
;
236
237
case
0x21:
238
ClipStartRight
(line);
239
ClipEndLeft
(line);
240
return
true
;
241
242
case
0x24:
243
ClipStartRight
(line);
244
if
(line.
start
.
y
>
m_clipMax
.y)
245
{
246
return
false
;
247
}
248
ClipEndBottom
(line);
249
return
true
;
250
251
case
0x25:
252
ClipStartRight
(line);
253
if
(line.
start
.
y
>
m_clipMax
.y)
254
{
255
return
false
;
256
}
257
ClipEndBottom
(line);
258
if
(line.
end
.
x
<
m_clipMin
.x)
259
{
260
ClipEndLeft
(line);
261
}
262
return
true
;
263
264
case
0x28:
265
ClipStartRight
(line);
266
if
(line.
start
.
y
<
m_clipMin
.y)
267
{
268
return
false
;
269
}
270
ClipEndTop
(line);
271
return
true
;
272
273
case
0x29:
274
ClipStartRight
(line);
275
if
(line.
start
.
y
<
m_clipMin
.y)
276
{
277
return
false
;
278
}
279
ClipEndTop
(line);
280
if
(line.
end
.
x
<
m_clipMin
.x)
281
{
282
ClipEndLeft
(line);
283
}
284
return
true
;
285
286
// bottom
287
case
0x40:
288
ClipStartBottom
(line);
289
return
true
;
290
291
case
0x41:
292
ClipStartBottom
(line);
293
if
(line.
start
.
x
<
m_clipMin
.x)
294
{
295
return
false
;
296
}
297
ClipEndLeft
(line);
298
if
(line.
end
.
y
>
m_clipMax
.y)
299
{
300
ClipEndBottom
(line);
301
}
302
return
true
;
303
304
case
0x42:
305
ClipStartBottom
(line);
306
if
(line.
start
.
x
>
m_clipMax
.x)
307
{
308
return
false
;
309
}
310
ClipEndRight
(line);
311
return
true
;
312
313
case
0x48:
314
ClipStartBottom
(line);
315
ClipEndTop
(line);
316
return
true
;
317
318
case
0x49:
319
ClipStartBottom
(line);
320
if
(line.
start
.
x
<
m_clipMin
.x)
321
{
322
return
false
;
323
}
324
ClipEndLeft
(line);
325
if
(line.
end
.
y
<
m_clipMin
.y)
326
{
327
ClipEndTop
(line);
328
}
329
return
true
;
330
331
case
0x4A:
332
ClipStartBottom
(line);
333
if
(line.
start
.
x
>
m_clipMax
.x)
334
{
335
return
false
;
336
}
337
ClipEndRight
(line);
338
if
(line.
end
.
y
<
m_clipMin
.y)
339
{
340
ClipEndTop
(line);
341
}
342
return
true
;
343
344
// bottom-left
345
case
0x50:
346
ClipStartLeft
(line);
347
if
(line.
start
.
y
>
m_clipMax
.y)
348
{
349
ClipStartBottom
(line);
350
}
351
return
true
;
352
353
case
0x52:
354
ClipEndRight
(line);
355
if
(line.
end
.
y
>
m_clipMax
.y)
356
{
357
return
false
;
358
}
359
ClipStartBottom
(line);
360
if
(line.
start
.
x
<
m_clipMin
.x)
361
{
362
ClipStartLeft
(line);
363
}
364
return
true
;
365
366
case
0x58:
367
ClipEndTop
(line);
368
if
(line.
end
.
x
<
m_clipMin
.x)
369
{
370
return
false
;
371
}
372
ClipStartBottom
(line);
373
if
(line.
start
.
x
<
m_clipMin
.x)
374
{
375
ClipStartLeft
(line);
376
}
377
return
true
;
378
379
case
0x5A:
380
ClipStartLeft
(line);
381
if
(line.
start
.
y
<
m_clipMin
.y)
382
{
383
return
false
;
384
}
385
ClipEndRight
(line);
386
if
(line.
end
.
y
>
m_clipMax
.y)
387
{
388
return
false
;
389
}
390
if
(line.
start
.
y
>
m_clipMax
.y)
391
{
392
ClipStartBottom
(line);
393
}
394
if
(line.
end
.
y
<
m_clipMin
.y)
395
{
396
ClipEndTop
(line);
397
}
398
return
true
;
399
400
// bottom-right
401
case
0x60:
402
ClipStartRight
(line);
403
if
(line.
start
.
y
>
m_clipMax
.y)
404
{
405
ClipStartBottom
(line);
406
}
407
return
true
;
408
409
case
0x61:
410
ClipEndLeft
(line);
411
if
(line.
end
.
y
>
m_clipMax
.y)
412
{
413
return
false
;
414
}
415
ClipStartBottom
(line);
416
if
(line.
start
.
x
>
m_clipMax
.x)
417
{
418
ClipStartRight
(line);
419
}
420
return
true
;
421
422
case
0x68:
423
ClipEndTop
(line);
424
if
(line.
end
.
x
>
m_clipMax
.x)
425
{
426
return
false
;
427
}
428
ClipStartRight
(line);
429
if
(line.
start
.
y
>
m_clipMax
.y)
430
{
431
ClipStartBottom
(line);
432
}
433
return
true
;
434
435
case
0x69:
436
ClipEndLeft
(line);
437
if
(line.
end
.
y
>
m_clipMax
.y)
438
{
439
return
false
;
440
}
441
ClipStartRight
(line);
442
if
(line.
start
.
y
<
m_clipMin
.y)
443
{
444
return
false
;
445
}
446
if
(line.
end
.
y
<
m_clipMin
.y)
447
{
448
ClipEndTop
(line);
449
}
450
if
(line.
start
.
y
>
m_clipMax
.y)
451
{
452
ClipStartBottom
(line);
453
}
454
return
true
;
455
456
// top
457
case
0x80:
458
ClipStartTop
(line);
459
return
true
;
460
461
case
0x81:
462
ClipStartTop
(line);
463
if
(line.
start
.
x
<
m_clipMin
.x)
464
{
465
return
false
;
466
}
467
ClipEndLeft
(line);
468
return
true
;
469
470
case
0x82:
471
ClipStartTop
(line);
472
if
(line.
start
.
x
>
m_clipMax
.x)
473
{
474
return
false
;
475
}
476
ClipEndRight
(line);
477
return
true
;
478
479
case
0x84:
480
ClipStartTop
(line);
481
ClipEndBottom
(line);
482
return
true
;
483
484
case
0x85:
485
ClipStartTop
(line);
486
if
(line.
start
.
x
<
m_clipMin
.x)
487
{
488
return
false
;
489
}
490
ClipEndLeft
(line);
491
if
(line.
end
.
y
>
m_clipMax
.y)
492
{
493
ClipEndBottom
(line);
494
}
495
return
true
;
496
497
case
0x86:
498
ClipStartTop
(line);
499
if
(line.
start
.
x
>
m_clipMax
.x)
500
{
501
return
false
;
502
}
503
ClipEndRight
(line);
504
if
(line.
end
.
y
>
m_clipMax
.y)
505
{
506
ClipEndBottom
(line);
507
}
508
return
true
;
509
510
// top-left
511
case
0x90:
512
ClipStartLeft
(line);
513
if
(line.
start
.
y
<
m_clipMin
.y)
514
{
515
ClipStartTop
(line);
516
}
517
return
true
;
518
519
case
0x92:
520
ClipEndRight
(line);
521
if
(line.
end
.
y
<
m_clipMin
.y)
522
{
523
return
false
;
524
}
525
ClipStartTop
(line);
526
if
(line.
start
.
x
<
m_clipMin
.x)
527
{
528
ClipStartLeft
(line);
529
}
530
return
true
;
531
532
case
0x94:
533
ClipEndBottom
(line);
534
if
(line.
end
.
x
<
m_clipMin
.x)
535
{
536
return
false
;
537
}
538
ClipStartLeft
(line);
539
if
(line.
start
.
y
<
m_clipMin
.y)
540
{
541
ClipStartTop
(line);
542
}
543
return
true
;
544
545
case
0x96:
546
ClipStartLeft
(line);
547
if
(line.
start
.
y
>
m_clipMax
.y)
548
{
549
return
false
;
550
}
551
ClipEndRight
(line);
552
if
(line.
end
.
y
<
m_clipMin
.y)
553
{
554
return
false
;
555
}
556
if
(line.
start
.
y
<
m_clipMin
.y)
557
{
558
ClipStartTop
(line);
559
}
560
if
(line.
end
.
y
>
m_clipMax
.y)
561
{
562
ClipEndBottom
(line);
563
}
564
return
true
;
565
566
// top-right
567
case
0xA0:
568
ClipStartRight
(line);
569
if
(line.
start
.
y
<
m_clipMin
.y)
570
{
571
ClipStartTop
(line);
572
}
573
return
true
;
574
575
case
0xA1:
576
ClipEndLeft
(line);
577
if
(line.
end
.
y
<
m_clipMin
.y)
578
{
579
return
false
;
580
}
581
ClipStartTop
(line);
582
if
(line.
start
.
x
>
m_clipMax
.x)
583
{
584
ClipStartRight
(line);
585
}
586
return
true
;
587
588
case
0xA4:
589
ClipEndBottom
(line);
590
if
(line.
end
.
x
>
m_clipMax
.x)
591
{
592
return
false
;
593
}
594
ClipStartRight
(line);
595
if
(line.
start
.
y
<
m_clipMin
.y)
596
{
597
ClipStartTop
(line);
598
}
599
return
true
;
600
601
case
0xA5:
602
ClipEndLeft
(line);
603
if
(line.
end
.
y
<
m_clipMin
.y)
604
{
605
return
false
;
606
}
607
ClipStartRight
(line);
608
if
(line.
start
.
y
>
m_clipMax
.y)
609
{
610
return
false
;
611
}
612
if
(line.
end
.
y
>
m_clipMax
.y)
613
{
614
ClipEndBottom
(line);
615
}
616
if
(line.
start
.
y
<
m_clipMin
.y)
617
{
618
ClipStartTop
(line);
619
}
620
return
true
;
621
}
622
623
return
false
;
624
}
625
626
}
// namespace visualizer
627
}
// namespace ns3
ns3::visualizer::FastClipping::ClipEndRight
void ClipEndRight(Line &line) const
Clip end right function.
Definition
fast-clipping.cc:65
ns3::visualizer::FastClipping::ClipLine
bool ClipLine(Line &line)
Clip line function.
Definition
fast-clipping.cc:79
ns3::visualizer::FastClipping::m_clipMin
Vector2 m_clipMin
The minimum point of the bounding area required clipping.
Definition
fast-clipping.h:124
ns3::visualizer::FastClipping::ClipStartRight
void ClipStartRight(Line &line) const
Clip start right function.
Definition
fast-clipping.cc:37
ns3::visualizer::FastClipping::ClipEndTop
void ClipEndTop(Line &line) const
Clip end top function.
Definition
fast-clipping.cc:51
ns3::visualizer::FastClipping::ClipStartBottom
void ClipStartBottom(Line &line) const
Clip start bottom function.
Definition
fast-clipping.cc:30
ns3::visualizer::FastClipping::m_clipMax
Vector2 m_clipMax
The maximum point of the bounding area required clipping.
Definition
fast-clipping.h:125
ns3::visualizer::FastClipping::ClipStartTop
void ClipStartTop(Line &line) const
Clip start top function.
Definition
fast-clipping.cc:23
ns3::visualizer::FastClipping::FastClipping
FastClipping(Vector2 clipMin, Vector2 clipMax)
Constructor.
Definition
fast-clipping.cc:16
ns3::visualizer::FastClipping::ClipStartLeft
void ClipStartLeft(Line &line) const
Clip start left function.
Definition
fast-clipping.cc:44
ns3::visualizer::FastClipping::ClipEndLeft
void ClipEndLeft(Line &line) const
Clip end left function.
Definition
fast-clipping.cc:72
ns3::visualizer::FastClipping::ClipEndBottom
void ClipEndBottom(Line &line) const
Clip end bottom function.
Definition
fast-clipping.cc:58
fast-clipping.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
visualizer
Definition
__init__.py:1
ns3::visualizer::FastClipping::Line
The line struct.
Definition
fast-clipping.h:44
ns3::visualizer::FastClipping::Line::dx
double dx
dX
Definition
fast-clipping.h:47
ns3::visualizer::FastClipping::Line::start
Vector2 start
The start point of the line.
Definition
fast-clipping.h:45
ns3::visualizer::FastClipping::Line::dy
double dy
dY
Definition
fast-clipping.h:48
ns3::visualizer::FastClipping::Line::end
Vector2 end
The end point of the line.
Definition
fast-clipping.h:46
ns3::visualizer::FastClipping::Vector2
The Vector 2 struct.
Definition
fast-clipping.h:33
ns3::visualizer::FastClipping::Vector2::y
double y
Y coordinate.
Definition
fast-clipping.h:35
ns3::visualizer::FastClipping::Vector2::x
double x
X coordinate.
Definition
fast-clipping.h:34
src
visualizer
model
fast-clipping.cc
Generated on
for ns-3 by
1.15.0