Qt 4.8
Public Functions | Private Functions | List of all members
QIntersectionFinder Class Reference

Public Functions

bool hasIntersections (const QPathSegments &a, const QPathSegments &b) const
 
void produceIntersections (QPathSegments &segments)
 

Private Functions

bool linesIntersect (const QLineF &a, const QLineF &b) const
 

Detailed Description

Definition at line 104 of file qpathclipper.cpp.

Functions

◆ hasIntersections()

bool QIntersectionFinder::hasIntersections ( const QPathSegments a,
const QPathSegments b 
) const

Definition at line 181 of file qpathclipper.cpp.

Referenced by QPathClipper::contains(), and QPathClipper::intersect().

182 {
183  if (a.segments() == 0 || b.segments() == 0)
184  return false;
185 
186  const QRectF &rb0 = b.elementBounds(0);
187 
188  qreal minX = rb0.left();
189  qreal minY = rb0.top();
190  qreal maxX = rb0.right();
191  qreal maxY = rb0.bottom();
192 
193  for (int i = 1; i < b.segments(); ++i) {
194  const QRectF &r = b.elementBounds(i);
195  minX = qMin(minX, r.left());
196  minY = qMin(minY, r.top());
197  maxX = qMax(maxX, r.right());
198  maxY = qMax(maxY, r.bottom());
199  }
200 
201  QRectF rb(minX, minY, maxX - minX, maxY - minY);
202 
203  for (int i = 0; i < a.segments(); ++i) {
204  const QRectF &r1 = a.elementBounds(i);
205 
206  if (r1.left() > rb.right() || rb.left() > r1.right())
207  continue;
208  if (r1.top() > rb.bottom() || rb.top() > r1.bottom())
209  continue;
210 
211  for (int j = 0; j < b.segments(); ++j) {
212  const QRectF &r2 = b.elementBounds(j);
213 
214  if (r1.left() > r2.right() || r2.left() > r1.right())
215  continue;
216  if (r1.top() > r2.bottom() || r2.top() > r1.bottom())
217  continue;
218 
219  if (linesIntersect(a.lineAt(i), b.lineAt(j)))
220  return true;
221  }
222  }
223 
224  return false;
225 }
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int segments() const
const QLineF lineAt(int index) const
bool linesIntersect(const QLineF &a, const QLineF &b) const
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
const QRectF & elementBounds(int index) const

◆ linesIntersect()

bool QIntersectionFinder::linesIntersect ( const QLineF a,
const QLineF b 
) const
private

Definition at line 114 of file qpathclipper.cpp.

115 {
116  const QPointF p1 = a.p1();
117  const QPointF p2 = a.p2();
118 
119  const QPointF q1 = b.p1();
120  const QPointF q2 = b.p2();
121 
122  if (comparePoints(p1, p2) || comparePoints(q1, q2))
123  return false;
124 
125  const bool p1_equals_q1 = comparePoints(p1, q1);
126  const bool p2_equals_q2 = comparePoints(p2, q2);
127 
128  if (p1_equals_q1 && p2_equals_q2)
129  return true;
130 
131  const bool p1_equals_q2 = comparePoints(p1, q2);
132  const bool p2_equals_q1 = comparePoints(p2, q1);
133 
134  if (p1_equals_q2 && p2_equals_q1)
135  return true;
136 
137  const QPointF pDelta = p2 - p1;
138  const QPointF qDelta = q2 - q1;
139 
140  const qreal par = pDelta.x() * qDelta.y() - pDelta.y() * qDelta.x();
141 
142  if (qFuzzyIsNull(par)) {
143  const QPointF normal(-pDelta.y(), pDelta.x());
144 
145  // coinciding?
146  if (qFuzzyIsNull(dot(normal, q1 - p1))) {
147  const qreal dp = dot(pDelta, pDelta);
148 
149  const qreal tq1 = dot(pDelta, q1 - p1);
150  const qreal tq2 = dot(pDelta, q2 - p1);
151 
152  if ((tq1 > 0 && tq1 < dp) || (tq2 > 0 && tq2 < dp))
153  return true;
154 
155  const qreal dq = dot(qDelta, qDelta);
156 
157  const qreal tp1 = dot(qDelta, p1 - q1);
158  const qreal tp2 = dot(qDelta, p2 - q1);
159 
160  if ((tp1 > 0 && tp1 < dq) || (tp2 > 0 && tp2 < dq))
161  return true;
162  }
163 
164  return false;
165  }
166 
167  const qreal invPar = 1 / par;
168 
169  const qreal tp = (qDelta.y() * (q1.x() - p1.x()) -
170  qDelta.x() * (q1.y() - p1.y())) * invPar;
171 
172  if (tp < 0 || tp > 1)
173  return false;
174 
175  const qreal tq = (pDelta.y() * (q1.x() - p1.x()) -
176  pDelta.x() * (q1.y() - p1.y())) * invPar;
177 
178  return tq >= 0 && tq <= 1;
179 }
double qreal
Definition: qglobal.h:1193
QPointF p1() const
Returns the line&#39;s start point.
Definition: qline.h:314
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QPointF p2() const
Returns the line&#39;s end point.
Definition: qline.h:319
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
static bool comparePoints(const QPointF &a, const QPointF &b)
static qreal dot(const QPointF &a, const QPointF &b)

◆ produceIntersections()

void QIntersectionFinder::produceIntersections ( QPathSegments segments)

Definition at line 594 of file qpathclipper.cpp.

Referenced by QWingedEdge::intersectAndAdd().

595 {
596  SegmentTree tree(segments);
597 
598  for (int i = 0; i < segments.segments(); ++i)
599  tree.produceIntersections(i);
600 }
int segments() const

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