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