18#include <private/qdebug_p.h>
21# include <qt_windows.h>
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
68
69
70
71
72
73
74
77
78
79
80
81
82
83
84
85
86
89
90
93
94
95
96
97
98
101
102
103
104
105
106
107
108
109
112
113
114
115
116
117
118
119
120
121
122
123
126
127
128
129
132
133
134
135
136
137
138
139
142
143
144
145
146
147
148
149
150
151
152
155
156
157
158
159
160
161
162QRegion::QRegion(
int x,
int y,
int w,
int h, RegionType t)
164 QRegion tmp(QRect(x, y, w, h), t);
170
171
172
173
174
176void QRegion::detach()
178 if (d->ref.isShared())
183#define QRGN_SETRECT 1
184#define QRGN_SETELLIPSE 2
185#define QRGN_SETPTARRAY_ALT 3
186#define QRGN_SETPTARRAY_WIND 4
187#define QRGN_TRANSLATE 5
195#ifndef QT_NO_DATASTREAM
198
199
200
201
202
203
204
205
206void QRegion::exec(
const QByteArray &buffer,
int ver, QDataStream::ByteOrder byteOrder)
208 QByteArray copy = buffer;
209 QDataStream s(©, QIODevice::ReadOnly);
212 s.setByteOrder(byteOrder);
219 if (s.version() == 1) {
228 qWarning(
"QRegion::exec: Internal error");
234 rgn = QRegion(r, id ==
QRGN_SETRECT ? Rectangle : Ellipse);
242 rgn.translate(p.x(), p.y());
244 QByteArray bop1, bop2;
256 rgn = r1.intersected(r2);
259 rgn = r1.subtracted(r2);
270 for (
int i=0; i <
static_cast<
int>(n); i++) {
272 rgn = rgn.united(QRegion(r));
281
282
285
286
287
288
291
292
293
294
295
296
299
300
301
302
305
306
307
308
309
310
311
313QDataStream &operator<<(QDataStream &s,
const QRegion &r)
315 auto b = r.begin(), e = r.end();
317 s <<
static_cast<quint32>(0);
319 const auto size = e - b;
320 if (s.version() == 1) {
321 for (
auto i = size - 1; i > 0; --i) {
322 s <<
static_cast<quint32>(12 + i * 24);
323 s <<
static_cast<
int>(
QRGN_OR);
325 for (
auto it = b; it != e; ++it)
326 s <<
static_cast<quint32>(4+8) <<
static_cast<
int>(
QRGN_SETRECT) << *it;
328 s << quint32(4 + 4 + 16 * size);
331 for (
auto it = b; it != e; ++it)
339
340
341
342
343
344
345
347QDataStream &operator>>(QDataStream &s, QRegion &r)
351 r.exec(b, s.version(), s.byteOrder());
356#ifndef QT_NO_DEBUG_STREAM
359 QDebugStateSaver saver(s);
364 }
else if (r.isEmpty()) {
367 const int count = r.rectCount();
369 s <<
"size=" << count <<
", bounds=(";
370 QtDebugUtils::formatQRect(s, r.boundingRect());
374 for (
const QRect &rect : r) {
378 QtDebugUtils::formatQRect(s, rect);
396
397
398
399
400
401QRegion QRegion::operator|(
const QRegion &r)
const
402 {
return united(r); }
405
406
407
408
409
410QRegion QRegion::operator+(
const QRegion &r)
const
411 {
return united(r); }
414
415
416
417QRegion QRegion::operator+(
const QRect &r)
const
418 {
return united(r); }
421
422
423
424
425
426QRegion QRegion::operator&(
const QRegion &r)
const
427 {
return intersected(r); }
430
431
432
433QRegion QRegion::operator&(
const QRect &r)
const
435 return intersected(r);
439
440
441
442
443
444QRegion QRegion::operator-(
const QRegion &r)
const
445 {
return subtracted(r); }
448
449
450
451
452
453QRegion QRegion::operator^(
const QRegion &r)
const
457
458
459
460
461
462
463QRegion& QRegion::operator|=(
const QRegion &r)
464 {
return *
this = *
this | r; }
467
468
469
470
471
472
474
475
476
477
478
479
480
481
484
485
486
487
488
489
490
491
492QRegion& QRegion::operator&=(
const QRegion &r)
493 {
return *
this = *
this & r; }
496
497
498
499#if defined (Q_OS_UNIX) || defined (Q_OS_WIN)
500QRegion& QRegion::operator&=(
const QRect &r)
502 return *
this = *
this & r;
505QRegion& QRegion::operator&=(
const QRect &r)
507 return *
this &= (QRegion(r));
512
513
514
515
516
517
518
519
520QRegion& QRegion::operator-=(
const QRegion &r)
521 {
return *
this = *
this - r; }
524
525
526
527
528
529
530QRegion& QRegion::operator^=(
const QRegion &r)
531 {
return *
this = *
this ^ r; }
534
535
536
537
538
541
542
543QRegion::operator QVariant()
const
545 return QVariant::fromValue(*
this);
549
550
551
552
553
556
557
558
559
560
563
564
565
566
567
568
569
570
571
572
573
576
577
578
579
580
581
582
583
584
587QRegion::translated(
int dx,
int dy)
const
590 ret.translate(dx, dy);
597 return (r1.right() >= r2.left() && r1.left() <= r2.right() &&
598 r1.bottom() >= r2.top() && r1.top() <= r2.bottom());
602
603
604
605
606
607bool QRegion::intersects(
const QRegion ®ion)
const
609 if (isEmpty() || region.isEmpty())
612 if (!rect_intersects(boundingRect(), region.boundingRect()))
614 if (rectCount() == 1 && region.rectCount() == 1)
617 for (
const QRect &myRect : *
this)
618 for (
const QRect &otherRect : region)
619 if (rect_intersects(myRect, otherRect))
625
626
627
628
629
630
633#if !defined (Q_OS_UNIX) && !defined (Q_OS_WIN) || defined(Q_QDOC)
635
636
637
638QRegion QRegion::intersect(
const QRect &r)
const
640 return intersect(QRegion(r));
645
646
647
648
649
650
653
654
655
656
657
658
659
660
663
664
665
666
667
668
669
670
671
674
675
676
677
678
681
682
683
684
685
686
689
690
691
692
693
694
695
698
699
700
701
702
703
704
705
706
707
708
711
712
713
714
715
716
717
720
721
722
723
724
725
726
727
728
729
730
733
734
735
736
737
738
739
740
741
742
743
744
747
748
749
750
751
752
753
754
755
756
757
758
761
762
763
764
765
768
769
770
771
772
773
774
775
776
777
778
779
782
783
784
785
786
787
788
789
790
791
792
793
796
797
798
799
800
801
802
803
804
805
808
809
810
811
812
815
816
817
818
819
820
821
822
823
824
827
828
829
830
831
834
835
836
837
838
839
840
841
842
843
846
847
848
849
850
853
854
855
856
857
858
859
860
861
862
865
866
867
868
869
872
873
874
875
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
915 return qMin(point.x(), next->point.x());
920 return qMax(point.x(), next->point.x());
923 bool overlaps(
const Segment &other)
const
925 return left() < other.right() && other.left() < right();
928 void connect(Segment &other)
933 horizontal = (point.y() == other.point.y());
936 void merge(Segment &other)
938 if (right() <= other.right()) {
940 Segment *oprev = other.prev;
950 Segment *onext = other.next;
967void mergeSegments(Segment *a,
int na, Segment *b,
int nb)
972 while (i != na && j != nb) {
975 const int ra = sa.right();
976 const int rb = sb.right();
984void addSegmentsToPath(Segment *segment, QPainterPath &path)
986 Segment *current = segment;
987 path.moveTo(current->point);
989 current->added =
true;
991 Segment *last = current;
992 current = current->next;
993 while (current != segment) {
994 if (current->horizontal != last->horizontal)
995 path.lineTo(current->point);
996 current->added =
true;
998 current = current->next;
1014 QPainterPath result;
1015 if (region.rectCount() == 1) {
1016 result.addRect(region.boundingRect());
1020 auto rect = region.begin();
1021 const auto end = region.end();
1023 QVarLengthArray<Segment> segments;
1024 segments.resize(4 * (end - rect));
1026 int lastRowSegmentCount = 0;
1027 Segment *lastRowSegments =
nullptr;
1029 int lastSegment = 0;
1031 while (rect != end) {
1032 const int y = rect[0].y();
1034 while (&rect[count] != end && rect[count].y() == y)
1037 for (
int i = 0; i < count; ++i) {
1038 int offset = lastSegment + i;
1039 segments[offset] = Segment(rect[i].topLeft());
1040 segments[offset += count] = Segment(rect[i].topRight() + QPoint(1, 0));
1041 segments[offset += count] = Segment(rect[i].bottomRight() + QPoint(1, 1));
1042 segments[offset += count] = Segment(rect[i].bottomLeft() + QPoint(0, 1));
1044 offset = lastSegment + i;
1045 for (
int j = 0; j < 4; ++j)
1046 segments[offset + j * count].connect(segments[offset + ((j + 1) % 4) * count]);
1049 if (lastRowSegments && lastY == y)
1050 mergeSegments(lastRowSegments, lastRowSegmentCount, &segments[lastSegment], count);
1052 lastRowSegments = &segments[lastSegment + 2 * count];
1053 lastRowSegmentCount = count;
1054 lastSegment += 4 * count;
1055 lastY = y + rect[0].height();
1059 for (
int i = 0; i < lastSegment; ++i) {
1060 Segment *segment = &segments[i];
1061 if (!segment->added)
1062 addSegmentsToPath(segment, result);
1070
1071
1092
1093
1094
1096 return contains(r.extents);
1100 const QRect &r1 = innerRect;
1101 return r2.left() >= r1.left() && r2.right() <= r1.right()
1102 && r2.top() >= r1.top() && r2.bottom() <= r1.bottom();
1106
1107
1109 const QRect &r2 = extents;
1110 return r2.left() >= r1.left() && r2.right() <= r1.right()
1111 && r2.top() >= r1.top() && r2.bottom() <= r1.bottom();
1115 const int area = rect.width() * rect.height();
1131 {
return numRects == 1 ? &extents : rects.data(); }
1133 const QRect *
end()
const noexcept
1148 const QRect *nextToTop,
1149 const QRect *nextToBottom);
1151 const QRect *nextToBottom,
1152 const QRect *nextToTop);
1154#ifdef QT_REGION_DEBUG
1166 return (right->top() == left->top()
1167 && right->bottom() == left->bottom()
1168 && right->left() <= (left->right() + 1));
1179 left->setRight(right->right());
1189 right->setLeft(left->left());
1197 const QRect *nextToTop,
1198 const QRect *nextToBottom)
1200 if (nextToTop && nextToTop->y() == top->y())
1202 if (nextToBottom && nextToBottom->y() == bottom->y())
1205 return ((top->bottom() >= (bottom->top() - 1))
1206 && top->left() == bottom->left()
1207 && top->right() == bottom->right());
1211 const QRect *nextToTop,
1212 const QRect *nextToBottom)
1215 top->setBottom(bottom->bottom());
1223 const QRect *nextToBottom,
1224 const QRect *nextToTop)
1227 bottom->setTop(top->top());
1238 r.setLeft(qMax(r1.left(), r2.left()));
1239 r.setRight(qMin(r1.right(), r2.right()));
1240 r.setTop(qMax(r1.top(), r2.top()));
1241 r.setBottom(qMin(r1.bottom(), r2.bottom()));
1247 Q_ASSERT(extents.intersects(rect));
1250#ifdef QT_REGION_DEBUG
1254 const QRect r = rect.normalized();
1256 innerRect = QRect();
1259 QRect *dest = rects.data();
1260 const QRect *src = dest;
1264 *dest = qt_rect_intersect_normalized(*src++, r);
1265 if (dest->isEmpty())
1271 extents.setLeft(qMin(extents.left(), dest->left()));
1274 extents.setRight(qMax(extents.right(), dest->right()));
1275 extents.setBottom(qMax(extents.bottom(), dest->bottom()));
1277 const QRect *nextToLast = (
numRects > 1 ? dest - 2 :
nullptr);
1280 if (canMergeFromBelow(dest - 1, dest, nextToLast,
nullptr)) {
1281 if (!n || src->y() != dest->y() || src->left() > r.right()) {
1282 QRect *prev = dest - 1;
1283 prev->setBottom(dest->bottom());
1293#ifdef QT_REGION_DEBUG
1300 Q_ASSERT(!r->isEmpty());
1302 QRect *myLast = (numRects == 1 ? &extents : rects.data() + (numRects - 1));
1305 const QRect *nextToTop = (
numRects > 2 ? myLast - 2 :
nullptr);
1315 if (rects.size() < numRects)
1316 rects.resize(numRects);
1317 rects[numRects - 1] = *r;
1319 extents.setCoords(qMin(extents.left(), r->left()),
1320 qMin(extents.top(), r->top()),
1321 qMax(extents.right(), r->right()),
1322 qMax(extents.bottom(), r->bottom()));
1324#ifdef QT_REGION_DEBUG
1334 append(&r->extents);
1340 QRect *destRect = rects.data() + numRects;
1341 const QRect *srcRect = r->rects.constData();
1346 const QRect *rFirst = srcRect;
1347 QRect *myLast = destRect - 1;
1348 const QRect *nextToLast = (
numRects > 1 ? myLast - 1 :
nullptr);
1352 const QRect *rNextToFirst = (numAppend > 1 ? rFirst + 2 :
nullptr);
1358 nextToLast = (
numRects > 2 ? myLast - 2 :
nullptr);
1359 rNextToFirst = (numAppend > 0 ? srcRect :
nullptr);
1372 if (numAppend > 0) {
1373 const int newNumRects =
numRects + numAppend;
1374 if (newNumRects > rects.size()) {
1375 rects.resize(newNumRects);
1376 destRect = rects.data() + numRects;
1378 memcpy(destRect, srcRect, numAppend *
sizeof(QRect));
1386 innerRect = r->innerRect;
1390 destRect = &extents;
1391 srcRect = &r->extents;
1392 extents.setCoords(qMin(destRect->left(), srcRect->left()),
1393 qMin(destRect->top(), srcRect->top()),
1394 qMax(destRect->right(), srcRect->right()),
1395 qMax(destRect->bottom(), srcRect->bottom()));
1397#ifdef QT_REGION_DEBUG
1407 prepend(&r->extents);
1418 QRect *myFirst = rects.data();
1419 const QRect *nextToFirst = (
numRects > 1 ? myFirst + 1 :
nullptr);
1420 const QRect *rLast = r->rects.constData() + r
->numRects - 1;
1421 const QRect *rNextToLast = (r
->numRects > 1 ? rLast - 1 :
nullptr);
1425 rNextToLast = (numPrepend > 1 ? rLast - 1 :
nullptr);
1431 nextToFirst = (
numRects > 2? myFirst + 2 :
nullptr);
1432 rNextToLast = (numPrepend > 0 ? rLast :
nullptr);
1443 if (numPrepend > 0) {
1444 const int newNumRects =
numRects + numPrepend;
1445 if (newNumRects > rects.size())
1446 rects.resize(newNumRects);
1449 memmove(rects.data() + numPrepend, rects.constData() + numSkip,
1450 numRects *
sizeof(QRect));
1453 memcpy(rects.data(), r->rects.constData(), numPrepend *
sizeof(QRect));
1461 innerRect = r->innerRect;
1465 extents.setCoords(qMin(extents.left(), r->extents.left()),
1466 qMin(extents.top(), r->extents.top()),
1467 qMax(extents.right(), r->extents.right()),
1468 qMax(extents.bottom(), r->extents.bottom()));
1470#ifdef QT_REGION_DEBUG
1477 Q_ASSERT(!r->isEmpty());
1479 QRect *myFirst = (numRects == 1 ? &extents : rects.data());
1482 const QRect *nextToFirst = (
numRects > 2 ? myFirst + 2 :
nullptr);
1485 memmove(rects.data(), rects.constData() + 1,
1486 numRects *
sizeof(QRect));
1497 extents.setCoords(qMin(extents.left(), r->left()),
1498 qMin(extents.top(), r->top()),
1499 qMax(extents.right(), r->right()),
1500 qMax(extents.bottom(), r->bottom()));
1502#ifdef QT_REGION_DEBUG
1509 Q_ASSERT(!r->isEmpty());
1511 const QRect *myLast = (numRects == 1) ? &extents : (rects.constData() + (numRects - 1));
1512 if (r->top() > myLast->bottom())
1514 if (r->top() == myLast->top()
1515 && r->height() == myLast->height()
1516 && r->left() > myLast->right())
1526 return canAppend(r
->numRects == 1 ? &r->extents : r->rects.constData());
1531 Q_ASSERT(!r->isEmpty());
1533 const QRect *myFirst = (numRects == 1) ? &extents : rects.constData();
1534 if (r->bottom() < myFirst->top())
1536 if (r->top() == myFirst->top()
1537 && r->height() == myFirst->height()
1538 && r->right() < myFirst->left())
1551#ifdef QT_REGION_DEBUG
1552void QRegionPrivate::selfTest()
const
1554 if (numRects == 0) {
1555 Q_ASSERT(extents.isEmpty());
1556 Q_ASSERT(innerRect.isEmpty());
1560 Q_ASSERT(innerArea == (innerRect.width() * innerRect.height()));
1562 if (numRects == 1) {
1563 Q_ASSERT(innerRect == extents);
1564 Q_ASSERT(!innerRect.isEmpty());
1568 for (
int i = 0; i < numRects; ++i) {
1569 const QRect r = rects.at(i);
1570 if ((r.width() * r.height()) > innerArea)
1571 qDebug() <<
"selfTest(): innerRect" << innerRect <<
'<' << r;
1574 QRect r = rects.first();
1575 for (
int i = 1; i < numRects; ++i) {
1576 const QRect r2 = rects.at(i);
1577 Q_ASSERT(!r2.isEmpty());
1578 if (r2.y() == r.y()) {
1579 Q_ASSERT(r.bottom() == r2.bottom());
1580 Q_ASSERT(r.right() < (r2.left() + 1));
1582 Q_ASSERT(r2.y() >= r.bottom());
1589Q_CONSTINIT
static QRegionPrivate qrp;
1590Q_CONSTINIT
const QRegion::QRegionData QRegion::shared_empty = {Q_REFCOUNT_INITIALIZE_STATIC, &qrp};
1593 const QRect *r2,
const QRect *r2End,
int y1,
int y2);
1603#define RectangleOut 0
1604#define RectangleIn 1
1605#define RectanglePart 2
1606#define EvenOddRule 0
1607#define WindingRule 1
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1662QT_BEGIN_INCLUDE_NAMESPACE
1664QT_END_INCLUDE_NAMESPACE
1667
1668
1669
1670#define EXTENTCHECK(r1, r2)
1671 ((r1)->right() >= (r2)->left() &&
1672 (r1)->left() <= (r2)->right() &&
1673 (r1)->bottom() >= (r2)->top() &&
1674 (r1)->top() <= (r2)->bottom())
1677
1678
1679#define EXTENTS(r,idRect){
1680 if((r)->left() < (idRect)->extents.left())
1681 (idRect)->extents.setLeft((r)->left());
1682 if((r)->top() < (idRect)->extents.top())
1683 (idRect)->extents.setTop((r)->top());
1684 if((r)->right() > (idRect)->extents.right())
1685 (idRect)->extents.setRight((r)->right());
1686 if((r)->bottom() > (idRect)->extents.bottom())
1687 (idRect)->extents.setBottom((r)->bottom());
1691
1692
1693#define MEMCHECK(dest, rect, firstrect){
1694 if ((dest).numRects >= ((dest).rects.size()-1
)){
1695 firstrect.resize(firstrect.size() * 2
);
1696 (rect) = (firstrect).data() + (dest).numRects;
1702
1703
1704
1705#define NUMPTSTOBUFFER 200
1708
1709
1710
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1799 if (rect->isEmpty())
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1835 dest.innerRect.setCoords(0, 0, -1, -1);
1838 dest.extents.setCoords(0, 0, -1, -1);
1842 pExtents = &dest.extents;
1843 if (dest.rects.isEmpty())
1844 pBox = &dest.extents;
1846 pBox = dest.rects.constData();
1850
1851
1852
1853
1854
1855
1856 pExtents->setLeft(pBox->left());
1857 pExtents->setTop(pBox->top());
1858 pExtents->setRight(pBoxEnd->right());
1859 pExtents->setBottom(pBoxEnd->bottom());
1861 Q_ASSERT(pExtents->top() <= pExtents->bottom());
1862 while (pBox <= pBoxEnd) {
1863 if (pBox->left() < pExtents->left())
1864 pExtents->setLeft(pBox->left());
1865 if (pBox->right() > pExtents->right())
1866 pExtents->setRight(pBox->right());
1870 Q_ASSERT(pExtents->left() <= pExtents->right());
1874
1875
1876
1880 if (region.rects.size()) {
1881 QRect *pbox = region.rects.data();
1885 pbox->translate(x, y);
1889 region.extents.translate(x, y);
1890 region.innerRect.translate(x, y);
1894
1895
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1910 const QRect *r2,
const QRect *r2End,
int y1,
int y2)
1916 pNextRect = dest.rects.data() + dest
.numRects;
1918 while (r1 != r1End && r2 != r2End) {
1919 x1 = qMax(r1->left(), r2->left());
1920 x2 = qMin(r1->right(), r2->right());
1923
1924
1925
1926
1927
1928
1931 MEMCHECK(dest, pNextRect, dest.rects)
1932 pNextRect->setCoords(x1, y1, x2, y2);
1938
1939
1940
1941
1942 if (r1->right() < r2->right()) {
1944 }
else if (r2->right() < r1->right()) {
1954
1955
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1982 QRect *rData = dest.rects.data();
1986 pPrevBox = rData + prevStart;
1987 prevNumRects = curStart - prevStart;
1990
1991
1992
1993
1994 pCurBox = rData + curStart;
1995 bandY1 = pCurBox->top();
1996 for (curNumRects = 0; pCurBox != pRegEnd && pCurBox->top() == bandY1; ++curNumRects) {
2000 if (pCurBox != pRegEnd) {
2002
2003
2004
2005
2006
2008 while ((pRegEnd - 1)->top() == pRegEnd->top())
2010 curStart = pRegEnd - rData;
2014 if (curNumRects == prevNumRects && curNumRects != 0) {
2015 pCurBox -= curNumRects;
2017
2018
2019
2020 if (pPrevBox->bottom() == pCurBox->top() - 1) {
2022
2023
2024
2025
2026
2028 if (pPrevBox->left() != pCurBox->left() || pPrevBox->right() != pCurBox->right()) {
2035 }
while (prevNumRects != 0);
2038 pCurBox -= curNumRects;
2039 pPrevBox -= curNumRects;
2042
2043
2044
2045
2047 pPrevBox->setBottom(pCurBox->bottom());
2052 }
while (curNumRects != 0);
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064 if (pCurBox == pRegEnd) {
2065 curStart = prevStart;
2068 *pPrevBox++ = *pCurBox++;
2070 }
while (pCurBox != pRegEnd);
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2116 const QRect *r1BandEnd;
2117 const QRect *r2BandEnd;
2122
2123
2124
2125
2126
2127
2129 r1 = ®1->extents;
2131 r1 = reg1->rects.constData();
2133 r2 = ®2->extents;
2135 r2 = reg2->rects.constData();
2143
2144
2145
2146
2147
2148 const QList<QRect> destRectsCopy = dest.rects;
2149 Q_UNUSED(destRectsCopy);
2154
2155
2156
2157
2158
2159
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175 if (reg1->extents.top() < reg2->extents.top())
2176 ybot = reg1->extents.top() - 1;
2178 ybot = reg2->extents.top() - 1;
2181
2182
2183
2184
2185
2186
2187
2188
2195
2196
2197
2198
2199
2200
2202 while (r1BandEnd != r1End && r1BandEnd->top() == r1->top())
2206 while (r2BandEnd != r2End && r2BandEnd->top() == r2->top())
2210
2211
2212
2213
2214
2215
2216
2217 if (r1->top() < r2->top()) {
2218 top = qMax(r1->top(), ybot + 1);
2219 bot = qMin(r1->bottom(), r2->top() - 1);
2221 if (nonOverlap1Func !=
nullptr && bot >= top)
2222 (*nonOverlap1Func)(dest, r1, r1BandEnd, top, bot);
2224 }
else if (r2->top() < r1->top()) {
2225 top = qMax(r2->top(), ybot + 1);
2226 bot = qMin(r2->bottom(), r1->top() - 1);
2228 if (nonOverlap2Func !=
nullptr && bot >= top)
2229 (*nonOverlap2Func)(dest, r2, r2BandEnd, top, bot);
2236
2237
2238
2239
2240
2245
2246
2247
2248 ybot = qMin(r1->bottom(), r2->bottom());
2251 (*overlapFunc)(dest, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot);
2257
2258
2259
2260 if (r1->bottom() == ybot)
2262 if (r2->bottom() == ybot)
2264 }
while (r1 != r1End && r2 != r2End);
2267
2268
2271 if (nonOverlap1Func !=
nullptr) {
2274 while (r1BandEnd < r1End && r1BandEnd->top() == r1->top())
2276 (*nonOverlap1Func)(dest, r1, r1BandEnd, qMax(r1->top(), ybot + 1), r1->bottom());
2278 }
while (r1 != r1End);
2280 }
else if ((r2 != r2End) && (nonOverlap2Func !=
nullptr)) {
2283 while (r2BandEnd < r2End && r2BandEnd->top() == r2->top())
2285 (*nonOverlap2Func)(dest, r2, r2BandEnd, qMax(r2->top(), ybot + 1), r2->bottom());
2287 }
while (r2 != r2End);
2294
2295
2296
2297
2298
2299
2300
2301 if (qMax(4, dest
.numRects) < (dest.rects.size() >> 1))
2306
2307
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2331 pNextRect = dest.rects.data() + dest
.numRects;
2336 Q_ASSERT(r->left() <= r->right());
2337 MEMCHECK(dest, pNextRect, dest.rects)
2338 pNextRect->setCoords(r->left(), y1, r->right(), y2);
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2363 const QRect *r2,
const QRect *r2End,
int y1,
int y2)
2367 pNextRect = dest.rects.data() + dest
.numRects;
2370 if ((dest.numRects != 0
) &&
2371 (pNextRect[-1
].top() == y1) &&
2372 (pNextRect[-1
].bottom() == y2) &&
2373 (pNextRect[-1
].right() >= r->left()-1
)) {
2374 if (pNextRect[-1
].right() < r->right()) {
2375 pNextRect[-1
].setRight(r->right());
2376 dest.updateInnerRect(pNextRect[-1
]);
2377 Q_ASSERT(pNextRect[-1
].left() <= pNextRect[-1
].right());
2380 MEMCHECK(dest, pNextRect, dest.rects)
2381 pNextRect->setCoords(r->left(), y1, r->right(), y2);
2382 dest.updateInnerRect(*pNextRect);
2389 while (r1 != r1End && r2 != r2End) {
2390 if (r1->left() < r2->left()) {
2400 }
while (r1 != r1End);
2402 while (r2 != r2End) {
2419 dest.innerRect = reg1->innerRect;
2422 dest.innerRect = reg2->innerRect;
2426 dest.extents.setCoords(qMin(reg1->extents.left(), reg2->extents.left()),
2427 qMin(reg1->extents.top(), reg2->extents.top()),
2428 qMax(reg1->extents.right(), reg2->extents.right()),
2429 qMax(reg1->extents.bottom(), reg2->extents.bottom()));
2433
2434
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2452 const QRect *rEnd,
int y1,
int y2)
2456 pNextRect = dest.rects.data() + dest
.numRects;
2461 Q_ASSERT(r->left() <= r->right());
2462 MEMCHECK(dest, pNextRect, dest.rects)
2463 pNextRect->setCoords(r->left(), y1, r->right(), y2);
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2486 const QRect *r2,
const QRect *r2End,
int y1,
int y2)
2494 pNextRect = dest.rects.data() + dest
.numRects;
2496 while (r1 != r1End && r2 != r2End) {
2497 if (r2->right() < x1) {
2499
2500
2502 }
else if (r2->left() <= x1) {
2504
2505
2506 x1 = r2->right() + 1;
2507 if (x1 > r1->right()) {
2509
2510
2511
2519 }
else if (r2->left() <= r1->right()) {
2521
2522
2523
2524 Q_ASSERT(x1 < r2->left());
2525 MEMCHECK(dest, pNextRect, dest.rects)
2526 pNextRect->setCoords(x1, y1, r2->left() - 1, y2);
2530 x1 = r2->right() + 1;
2531 if (x1 > r1->right()) {
2533
2534
2544
2545
2546 if (r1->right() >= x1) {
2547 MEMCHECK(dest, pNextRect, dest.rects)
2548 pNextRect->setCoords(x1, y1, r1->right(), y2);
2559
2560
2561 while (r1 != r1End) {
2562 Q_ASSERT(x1 <= r1->right());
2563 MEMCHECK(dest, pNextRect, dest.rects)
2564 pNextRect->setCoords(x1, y1, r1->right(), y2);
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2591 Q_ASSERT(
EXTENTCHECK(®M->extents, ®S->extents));
2598
2599
2600
2601
2602
2603
2610 Q_ASSERT(
EXTENTCHECK(&sra->extents, &srb->extents));
2639
2640
2647 }
else if (r1->extents != r2->extents) {
2652 const QRect *rr1 = (r1
->numRects == 1) ? &r1->extents : r1->rects.constData();
2653 const QRect *rr2 = (r2
->numRects == 1) ? &r2->extents : r2->rects.constData();
2654 for (
int i = 0; i < r1
->numRects; ++i, ++rr1, ++rr2) {
2666 bool operator()(QRect lhs,
int rhs)
const {
return lhs.bottom() < rhs; }
2667 bool operator()(
int lhs, QRect rhs)
const {
return lhs < rhs.bottom(); }
2668 bool operator()(QRect lhs, QRect rhs)
const {
return lhs.bottom() < rhs.bottom(); }
2676 if (!pRegion->extents.contains(x, y))
2680 if (pRegion->innerRect.contains(x, y))
2685 const QRect *pbox = pRegion->rects.constData();
2686 const QRect *pboxEnd = pbox + pRegion
->numRects;
2687 pbox =
std::lower_bound(pbox, pboxEnd, y, ByBottom());
2688 for (; pbox != pboxEnd; ++pbox) {
2691 if (y < pbox->top() || x < pbox->left())
2693 if (x <= pbox->right())
2702 const QRect *pboxEnd;
2703 QRect rect(rx, ry, rwidth, rheight);
2704 QRect *prect = ▭
2705 int partIn, partOut;
2714 pbox = (region
->numRects == 1) ? ®ion->extents : region->rects.constData();
2716 for (; pbox < pboxEnd; ++pbox) {
2717 if (pbox->bottom() < ry)
2720 if (pbox->top() > ry) {
2722 if (partIn || pbox->top() > prect->bottom())
2727 if (pbox->right() < rx)
2730 if (pbox->left() > rx) {
2736 if (pbox->left() <= prect->right()) {
2742 if (pbox->right() >= prect->right()) {
2743 ry = pbox->bottom() + 1;
2744 if (ry > prect->bottom())
2749
2750
2751
2752
2753
2754
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) {
2850
2851
2852
2859 incr1 = -2
* dx + 2
* (dy) * m1;
2860 incr2 = -2
* dx + 2
* (dy) * m;
2861 d = 2
* m * (dy) - 2
* dx - 2
* (dy);
2865 incr1 = 2
* dx - 2
* (dy) * m1;
2866 incr2 = 2
* dx - 2
* (dy) * m;
2867 d = -2
* m * (dy) + 2
* dx;
2870}
2872#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) {
2892}
2896
2897
2898
2899
2900
2901
2910#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres)
2911 BRESINITPGON(dmaj, min1, min2, bres.minor_axis, bres.d,
2912 bres.m, bres.m1, bres.incr1, bres.incr2)
2914#define BRESINCRPGONSTRUCT(bres)
2915 BRESINCRPGON(bres.d, bres.minor_axis, bres.m, bres.m1, bres.incr1, bres.incr2)
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2966
2967
2969#define COUNTERCLOCKWISE -1
2996
2997
2998
2999
3000#define SLLSPERBLOCK 25
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022#define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) {
3023 if (pAET->ymax == y) {
3024 pPrevAET->next = pAET->next;
3025 pAET = pPrevAET->next;
3028 pAET->back = pPrevAET;
3035}
3039
3040
3041
3042
3043
3044
3045#define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) {
3046 if (pAET->ymax == y) {
3047 pPrevAET->next = pAET->next;
3048 pAET = pPrevAET->next;
3050 pAET->back = pPrevAET;
3057}
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3110#define LARGE_COORDINATE INT_MAX
3111#define SMALL_COORDINATE INT_MIN
3114
3115
3116
3117
3118
3119
3120
3121
3123 ScanLineListBlock **SLLBlock,
int *iSLLBlock)
3125 EdgeTableEntry *start, *prev;
3126 ScanLineList *pSLL, *pPrevSLL;
3127 ScanLineListBlock *tmpSLLBlock;
3130
3131
3134 while (pSLL && (pSLL
->scanline < scanline)) {
3140
3141
3142 if ((!pSLL) || (pSLL
->scanline > scanline)) {
3146 (ScanLineListBlock *)malloc(
sizeof(ScanLineListBlock));
3147 Q_CHECK_PTR(tmpSLLBlock);
3148 (*SLLBlock)
->next = tmpSLLBlock;
3149 tmpSLLBlock
->next = (ScanLineListBlock *)
nullptr;
3150 *SLLBlock = tmpSLLBlock;
3153 pSLL = &((*SLLBlock)
->SLLs[(*iSLLBlock)++]);
3162
3163
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3204 EdgeTable *ET, EdgeTableEntry *AET, EdgeTableEntry *pETEs,
3205 ScanLineListBlock *pSLLBlock)
3214 Q_ASSERT(count > 1);
3217
3218
3225
3226
3230 pSLLBlock
->next =
nullptr;
3232 PrevPt = &pts[count - 1];
3235
3236
3237
3238
3243
3244
3245 if (PrevPt->y() > CurrPt->y()) {
3256
3257
3258 if (bottom->y() != top->y()) {
3259 pETEs
->ymax = bottom->y() - 1;
3262
3263
3264 dy = bottom->y() - top->y();
3267 InsertEdgeInET(ET, pETEs, top->y(), &pSLLBlock, &iSLLBlock);
3269 if (PrevPt->y() > ET
->ymax)
3271 if (PrevPt->y() < ET
->ymin)
3281
3282
3283
3284
3285
3286
3287
3289static void loadAET(EdgeTableEntry *AET, EdgeTableEntry *ETEs)
3291 EdgeTableEntry *pPrevAET;
3292 EdgeTableEntry *tmp;
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3335 EdgeTableEntry *pWETE;
3348 if ((!inside && !isInside) || (inside && isInside)) {
3359
3360
3361
3362
3363
3364
3365
3369 EdgeTableEntry *pETEchase;
3370 EdgeTableEntry *pETEinsert;
3371 EdgeTableEntry *pETEchaseBackTMP;
3379 pETEchase = pETEchase
->back;
3382 if (pETEchase != pETEinsert) {
3383 pETEchaseBackTMP = pETEchase
->back;
3387 pETEinsert
->next = pETEchase;
3389 pETEchase
->back = pETEinsert;
3390 pETEinsert
->back = pETEchaseBackTMP;
3398
3399
3402 ScanLineListBlock *tmpSLLBlock;
3405 tmpSLLBlock = pSLLBlock
->next;
3407 pSLLBlock = tmpSLLBlock;
3424 QRect *regRects = reg->rects.data() + *lastRow;
3425 bool canExtend = reg->rects.size() - *lastRow == numSpans
3426 && !(*needsExtend && *extendTo + 1 != y)
3427 && (*needsExtend || regRects[0].y() + regRects[0].height() == y);
3429 for (
int i = 0; i < numSpans && canExtend; ++i) {
3430 if (regRects[i].x() != spans[i].x1 || regRects[i].right() != spans[i].x2 - 1)
3436 *needsExtend =
true;
3439 for (
int i = 0; i < reg->rects.size() - *lastRow; ++i)
3440 regRects[i].setBottom(*extendTo);
3443 *lastRow = reg->rects.size();
3444 reg->rects.reserve(*lastRow + numSpans);
3445 for (
int i = 0; i < numSpans; ++i)
3446 reg->rects << QRect(spans[i]
.x1, y, spans[i]
.width(), 1);
3448 if (spans[0]
.x1 < reg->extents.left())
3449 reg->extents.setLeft(spans[0]
.x1);
3451 if (spans[numSpans-1]
.x2 - 1 > reg->extents.right())
3452 reg->extents.setRight(spans[numSpans-1]
.x2 - 1);
3454 *needsExtend =
false;
3459
3460
3461
3462
3463
3464
3465
3471 bool needsExtend =
false;
3472 QVarLengthArray<QRegionSpan> row;
3473 qsizetype rowSize = 0;
3475 reg->extents.setLeft(INT_MAX);
3476 reg->extents.setRight(INT_MIN);
3479 POINTBLOCK *CurPtBlock = FirstPtBlock;
3480 for (; numFullPtBlocks >= 0; --numFullPtBlocks) {
3483 if (!numFullPtBlocks)
3484 i = iCurPtBlock >> 1;
3486 row.resize(qMax(row.size(), rowSize + i));
3487 for (
QPoint *pts = CurPtBlock
->pts; i--; pts += 2) {
3488 const int width = pts[1].x() - pts[0].x();
3490 if (rowSize && row[rowSize-1].x2 == pts[0].x())
3491 row[rowSize-1].x2 = pts[1].x();
3493 row[rowSize++] = QRegionSpan(pts[0].x(), pts[1].x());
3497 QPoint *next = i ? &pts[2] : (numFullPtBlocks && iCurPtBlock ? CurPtBlock->next->pts :
nullptr);
3499 if (!next || next->y() != pts[0].y()) {
3500 flushRow(row.data(), pts[0].y(), rowSize, reg, &lastRow, &extendTo, &needsExtend);
3506 CurPtBlock = CurPtBlock
->next;
3510 for (
int i = lastRow; i < reg->rects.size(); ++i)
3511 reg->rects[i].setBottom(extendTo);
3517 reg->extents.setTop(reg->rects[0].top());
3518 reg->extents.setBottom(reg->rects[lastRow].bottom());
3520 for (
int i = 0; i < reg->rects.size(); ++i)
3523 reg->extents.setCoords(0, 0, 0, 0);
3528
3529
3530
3531
3532
3533
3534
3535
3542 EdgeTableEntry *pAET;
3545 EdgeTableEntry *pWETE;
3548 EdgeTableEntry *pPrevAET;
3550 EdgeTableEntry *AET;
3551 EdgeTableEntry *pETEs;
3552 ScanLineListBlock SLLBlock;
3553 int fixWAET =
false;
3554 POINTBLOCK FirstPtBlock, *curPtBlock;
3555 FirstPtBlock
.pts =
reinterpret_cast<
QPoint *>(FirstPtBlock.data);
3556 FirstPtBlock
.next =
nullptr;
3557 POINTBLOCK *tmpPtBlock;
3558 int numFullPtBlocks = 0;
3560 Q_ASSERT(Count > 1);
3565 if (((Count == 4) ||
3566 ((Count == 5) && (Pts[4].x() == Pts[0].x()) && (Pts[4].y() == Pts[0].y())))
3567 && (((Pts[0].y() == Pts[1].y()) && (Pts[1].x() == Pts[2].x()) && (Pts[2].y() == Pts[3].y())
3568 && (Pts[3].x() == Pts[0].x())) || ((Pts[0].x() == Pts[1].x())
3569 && (Pts[1].y() == Pts[2].y()) && (Pts[2].x() == Pts[3].x())
3570 && (Pts[3].y() == Pts[0].y())))) {
3571 int x = qMin(Pts[0].x(), Pts[2].x());
3572 region->extents.setLeft(x);
3573 int y = qMin(Pts[0].y(), Pts[2].y());
3574 region->extents.setTop(y);
3575 region->extents.setWidth(qMax(Pts[0].x(), Pts[2].x()) - x);
3576 region->extents.setHeight(qMax(Pts[0].y(), Pts[2].y()) - y);
3577 if ((region->extents.left() <= region->extents.right()) &&
3578 (region->extents.top() <= region->extents.bottom())) {
3580 region->innerRect = region->extents;
3581 region
->innerArea = region->innerRect.width() * region->innerRect.height();
3586 if (!(pETEs =
static_cast<EdgeTableEntry *>(malloc(
sizeof(EdgeTableEntry) * Count)))) {
3593 AET =
new EdgeTableEntry;
3594 pts = FirstPtBlock
.pts;
3598 curPtBlock = &FirstPtBlock;
3604 qWarning(
"QRegion: creating region from big polygon failed...!");
3615
3616
3617 for (y = ET.ymin; y < ET.ymax; ++y) {
3620
3621
3622
3623 if (pSLL && y == pSLL->scanline) {
3624 loadAET(AET, pSLL->edgelist);
3631
3632
3634 pts->setX(pAET->bres.minor_axis);
3640
3641
3643 tmpPtBlock = (POINTBLOCK *)malloc(
sizeof(POINTBLOCK));
3644 Q_CHECK_PTR(tmpPtBlock);
3645 tmpPtBlock->pts =
reinterpret_cast<QPoint *>(tmpPtBlock->data);
3646 curPtBlock->next = tmpPtBlock;
3647 curPtBlock = tmpPtBlock;
3648 pts = curPtBlock->pts;
3658
3659
3660 for (y = ET.ymin; y < ET.ymax; ++y) {
3662
3663
3664
3665 if (pSLL && y == pSLL->scanline) {
3666 loadAET(AET, pSLL->edgelist);
3675
3676
3679
3680
3681
3682 if (pWETE == pAET) {
3683 pts->setX(pAET->bres.minor_axis);
3689
3690
3692 tmpPtBlock =
static_cast<POINTBLOCK *>(malloc(
sizeof(POINTBLOCK)));
3693 tmpPtBlock->pts =
reinterpret_cast<QPoint *>(tmpPtBlock->data);
3694 curPtBlock->next = tmpPtBlock;
3695 curPtBlock = tmpPtBlock;
3696 pts = curPtBlock->pts;
3700 pWETE = pWETE->nextWETE;
3706
3707
3708
3709 if (InsertionSort(AET) || fixWAET) {
3716 FreeStorage(SLLBlock.next);
3717 PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region);
3718 for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;) {
3719 tmpPtBlock = curPtBlock->next;
3721 curPtBlock = tmpPtBlock;
3727 FreeStorage(SLLBlock.next);
3729 for (curPtBlock = FirstPtBlock
.next; --numFullPtBlocks >= 0;) {
3730 tmpPtBlock = curPtBlock
->next;
3732 curPtBlock = tmpPtBlock;
3742 const QImage image = bitmap.toImage();
3750 xr.setCoords(prev1, y, x-1
, y);
3751 UnionRectWithRegion(&xr, region, *region);
3754 const uchar zero = 0;
3755 bool little = image.format() == QImage::Format_MonoLSB;
3759 for (y = 0; y < image.height(); ++y) {
3760 const uchar *line = image.constScanLine(y);
3761 int w = image.width();
3764 for (x = 0; x < w;) {
3765 uchar byte = line[x / 8];
3766 if (x > w - 8 || byte!=all) {
3768 for (
int b = 8; b > 0 && x < w; --b) {
3769 if (!(byte & 0x01) == !all) {
3785 for (
int b = 8; b > 0 && x < w; --b) {
3786 if (!(byte & 0x80) == !all) {
3816 : d(
const_cast<QRegionData*>(&shared_empty))
3820QRegion::QRegion(
const QRect &r, RegionType t)
3823 d =
const_cast<QRegionData*>(&shared_empty);
3825 d =
new QRegionData;
3826 if (t == Rectangle) {
3827 d->qt_rgn =
new QRegionPrivate(r);
3828 }
else if (t == Ellipse) {
3830 path.addEllipse(r.x(), r.y(), r.width(), r.height());
3831 QPolygon a = path.toSubpathPolygons().at(0).toPolygon();
3832 d->qt_rgn = PolygonRegion(a.constData(), a.size(),
EvenOddRule);
3837QRegion::QRegion(
const QPolygon &a, Qt::FillRule fillRule)
3840 QRegionPrivate *qt_rgn = PolygonRegion(a.constData(), a.size(),
3843 d =
new QRegionData;
3846 d =
const_cast<QRegionData*>(&shared_empty);
3849 d =
const_cast<QRegionData*>(&shared_empty);
3853QRegion::QRegion(
const QRegion &r)
3860QRegion::QRegion(
const QBitmap &bm)
3863 d =
const_cast<QRegionData*>(&shared_empty);
3865 d =
new QRegionData;
3866 d->qt_rgn = qt_bitmapToRegion(bm);
3870void QRegion::cleanUp(QRegion::QRegionData *x)
3878 if (!d->ref.deref())
3883QRegion &QRegion::operator=(
const QRegion &r)
3886 if (!d->ref.deref())
3894
3895
3896QRegion QRegion::copy()
const
3899 auto x = std::make_unique<QRegionData>();
3900 x->ref.initializeOwned();
3902 x->qt_rgn =
new QRegionPrivate(*d->qt_rgn);
3904 x->qt_rgn =
new QRegionPrivate;
3905 if (!r.d->ref.deref())
3911bool QRegion::isEmpty()
const
3913 return d == &shared_empty || d->qt_rgn->numRects == 0;
3916bool QRegion::isNull()
const
3918 return d == &shared_empty || d->qt_rgn->numRects == 0;
3921bool QRegion::contains(
const QPoint &p)
const
3923 return PointInRegion(d->qt_rgn, p.x(), p.y());
3926bool QRegion::contains(
const QRect &r)
const
3928 return RectInRegion(d->qt_rgn, r.left(), r.top(), r.width(), r.height()) !=
RectangleOut;
3933void QRegion::translate(
int dx,
int dy)
3935 if ((dx == 0 && dy == 0) || isEmptyHelper(d->qt_rgn))
3939 OffsetRegion(*d->qt_rgn, dx, dy);
3942QRegion QRegion::united(
const QRegion &r)
const
3944 if (isEmptyHelper(d->qt_rgn))
3946 if (isEmptyHelper(r.d->qt_rgn))
3951 if (d->qt_rgn->contains(*r.d->qt_rgn)) {
3953 }
else if (r.d->qt_rgn->contains(*d->qt_rgn)) {
3955 }
else if (d->qt_rgn->canAppend(r.d->qt_rgn)) {
3956 QRegion result(*
this);
3958 result.d->qt_rgn->append(r.d->qt_rgn);
3960 }
else if (d->qt_rgn->canPrepend(r.d->qt_rgn)) {
3961 QRegion result(*
this);
3963 result.d->qt_rgn->prepend(r.d->qt_rgn);
3965 }
else if (EqualRegion(d->qt_rgn, r.d->qt_rgn)) {
3970 UnionRegion(d->qt_rgn, r.d->qt_rgn, *result.d->qt_rgn);
3975QRegion& QRegion::operator+=(
const QRegion &r)
3977 if (isEmptyHelper(d->qt_rgn))
3979 if (isEmptyHelper(r.d->qt_rgn))
3984 if (d->qt_rgn->contains(*r.d->qt_rgn)) {
3986 }
else if (r.d->qt_rgn->contains(*d->qt_rgn)) {
3988 }
else if (d->qt_rgn->canAppend(r.d->qt_rgn)) {
3990 d->qt_rgn->append(r.d->qt_rgn);
3992 }
else if (d->qt_rgn->canPrepend(r.d->qt_rgn)) {
3994 d->qt_rgn->prepend(r.d->qt_rgn);
3996 }
else if (EqualRegion(d->qt_rgn, r.d->qt_rgn)) {
4000 UnionRegion(d->qt_rgn, r.d->qt_rgn, *d->qt_rgn);
4005QRegion QRegion::united(
const QRect &r)
const
4007 if (isEmptyHelper(d->qt_rgn))
4012 if (d->qt_rgn->contains(r)) {
4014 }
else if (d->qt_rgn->within(r)) {
4016 }
else if (d->qt_rgn->numRects == 1 && d->qt_rgn->extents == r) {
4018 }
else if (d->qt_rgn->canAppend(&r)) {
4019 QRegion result(*
this);
4021 result.d->qt_rgn->append(&r);
4023 }
else if (d->qt_rgn->canPrepend(&r)) {
4024 QRegion result(*
this);
4026 result.d->qt_rgn->prepend(&r);
4031 QRegionPrivate rp(r);
4032 UnionRegion(d->qt_rgn, &rp, *result.d->qt_rgn);
4037QRegion& QRegion::operator+=(
const QRect &r)
4039 if (isEmptyHelper(d->qt_rgn))
4044 if (d->qt_rgn->contains(r)) {
4046 }
else if (d->qt_rgn->within(r)) {
4048 }
else if (d->qt_rgn->canAppend(&r)) {
4050 d->qt_rgn->append(&r);
4052 }
else if (d->qt_rgn->canPrepend(&r)) {
4054 d->qt_rgn->prepend(&r);
4056 }
else if (d->qt_rgn->numRects == 1 && d->qt_rgn->extents == r) {
4060 QRegionPrivate p(r);
4061 UnionRegion(d->qt_rgn, &p, *d->qt_rgn);
4066QRegion QRegion::intersected(
const QRegion &r)
const
4068 if (isEmptyHelper(d->qt_rgn) || isEmptyHelper(r.d->qt_rgn)
4069 || !
EXTENTCHECK(&d->qt_rgn->extents, &r.d->qt_rgn->extents))
4073 if (r.d->qt_rgn->contains(*d->qt_rgn))
4077 if (d->qt_rgn->contains(*r.d->qt_rgn))
4080 if (r.d->qt_rgn->numRects == 1 && d->qt_rgn->numRects == 1) {
4081 const QRect rect = qt_rect_intersect_normalized(r.d->qt_rgn->extents,
4082 d->qt_rgn->extents);
4083 return QRegion(rect);
4084 }
else if (r.d->qt_rgn->numRects == 1) {
4085 QRegion result(*
this);
4087 result.d->qt_rgn->intersect(r.d->qt_rgn->extents);
4089 }
else if (d->qt_rgn->numRects == 1) {
4092 result.d->qt_rgn->intersect(d->qt_rgn->extents);
4098 miRegionOp(*result.d->qt_rgn, d->qt_rgn, r.d->qt_rgn, miIntersectO,
nullptr,
nullptr);
4101
4102
4103
4104
4105
4106
4107 miSetExtents(*result.d->qt_rgn);
4111QRegion QRegion::intersected(
const QRect &r)
const
4113 if (isEmptyHelper(d->qt_rgn) || r.isEmpty()
4118 if (d->qt_rgn->within(r))
4122 if (d->qt_rgn->contains(r))
4125 if (d->qt_rgn->numRects == 1) {
4126 const QRect rect = qt_rect_intersect_normalized(d->qt_rgn->extents,
4128 return QRegion(rect);
4131 QRegion result(*
this);
4133 result.d->qt_rgn->intersect(r);
4137QRegion QRegion::subtracted(
const QRegion &r)
const
4139 if (isEmptyHelper(d->qt_rgn) || isEmptyHelper(r.d->qt_rgn))
4141 if (r.d->qt_rgn->contains(*d->qt_rgn))
4143 if (!
EXTENTCHECK(&d->qt_rgn->extents, &r.d->qt_rgn->extents))
4145 if (d == r.d || EqualRegion(d->qt_rgn, r.d->qt_rgn))
4148#ifdef QT_REGION_DEBUG
4149 d->qt_rgn->selfTest();
4150 r.d->qt_rgn->selfTest();
4155 SubtractRegion(d->qt_rgn, r.d->qt_rgn, *result.d->qt_rgn);
4156#ifdef QT_REGION_DEBUG
4157 result.d->qt_rgn->selfTest();
4162QRegion QRegion::xored(
const QRegion &r)
const
4164 if (isEmptyHelper(d->qt_rgn)) {
4166 }
else if (isEmptyHelper(r.d->qt_rgn)) {
4168 }
else if (!
EXTENTCHECK(&d->qt_rgn->extents, &r.d->qt_rgn->extents)) {
4170 }
else if (d == r.d || EqualRegion(d->qt_rgn, r.d->qt_rgn)) {
4175 XorRegion(d->qt_rgn, r.d->qt_rgn, *result.d->qt_rgn);
4180QRect QRegion::boundingRect()
const noexcept
4184 return d->qt_rgn->extents;
4188
4189
4190
4194 if (isEmptyHelper(region.d->qt_rgn) || !rect.isValid())
4198 static bool guard =
false;
4202 QRegion inner = region.d->qt_rgn->innerRect;
4203 Q_ASSERT((inner - region).isEmpty());
4207 for (
int i = 0; i < region.d->qt_rgn->numRects; ++i) {
4208 const QRect r = region.d->qt_rgn->rects.at(i);
4209 if (r.width() * r.height() > maxArea)
4210 maxArea = r.width() * r.height();
4213 if (maxArea > region.d->qt_rgn->innerArea) {
4214 qDebug() <<
"not largest rectangle" << region << region.d->qt_rgn->innerRect;
4216 Q_ASSERT(maxArea <= region.d->qt_rgn->innerArea);
4219 const QRect r1 = region.d->qt_rgn->innerRect;
4220 return (rect.left() >= r1.left() && rect.right() <= r1.right()
4221 && rect.top() >= r1.top() && rect.bottom() <= r1.bottom());
4224QRegion::const_iterator QRegion::begin()
const noexcept
4226 return d->qt_rgn ? d->qt_rgn->begin() :
nullptr;
4229QRegion::const_iterator QRegion::end()
const noexcept
4231 return d->qt_rgn ? d->qt_rgn->end() :
nullptr;
4237 qWarning(
"QRegion::setRects(): %s", what);
4240void QRegion::setRects(
const QRect *r,
int n)
4243 set_rects_warn(
"passing num != 0 when rects == nullptr is deprecated.");
4246 setRects(QSpan<
const QRect>(r, n));
4249void QRegion::setRects(QSpan<
const QRect> rects)
4251 const auto num =
int(rects.size());
4252 if (num != rects.size()) {
4253 set_rects_warn(
"span size exceeds INT_MAX, ignoring");
4258 if (!rects.data() || num == 0 || (num == 1 && rects.front().isEmpty()))
4263 d->qt_rgn->numRects = num;
4265 d->qt_rgn->extents = rects.front();
4266 d->qt_rgn->innerRect = rects.front();
4268 d->qt_rgn->rects.resize(num);
4274 for (
int i = 0; i < num; ++i) {
4275 const QRect &rect = rects[i];
4276 d->qt_rgn->rects[i] = rect;
4277 left = qMin(rect.left(), left);
4278 right = qMax(rect.right(), right);
4279 top = qMin(rect.top(), top);
4280 bottom = qMax(rect.bottom(), bottom);
4281 d->qt_rgn->updateInnerRect(rect);
4283 d->qt_rgn->extents = QRect(QPoint(left, top), QPoint(right, bottom));
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301QSpan<
const QRect> QRegion::rects()
const noexcept
4303 return {begin(), end()};
4306int QRegion::rectCount()
const noexcept
4308 return (d->qt_rgn ? d->qt_rgn->numRects : 0);
4311bool QRegion::operator==(
const QRegion &r)
const
4321 return EqualRegion(d->qt_rgn, r.d->qt_rgn);
4324bool QRegion::intersects(
const QRect &rect)
const
4326 if (isEmptyHelper(d->qt_rgn) || rect.isNull())
4329 const QRect r = rect.normalized();
4330 if (!rect_intersects(d->qt_rgn->extents, r))
4332 if (d->qt_rgn->numRects == 1)
4335 for (
const QRect &rect : *
this) {
4336 if (rect_intersects(r, rect))
4342#if defined(Q_OS_WIN) || defined(Q_QDOC)
4344static inline HRGN qt_RectToHRGN(
const QRect &rc)
4346 return CreateRectRgn(rc.left(), rc.top(), rc.right() + 1, rc.bottom() + 1);
4350
4351
4352
4353
4354HRGN QRegion::toHRGN()
const
4356 const int size = rectCount();
4360 HRGN resultRgn =
nullptr;
4361 const auto rects = begin();
4362 resultRgn = qt_RectToHRGN(rects[0]);
4363 for (
int i = 1; i < size; ++i) {
4364 HRGN tmpRgn = qt_RectToHRGN(rects[i]);
4365 int err = CombineRgn(resultRgn, resultRgn, tmpRgn, RGN_OR);
4367 qWarning(
"Error combining HRGNs.");
4368 DeleteObject(tmpRgn);
4374
4375
4376
4377
4378QRegion QRegion::fromHRGN(HRGN hrgn)
4380 DWORD regionDataSize = GetRegionData(hrgn, 0,
nullptr);
4381 if (regionDataSize == 0)
4384 auto regionData =
reinterpret_cast<LPRGNDATA>(malloc(regionDataSize));
4389 if (GetRegionData(hrgn, regionDataSize, regionData) == regionDataSize) {
4390 auto pRect =
reinterpret_cast<LPRECT>(regionData->Buffer);
4391 for (DWORD i = 0; i < regionData->rdh.nCount; ++i)
4392 region += QRect(pRect[i].left, pRect[i].top,
4393 pRect[i].right - pRect[i].left,
4394 pRect[i].bottom - pRect[i].top);
\inmodule QtCore\reentrant
Combined button and popup list for selecting options.
static bool canMergeFromBelow(const QRect *top, const QRect *bottom, const QRect *nextToTop, const QRect *nextToBottom)
static void miSubtractO(QRegionPrivate &dest, const QRect *r1, const QRect *r1End, const QRect *r2, const QRect *r2End, int y1, int y2)
Q_DECLARE_TYPEINFO(Segment, Q_PRIMITIVE_TYPE)
static bool isEmptyHelper(const QRegionPrivate *preg)
static void OffsetRegion(QRegionPrivate ®ion, int x, int y)
static bool canMergeFromLeft(const QRect *right, const QRect *left)
static QRect qt_rect_intersect_normalized(const QRect &r1, const QRect &r2)
static Q_DECL_COLD_FUNCTION void set_rects_warn(const char *what)
static bool canMergeFromRight(const QRect *left, const QRect *right)
static bool EqualRegion(const QRegionPrivate *r1, const QRegionPrivate *r2)
static void XorRegion(QRegionPrivate *sra, QRegionPrivate *srb, QRegionPrivate &dest)
static int miCoalesce(QRegionPrivate &dest, int prevStart, int curStart)
static void CreateETandAET(int count, const QPoint *pts, EdgeTable *ET, EdgeTableEntry *AET, EdgeTableEntry *pETEs, ScanLineListBlock *pSLLBlock)
static bool PointInRegion(QRegionPrivate *pRegion, int x, int y)
#define EXTENTCHECK(r1, r2)
static void flushRow(const QRegionSpan *spans, int y, int numSpans, QRegionPrivate *reg, int *lastRow, int *extendTo, bool *needsExtend)
#define QRGN_SETPTARRAY_ALT
#define EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
static QRegionPrivate * PolygonRegion(const QPoint *Pts, int Count, int rule)
static bool RectInRegion(QRegionPrivate *region, int rx, int ry, uint rwidth, uint rheight)
static int InsertionSort(EdgeTableEntry *AET)
#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2)
QRegionPrivate * qt_bitmapToRegion(const QBitmap &bitmap)
QDebug operator<<(QDebug s, const QRegion &r)
static void loadAET(EdgeTableEntry *AET, EdgeTableEntry *ETEs)
static void miUnionO(QRegionPrivate &dest, const QRect *r1, const QRect *r1End, const QRect *r2, const QRect *r2End, int y1, int y2)
#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres)
#define MEMCHECK(dest, rect, firstrect)
void(*) OverlapFunc(QRegionPrivate &dest, const QRect *r1, const QRect *r1End, const QRect *r2, const QRect *r2End, int y1, int y2)
#define BRESINCRPGONSTRUCT(bres)
static void miSubtractNonO1(QRegionPrivate &dest, const QRect *r, const QRect *rEnd, int y1, int y2)
bool rect_intersects(const QRect &r1, const QRect &r2)
Q_DECLARE_TYPEINFO(QRegionSpan, Q_PRIMITIVE_TYPE)
static void UnionRectWithRegion(const QRect *rect, const QRegionPrivate *source, QRegionPrivate &dest)
static void UnionRegion(const QRegionPrivate *reg1, const QRegionPrivate *reg2, QRegionPrivate &dest)
static void PtsToRegion(int numFullPtBlocks, int iCurPtBlock, POINTBLOCK *FirstPtBlock, QRegionPrivate *reg)
static void computeWAET(EdgeTableEntry *AET)
#define QRGN_SETPTARRAY_WIND
static void FreeStorage(ScanLineListBlock *pSLLBlock)
static void miSetExtents(QRegionPrivate &dest)
static void InsertEdgeInET(EdgeTable *ET, EdgeTableEntry *ETE, int scanline, ScanLineListBlock **SLLBlock, int *iSLLBlock)
#define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET)
static void SubtractRegion(QRegionPrivate *regM, QRegionPrivate *regS, QRegionPrivate &dest)
void(*) NonOverlapFunc(QRegionPrivate &dest, const QRect *r, const QRect *rEnd, int y1, int y2)
static void miUnionNonO(QRegionPrivate &dest, const QRect *r, const QRect *rEnd, int y1, int y2)
#define BRESINCRPGON(d, minval, m, m1, incr1, incr2)
Q_GUI_EXPORT bool qt_region_strictContains(const QRegion ®ion, const QRect &rect)
static void miIntersectO(QRegionPrivate &dest, const QRect *r1, const QRect *r1End, const QRect *r2, const QRect *r2End, int y1, int y2)
static void miRegionOp(QRegionPrivate &dest, const QRegionPrivate *reg1, const QRegionPrivate *reg2, OverlapFunc overlapFunc, NonOverlapFunc nonOverlap1Func, NonOverlapFunc nonOverlap2Func)
void prepend(const QRect *r)
bool canPrepend(const QRegionPrivate *r) const
constexpr QRegionPrivate()
bool mergeFromAbove(QRect *bottom, const QRect *top, const QRect *nextToBottom, const QRect *nextToTop)
const QRect * end() const noexcept
const QRect * begin() const noexcept
bool canAppend(const QRegionPrivate *r) const
bool within(const QRect &r1) const
bool contains(const QRect &r2) const
void append(const QRegionPrivate *r)
bool mergeFromRight(QRect *left, const QRect *right)
void updateInnerRect(const QRect &rect)
bool contains(const QRegionPrivate &r) const
void append(const QRect *r)
bool canAppend(const QRect *r) const
QRegionPrivate(const QRect &r)
bool mergeFromLeft(QRect *left, const QRect *right)
bool canPrepend(const QRect *r) const
bool mergeFromBelow(QRect *top, const QRect *bottom, const QRect *nextToTop, const QRect *nextToBottom)
void prepend(const QRegionPrivate *r)
void intersect(const QRect &r)
QRegionSpan(int x1_, int x2_)
struct _EdgeTableEntry * nextWETE
struct _EdgeTableEntry * back
struct _EdgeTableEntry * next
char data[NUMPTSTOBUFFER *sizeof(QPoint)]
struct _POINTBLOCK * next
struct _ScanLineListBlock * next
ScanLineList SLLs[SLLSPERBLOCK]
EdgeTableEntry * edgelist
struct _ScanLineList * next