Krita Source Code Documentation
Loading...
Searching...
No Matches
KisWrappedRect Struct Reference

#include <kis_wrapped_rect.h>

+ Inheritance diagram for KisWrappedRect:

Public Types

enum  { TOPLEFT = 0 , TOPRIGHT , BOTTOMLEFT , BOTTOMRIGHT }
 

Public Member Functions

QRect bottomLeft () const
 
QRect bottomRight () const
 
bool isSplit () const
 
 KisWrappedRect (const QRect &rc, const QRect &wrapRect, WrapAroundAxis wrapAxis)
 
QRect originalRect () const
 
QRect topLeft () const
 
QRect topRight () const
 
QRect wrapRect () const
 

Static Public Member Functions

static QRect clipToWrapRect (QRect rc, const QRect &wrapRect, WrapAroundAxis wrapAxis)
 
static QVector< QRect > multiplyWrappedRect (const QRect &rc, const QRect &wrapRect, const QRect &limitRect, WrapAroundAxis wrapAxis)
 
static QVector< QPoint > normalizationOriginsForRect (const QRect &rc, const QRect &wrapRect, WrapAroundAxis wrapAxis)
 
static QPoint ptToWrappedPt (QPoint pt, const QRect &wrapRect, WrapAroundAxis wrapAxis)
 
static bool wrapRectContains (const QRect &rc, const QRect &wrapRect, WrapAroundAxis wrapAxis)
 
static bool wrapRectContains (QPoint pt, const QRect &wrapRect, WrapAroundAxis wrapAxis)
 
static int xToWrappedX (int x, const QRect &wrapRect, WrapAroundAxis wrapAxis)
 
static int yToWrappedY (int y, const QRect &wrapRect, WrapAroundAxis wrapAxis)
 

Private Attributes

QRect m_originalRect
 
QRect m_wrapRect
 

Detailed Description

Definition at line 16 of file kis_wrapped_rect.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
TOPLEFT 
TOPRIGHT 
BOTTOMLEFT 
BOTTOMRIGHT 

Definition at line 174 of file kis_wrapped_rect.h.

Constructor & Destructor Documentation

◆ KisWrappedRect()

KisWrappedRect::KisWrappedRect ( const QRect & rc,
const QRect & wrapRect,
WrapAroundAxis wrapAxis )
inline

Definition at line 181 of file kis_wrapped_rect.h.

184 {
185 if (wrapRectContains(rc, wrapRect, wrapAxis)) {
186 append(rc);
187 } else {
188 int x = xToWrappedX(rc.x(), wrapRect, wrapAxis);
189 int y = yToWrappedY(rc.y(), wrapRect, wrapAxis);
190 int w = wrapAxis != WRAPAROUND_VERTICAL ? qMin(rc.width(), wrapRect.width()) : rc.width();
191 int h = wrapAxis != WRAPAROUND_HORIZONTAL ? qMin(rc.height(), wrapRect.height()) : rc.height();
192
193 // we ensure that the top/left of the rect belongs to the
194 // visible rectangle
195 Q_ASSERT(wrapRectContains(QPoint(x,y), wrapRect, wrapAxis));
196
197 QRect newRect(x, y, w, h);
198
199 // We add empty QRects here because a "splitRect" is expected to contain exactly 4 rects.
200 // Functions such as KisPaintDeviceWrappedStrategy::readBytes() and
201 // KisWrappedLineIteratorBase() will not work properly (read: crash) otherwise.
202 append(clipToWrapRect(newRect, wrapRect, wrapAxis)); // tl
203 append(wrapAxis != WRAPAROUND_VERTICAL ?
204 clipToWrapRect(newRect.translated(-wrapRect.width(), 0), wrapRect, wrapAxis) : QRect()); // tr
205 append(wrapAxis != WRAPAROUND_HORIZONTAL ?
206 clipToWrapRect(newRect.translated(0, -wrapRect.height()), wrapRect, wrapAxis) : QRect()); // bl
207 append(wrapAxis == WRAPAROUND_BOTH ?
208 clipToWrapRect(newRect.translated(-wrapRect.width(), -wrapRect.height()), wrapRect, wrapAxis) : QRect()); // br
209 }
210 }
@ WRAPAROUND_HORIZONTAL
@ WRAPAROUND_BOTH
@ WRAPAROUND_VERTICAL
static int yToWrappedY(int y, const QRect &wrapRect, WrapAroundAxis wrapAxis)
static bool wrapRectContains(const QRect &rc, const QRect &wrapRect, WrapAroundAxis wrapAxis)
static QRect clipToWrapRect(QRect rc, const QRect &wrapRect, WrapAroundAxis wrapAxis)
QRect wrapRect() const
static int xToWrappedX(int x, const QRect &wrapRect, WrapAroundAxis wrapAxis)

