42 #ifndef QPOLYGONCLIPPER_P_H 43 #define QPOLYGONCLIPPER_P_H 56 #include "private/qdatabuffer_p.h" 62 template <
typename InType,
typename OutType,
typename CastType>
class QPolygonClipper 93 t.y =
static_cast<CastType
>(p2.y + (
x1 - p2.x) * dy);
101 qreal dy = (p1.y - p2.y) /
qreal(p1.x - p2.x);
103 t.y =
static_cast<CastType
>(p2.y + (
x2 - p2.x) * dy);
111 qreal dx = (p1.x - p2.x) /
qreal(p1.y - p2.y);
112 t.x =
static_cast<CastType
>(p2.x + (
y1 - p2.y) * dx);
121 qreal dx = (p1.x - p2.x) /
qreal(p1.y - p2.y);
122 t.x =
static_cast<CastType
>(p2.x + (
y2 - p2.y) * dx);
128 void clipPolygon(
const InType *inPoints,
int inCount, OutType **outPoints,
int *outCount,
129 bool closePolygon =
true)
146 bool doLeft =
false, doRight =
false, doTop =
false, doBottom =
false;
148 for (
int i=0; i<inCount; ++i) {
162 if (doLeft && clipped->
size() > 1) {
169 lastPos = source->
size() - 1;
174 if (source->
at(0).x >=
x1)
175 clipped->
add(source->
at(0));
177 for (
int i=start; i<inCount; ++i) {
178 const OutType &cpt = source->
at(i);
179 const OutType &ppt = source->
at(lastPos);
188 }
else if (ppt.x >=
x1) {
195 if (doRight && clipped->
size() > 1) {
202 lastPos = source->
size() - 1;
207 if (source->
at(0).x <=
x2)
208 clipped->
add(source->
at(0));
210 for (
int i=start; i<source->
size(); ++i) {
211 const OutType &cpt = source->
at(i);
212 const OutType &ppt = source->
at(lastPos);
221 }
else if (ppt.x <=
x2) {
230 if (doTop && clipped->
size() > 1) {
237 lastPos = source->
size() - 1;
242 if (source->
at(0).y >=
y1)
243 clipped->
add(source->
at(0));
245 for (
int i=start; i<source->
size(); ++i) {
246 const OutType &cpt = source->
at(i);
247 const OutType &ppt = source->
at(lastPos);
256 }
else if (ppt.y >=
y1) {
264 if (doBottom && clipped->
size() > 1) {
271 lastPos = source->
size() - 1;
276 if (source->
at(0).y <=
y2)
277 clipped->
add(source->
at(0));
279 for (
int i=start; i<source->
size(); ++i) {
280 const OutType &cpt = source->
at(i);
281 const OutType &ppt = source->
at(lastPos);
290 }
else if (ppt.y <=
y2) {
297 if (closePolygon && clipped->
size() > 0) {
299 if (clipped->
at(0).x != clipped->
at(clipped->
size()-1).x ||
300 clipped->
at(0).y != clipped->
at(clipped->
size()-1).y) {
301 OutType ot = clipped->
at(0);
305 *outCount = clipped->
size();
306 *outPoints = clipped->
data();
317 #endif // QPOLYGONCLIPPER_P_H void setBoundingRect(const QRect bounds)
QDataBuffer< OutType > buffer1
#define QT_END_NAMESPACE
This macro expands to.
QDataBuffer< OutType > buffer2
int width() const
Returns the width of the rectangle.
int height() const
Returns the height of the rectangle.
#define QT_BEGIN_NAMESPACE
This macro expands to.
void clipPolygon(const InType *inPoints, int inCount, OutType **outPoints, int *outCount, bool closePolygon=true)
OutType intersectBottom(const OutType &p1, const OutType &p2)
OutType intersectRight(const OutType &p1, const OutType &p2)
int y() const
Returns the y-coordinate of the rectangle's top edge.
int x() const
Returns the x-coordinate of the rectangle's left edge.
The QPoint class defines a point in the plane using integer precision.
The QRect class defines a rectangle in the plane using integer precision.
OutType intersectLeft(const OutType &p1, const OutType &p2)
OutType intersectTop(const OutType &p1, const OutType &p2)