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