References clipToWrapRect(), WRAPAROUND_BOTH, WRAPAROUND_HORIZONTAL, WRAPAROUND_VERTICAL, wrapRect(), wrapRectContains(), xToWrappedX(), and yToWrappedY().

Member Function Documentation

◆ bottomLeft()

QRect KisWrappedRect::bottomLeft ( ) const
inline

Definition at line 229 of file kis_wrapped_rect.h.

229 {
230 return this->at(BOTTOMLEFT);
231 }

References BOTTOMLEFT.

◆ bottomRight()

QRect KisWrappedRect::bottomRight ( ) const
inline

Definition at line 233 of file kis_wrapped_rect.h.

233 {
234 return this->at(BOTTOMRIGHT);
235 }

References BOTTOMRIGHT.

◆ clipToWrapRect()

static QRect KisWrappedRect::clipToWrapRect ( QRect rc,
const QRect & wrapRect,
WrapAroundAxis wrapAxis )
inlinestatic

Definition at line 41 of file kis_wrapped_rect.h.

41 {
42 switch (wrapAxis) {
44 {
45 if (rc.left() < wrapRect.left()) {
46 rc.setLeft(wrapRect.left());
47 }
48 if (rc.right() > wrapRect.right()) {
49 rc.setRight(wrapRect.right());
50 }
51 return rc;
52 }
54 {
55 if (rc.top() < wrapRect.top()) {
56 rc.setTop(wrapRect.top());
57 }
58 if (rc.bottom() > wrapRect.bottom()) {
59 rc.setBottom(wrapRect.bottom());
60 }
61 return rc;
62 }
63 default /*WRAPAROUND_BOTH*/:
64 return rc & wrapRect;
65 }
66 }

References WRAPAROUND_HORIZONTAL, WRAPAROUND_VERTICAL, and wrapRect().

◆ isSplit()

bool KisWrappedRect::isSplit ( ) const
inline

Definition at line 212 of file kis_wrapped_rect.h.

212 {
213 int size = this->size();
214
215 // we can either split or not split only
216 Q_ASSERT(size == 1 || size == 4);
217
218 return size > 1;
219 }
int size(const Forest< T > &forest)
Definition KisForest.h:1232

◆ multiplyWrappedRect()

static QVector< QRect > KisWrappedRect::multiplyWrappedRect ( const QRect & rc,
const QRect & wrapRect,
const QRect & limitRect,
WrapAroundAxis wrapAxis )
inlinestatic

Definition at line 134 of file kis_wrapped_rect.h.

