Qt 4.8
Public Functions | Public Variables | List of all members
QTessellatorPrivate::Edge Struct Reference

Public Functions

 Edge (const Vertices &v, int _edge)
 
bool intersect (const Edge &other, Q27Dot5 *y, bool *det_positive) const
 
bool isLeftOf (const Edge &other, Q27Dot5 y) const
 
Q27Dot5 positionAt (Q27Dot5 y) const
 

Public Variables

int edge
 
bool free
 
bool intersect_left
 
bool intersect_right
 
bool mark
 
const Vertexv0
 
const Vertexv1
 
signed int winding: 8
 
Q27Dot5 y_left
 
Q27Dot5 y_right
 

Detailed Description

Definition at line 111 of file qtessellator.cpp.

Constructors and Destructors

◆ Edge()

QTessellatorPrivate::Edge::Edge ( const Vertices v,
int  _edge 
)

Definition at line 241 of file qtessellator.cpp.

242 {
243  this->edge = edge;
245  mark = false;
246  free = false;
247 
248  v0 = vertices[edge];
249  v1 = vertices.next(v0);
250 
251  Q_ASSERT(v0->y != v1->y);
252 
253  if (v0->y > v1->y) {
254  qSwap(v0, v1);
255  winding = -1;
256  } else {
257  winding = 1;
258  }
259  y_left = y_right = v0->y;
260 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181

Functions

◆ intersect()

bool QTessellatorPrivate::Edge::intersect ( const Edge other,
Q27Dot5 y,
bool *  det_positive 
) const

Definition at line 284 of file qtessellator.cpp.

Referenced by QTessellatorPrivate::addIntersection().

285 {
286  qint64 a1 = v1->y - v0->y;
287  qint64 b1 = v0->x - v1->x;
288 
289  qint64 a2 = other.v1->y - other.v0->y;
290  qint64 b2 = other.v0->x - other.v1->x;
291 
292  qint64 det = a1 * b2 - a2 * b1;
293  if (det == 0)
294  return false;
295 
296  qint64 c1 = qint64(v1->x) * v0->y - qint64(v0->x) * v1->y;
297 
298  qint64 r3 = a1 * other.v0->x + b1 * other.v0->y + c1;
299  qint64 r4 = a1 * other.v1->x + b1 * other.v1->y + c1;
300 
301  // Check signs of r3 and r4. If both point 3 and point 4 lie on
302  // same side of line 1, the line segments do not intersect.
303  QDEBUG() << " " << r3 << r4;
304  if (r3 != 0 && r4 != 0 && sameSign( r3, r4 ))
305  return false;
306 
307  qint64 c2 = qint64(other.v1->x) * other.v0->y - qint64(other.v0->x) * other.v1->y;
308 
309  qint64 r1 = a2 * v0->x + b2 * v0->y + c2;
310  qint64 r2 = a2 * v1->x + b2 * v1->y + c2;
311 
312  // Check signs of r1 and r2. If both point 1 and point 2 lie
313  // on same side of second line segment, the line segments do not intersect.
314  QDEBUG() << " " << r1 << r2;
315  if (r1 != 0 && r2 != 0 && sameSign( r1, r2 ))
316  return false;
317 
318  // The det/2 is to get rounding instead of truncating. It
319  // is added or subtracted to the numerator, depending upon the
320  // sign of the numerator.
321  qint64 offset = det < 0 ? -det : det;
322  offset >>= 1;
323 
324  qint64 num = a2 * c1 - a1 * c2;
325  *y = ( num < 0 ? num - offset : num + offset ) / det;
326 
327  *det_positive = (det > 0);
328 
329  return true;
330 }
#define QDEBUG
__int64 qint64
Definition: qglobal.h:942
static bool sameSign(qint64 a, qint64 b)

◆ isLeftOf()

bool QTessellatorPrivate::Edge::isLeftOf ( const Edge other,
Q27Dot5  y 
) const

Definition at line 334 of file qtessellator.cpp.

Referenced by QTessellatorPrivate::EdgeSorter::operator()().

335 {
336 // QDEBUG() << "isLeftOf" << edge << other.edge << y;
337  qint64 a1 = v1->y - v0->y;
338  qint64 b1 = v0->x - v1->x;
339  qint64 a2 = other.v1->y - other.v0->y;
340  qint64 b2 = other.v0->x - other.v1->x;
341 
342  qint64 c2 = qint64(other.v1->x) * other.v0->y - qint64(other.v0->x) * other.v1->y;
343 
344  qint64 det = a1 * b2 - a2 * b1;
345  if (det == 0) {
346  // lines are parallel. Only need to check side of one point
347  // fixed ordering for coincident edges
348  qint64 r1 = a2 * v0->x + b2 * v0->y + c2;
349 // QDEBUG() << "det = 0" << r1;
350  if (r1 == 0)
351  return edge < other.edge;
352  return (r1 < 0);
353  }
354 
355  // not parallel, need to find the y coordinate of the intersection point
356  qint64 c1 = qint64(v1->x) * v0->y - qint64(v0->x) * v1->y;
357 
358  qint64 offset = det < 0 ? -det : det;
359  offset >>= 1;
360 
361  qint64 num = a2 * c1 - a1 * c2;
362  qint64 yi = ( num < 0 ? num - offset : num + offset ) / det;
363 // QDEBUG() << " num=" << num << "offset=" << offset << "det=" << det;
364 
365  return ((yi > y) ^ (det < 0));
366 }
__int64 qint64
Definition: qglobal.h:942

◆ positionAt()

Q27Dot5 QTessellatorPrivate::Edge::positionAt ( Q27Dot5  y) const

Definition at line 379 of file qtessellator.cpp.

Referenced by QTessellatorPrivate::processIntersections().

380 {
381  if (y == v0->y)
382  return v0->x;
383  else if (y == v1->y)
384  return v1->x;
385 
386  qint64 d = v1->x - v0->x;
387  return (v0->x + d*(y - v0->y)/(v1->y-v0->y));
388 }
double d
Definition: qnumeric_p.h:62
__int64 qint64
Definition: qglobal.h:942

Properties

◆ edge

int QTessellatorPrivate::Edge::edge

◆ free

bool QTessellatorPrivate::Edge::free

Definition at line 120 of file qtessellator.cpp.

Referenced by QTessellatorPrivate::Scanline::removeAt().

◆ intersect_left

bool QTessellatorPrivate::Edge::intersect_left

◆ intersect_right

bool QTessellatorPrivate::Edge::intersect_right

◆ mark

bool QTessellatorPrivate::Edge::mark

◆ v0

const Vertex* QTessellatorPrivate::Edge::v0

◆ v1

const Vertex* QTessellatorPrivate::Edge::v1

Definition at line 115 of file qtessellator.cpp.

Referenced by intersect(), and isLeftOf().

◆ winding

signed int QTessellatorPrivate::Edge::winding

Definition at line 118 of file qtessellator.cpp.

Referenced by QTessellatorPrivate::emitEdges().

◆ y_left

Q27Dot5 QTessellatorPrivate::Edge::y_left

Definition at line 116 of file qtessellator.cpp.

Referenced by QTessellatorPrivate::emitEdges().

◆ y_right

Q27Dot5 QTessellatorPrivate::Edge::y_right

Definition at line 117 of file qtessellator.cpp.

Referenced by QTessellatorPrivate::emitEdges().


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