137 {
138
139 QVector<QRect> result;
140
141 const int firstCol =
142 wrapAxis != WRAPAROUND_VERTICAL ? qFloor(qreal(limitRect.x() - wrapRect.x()) / wrapRect.width()) : 0;
143 const int firstRow =
144 wrapAxis != WRAPAROUND_HORIZONTAL ? qFloor(qreal(limitRect.y() - wrapRect.y()) / wrapRect.height()) : 0;
145
146 const int lastCol =
147 wrapAxis != WRAPAROUND_VERTICAL ? qFloor(qreal(limitRect.right() - wrapRect.x()) / wrapRect.width()) : 0;
148 const int lastRow =
149 wrapAxis != WRAPAROUND_HORIZONTAL ? qFloor(qreal(limitRect.bottom() - wrapRect.y()) / wrapRect.height()) : 0;
150
151 KisWrappedRect wrappedRect(rc, wrapRect, wrapAxis);
152
153 Q_FOREACH (const QRect &rect, wrappedRect) {
154 if (rect.isEmpty()) continue;
155
156 for (int y = firstRow; y <= lastRow; y++) {
157 for (int x = firstCol; x <= lastCol; x++) {
158 const QPoint offset(x * wrapRect.width(), y * wrapRect.height());
159 const QRect currentRect =
160 rect.translated(offset + wrapRect.topLeft()) & limitRect;
161
162 if (!currentRect.isEmpty()) {
163 result << currentRect;
164 }
165 }
166 }
167 }
168
169 return result;
170 }

References WRAPAROUND_HORIZONTAL, WRAPAROUND_VERTICAL, and wrapRect().

◆ normalizationOriginsForRect()

static QVector< QPoint > KisWrappedRect::normalizationOriginsForRect ( const QRect & rc,
const QRect & wrapRect,
WrapAroundAxis wrapAxis )
inlinestatic

Return origins at which we should paint rc with crop rect set to wrapRect, so that the final image would look "wrapped".

Definition at line 93 of file kis_wrapped_rect.h.

93 {
94 QVector<QPoint> result;
95
96 if (wrapRectContains(rc, wrapRect, wrapAxis)) {
97 result.append(rc.topLeft());
98 }
99 else {
100 int x = xToWrappedX(rc.x(), wrapRect, wrapAxis);
101 int y = yToWrappedY(rc.y(), wrapRect, wrapAxis);
102 int w = wrapAxis != WRAPAROUND_VERTICAL ? qMin(rc.width(), wrapRect.width()) : rc.width();
103 int h = wrapAxis != WRAPAROUND_HORIZONTAL ? qMin(rc.height(), wrapRect.height()) : rc.height();
104
105 // we ensure that the top/left of the rect belongs to the
106 // visible rectangle
107 Q_ASSERT(wrapRectContains(QPoint(x,y), wrapRect, wrapAxis));
108
109 QRect newRect(x, y, w, h);
110
111 if (!clipToWrapRect(newRect, wrapRect, wrapAxis).isEmpty()) {
112 result.append(QPoint(x, y)); // tl
113 }
114
115 if (wrapAxis != WRAPAROUND_VERTICAL &&
116 !clipToWrapRect(newRect.translated(-wrapRect.width(), 0), wrapRect, wrapAxis).isEmpty()) { // tr
117 result.append(QPoint(x - wrapRect.width(), y));
118 }
119
120 if (wrapAxis != WRAPAROUND_HORIZONTAL &&
121 !clipToWrapRect(newRect.translated(0, -wrapRect.height()), wrapRect, wrapAxis).isEmpty()) { // bl
122 result.append(QPoint(x, y - wrapRect.height()));
123 }
124
125 if (wrapAxis == WRAPAROUND_BOTH &&
126 !clipToWrapRect(newRect.translated(-wrapRect.width(), -wrapRect.height()), wrapRect, wrapAxis).isEmpty()) { // br
127 result.append(QPoint(x - wrapRect.width(), y - wrapRect.height()));
128 }
129 }
130
131 return result;
132 }

References clipToWrapRect(), WRAPAROUND_BOTH, WRAPAROUND_HORIZONTAL, WRAPAROUND_VERTICAL, wrapRect(), wrapRectContains(), xToWrappedX(), and yToWrappedY().

◆ originalRect()

QRect KisWrappedRect::originalRect ( ) const
inline

Definition at line 241 of file kis_wrapped_rect.h.

241 {
242 return m_originalRect;
243 }

References m_originalRect.

◆ ptToWrappedPt()

static QPoint KisWrappedRect::ptToWrappedPt ( QPoint pt,
const QRect & wrapRect,
WrapAroundAxis wrapAxis )
inlinestatic

Definition at line 35 of file kis_wrapped_rect.h.

35 {
36 pt.rx() = xToWrappedX(pt.x(), wrapRect, wrapAxis);
37 pt.ry() = yToWrappedY(pt.y(), wrapRect, wrapAxis);
38 return pt;
39 }

References wrapRect(), xToWrappedX(), and yToWrappedY().

◆ topLeft()

QRect KisWrappedRect::topLeft ( ) const
inline

Definition at line 221 of file kis_wrapped_rect.h.

221 {
222 return this->at(TOPLEFT);
223 }

References TOPLEFT.

◆ topRight()

QRect KisWrappedRect::topRight ( ) const
inline

Definition at line 225 of file kis_wrapped_rect.h.

225 {
226 return this->at(TOPRIGHT);
227 }

References TOPRIGHT.

◆ wrapRect()

QRect KisWrappedRect::wrapRect ( ) const
inline

Definition at line 237 of file kis_wrapped_rect.h.

237 {
238 return m_wrapRect;
239 }

References m_wrapRect.

◆ wrapRectContains() [1/2]

static bool KisWrappedRect::wrapRectContains ( const QRect & rc,
const QRect & wrapRect,
WrapAroundAxis wrapAxis )
inlinestatic

Definition at line 68 of file kis_wrapped_rect.h.

68 {
69 switch (wrapAxis) {
71 return (rc.left() >= wrapRect.left() && rc.right() <= wrapRect.right());
73 return (rc.top() >= wrapRect.top() && rc.bottom() <= wrapRect.bottom());
74 default /*WRAPAROUND_BOTH*/:
75 return wrapRect.contains(rc);
76 }
77 }

References WRAPAROUND_HORIZONTAL, WRAPAROUND_VERTICAL, and wrapRect().

◆ wrapRectContains() [2/2]

static bool KisWrappedRect::wrapRectContains ( QPoint pt,
const QRect & wrapRect,
WrapAroundAxis wrapAxis )
inlinestatic

Definition at line 78 of file kis_wrapped_rect.h.

78 {
79 switch (wrapAxis) {
81 return (pt.x() >= wrapRect.left() && pt.x() <= wrapRect.right());
83 return (pt.y() >= wrapRect.top() && pt.y() <= wrapRect.bottom());
84 default /*WRAPAROUND_BOTH*/:
85 return wrapRect.contains(pt);
86 }
87 }

References WRAPAROUND_HORIZONTAL, WRAPAROUND_VERTICAL, and wrapRect().

◆ xToWrappedX()

static int KisWrappedRect::xToWrappedX ( int x,
const QRect & wrapRect,
WrapAroundAxis wrapAxis )
inlinestatic

Definition at line 17 of file kis_wrapped_rect.h.

17 {
18 if (wrapAxis == WRAPAROUND_VERTICAL) {
19 return x;
20 }
21 x = (x - wrapRect.x()) % wrapRect.width();
22 if (x < 0) x += wrapRect.width();
23 return x;
24 }

References WRAPAROUND_VERTICAL, and wrapRect().

◆ yToWrappedY()

static int KisWrappedRect::yToWrappedY ( int y,
const QRect & wrapRect,
WrapAroundAxis wrapAxis )
inlinestatic

Definition at line 26 of file kis_wrapped_rect.h.

26 {
27 if (wrapAxis == WRAPAROUND_HORIZONTAL) {
28 return y;
29 }
30 y = (y - wrapRect.y()) % wrapRect.height();
31 if (y < 0) y += wrapRect.height();
32 return y;
33 }

References WRAPAROUND_HORIZONTAL, and wrapRect().

Member Data Documentation

◆ m_originalRect

QRect KisWrappedRect::m_originalRect
private

Definition at line 247 of file kis_wrapped_rect.h.

◆ m_wrapRect

QRect KisWrappedRect::m_wrapRect
private

Definition at line 246 of file kis_wrapped_rect.h.


The documentation for this struct was generated from the following file: