Qt 4.8
Classes | Public Functions | Properties | List of all members
QPathSegments Class Reference

#include <qpathclipper_p.h>

Classes

struct  Intersection
 
struct  Segment
 

Public Functions

void addIntersection (int index, const Intersection &intersection)
 
void addPath (const QPainterPath &path)
 
int addPoint (const QPointF &point)
 
const QRectFelementBounds (int index) const
 
const IntersectionintersectionAt (int index) const
 
int intersections () const
 
const QLineF lineAt (int index) const
 
void mergePoints ()
 
int pathId (int index) const
 
const QPointFpointAt (int vertex) const
 
int points () const
 
 QPathSegments (int reserve)
 
const SegmentsegmentAt (int index) const
 
int segments () const
 
void setPath (const QPainterPath &path)
 

Properties

QDataBuffer< Intersectionm_intersections
 
int m_pathId
 
QDataBuffer< QPointFm_points
 
QDataBuffer< Segmentm_segments
 

Detailed Description

Definition at line 166 of file qpathclipper_p.h.

Constructors and Destructors

◆ QPathSegments()

QPathSegments::QPathSegments ( int  reserve)
inline

Definition at line 348 of file qpathclipper_p.h.

348  :
349  m_points(reserve),
350  m_segments(reserve),
351  m_intersections(reserve)
352 {
353 }
QDataBuffer< QPointF > m_points
QDataBuffer< Segment > m_segments
QDataBuffer< Intersection > m_intersections

Functions

◆ addIntersection()

void QPathSegments::addIntersection ( int  index,
const Intersection intersection 
)
inline

Definition at line 411 of file qpathclipper_p.h.

412 {
413  m_intersections << intersection;
414 
415  Segment &segment = m_segments.at(index);
416  if (segment.intersection < 0) {
417  segment.intersection = m_intersections.size() - 1;
418  } else {
419  Intersection *isect = &m_intersections.at(segment.intersection);
420 
421  while (isect->next != 0)
422  isect += isect->next;
423 
424  isect->next = (m_intersections.size() - 1) - (isect - m_intersections.data());
425  }
426 }
QDataBuffer< Segment > m_segments
quint16 index
QDataBuffer< Intersection > m_intersections

◆ addPath()

void QPathSegments::addPath ( const QPainterPath path)

Definition at line 927 of file qpathclipper.cpp.

Referenced by QWingedEdge::QWingedEdge().

928 {
929  int firstSegment = m_segments.size();
930 
931  bool hasMoveTo = false;
932  int lastMoveTo = 0;
933  int last = 0;
934  for (int i = 0; i < path.elementCount(); ++i) {
935  int current = m_points.size();
936 
937  QPointF currentPoint;
939  currentPoint = path.elementAt(i+2);
940  else
941  currentPoint = path.elementAt(i);
942 
943  if (i > 0 && comparePoints(m_points.at(lastMoveTo), currentPoint))
944  current = lastMoveTo;
945  else
946  m_points << currentPoint;
947 
948  switch (path.elementAt(i).type) {
950  if (hasMoveTo && last != lastMoveTo && !comparePoints(m_points.at(last), m_points.at(lastMoveTo)))
951  m_segments << Segment(m_pathId, last, lastMoveTo);
952  hasMoveTo = true;
953  last = lastMoveTo = current;
954  break;
956  m_segments << Segment(m_pathId, last, current);
957  last = current;
958  break;
960  {
961  QBezier bezier = QBezier::fromPoints(m_points.at(last), path.elementAt(i), path.elementAt(i+1), path.elementAt(i+2));
962  if (isLine(bezier)) {
963  m_segments << Segment(m_pathId, last, current);
964  } else {
965  QRectF bounds = bezier.bounds();
966 
967  // threshold based on similar algorithm as in qtriangulatingstroker.cpp
968  int threshold = qMin<float>(64, qMax(bounds.width(), bounds.height()) * (2 * qreal(3.14) / 6));
969 
970  if (threshold < 3) threshold = 3;
971  qreal one_over_threshold_minus_1 = qreal(1) / (threshold - 1);
972 
973  for (int t = 1; t < threshold - 1; ++t) {
974  currentPoint = bezier.pointAt(t * one_over_threshold_minus_1);
975 
976  int index = m_points.size();
977  m_segments << Segment(m_pathId, last, index);
978  last = index;
979 
980  m_points << currentPoint;
981  }
982 
983  m_segments << Segment(m_pathId, last, current);
984  }
985  }
986  last = current;
987  i += 2;
988  break;
989  default:
990  Q_ASSERT(false);
991  break;
992  }
993  }
994 
995  if (hasMoveTo && last != lastMoveTo && !comparePoints(m_points.at(last), m_points.at(lastMoveTo)))
996  m_segments << Segment(m_pathId, last, lastMoveTo);
997 
998  for (int i = firstSegment; i < m_segments.size(); ++i) {
999  const QLineF line = lineAt(i);
1000 
1001  qreal x1 = line.p1().x();
1002  qreal y1 = line.p1().y();
1003  qreal x2 = line.p2().x();
1004  qreal y2 = line.p2().y();
1005 
1006  if (x2 < x1)
1007  qSwap(x1, x2);
1008  if (y2 < y1)
1009  qSwap(y1, y2);
1010 
1011  m_segments.at(i).bounds = QRectF(x1, y1, x2 - x1, y2 - y1);
1012  }
1013 
1014  ++m_pathId;
1015 }
ElementType type
the type of element
Definition: qpainterpath.h:81
double qreal
Definition: qglobal.h:1193
const QLineF lineAt(int index) const
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
QPointF pointAt(qreal t) const
Definition: qbezier_p.h:163
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Definition: qpainterpath.h:402
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QDataBuffer< QPointF > m_points
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition: qbezier.cpp:71
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
QDataBuffer< Segment > m_segments
Type & at(int i)
Definition: qdatabuffer_p.h:86
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
QRectF bounds() const
Definition: qbezier.cpp:223
static bool isLine(const QBezier &bezier)
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
quint16 index
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397
static bool comparePoints(const QPointF &a, const QPointF &b)
int size() const
Definition: qdatabuffer_p.h:83

◆ addPoint()

int QPathSegments::addPoint ( const QPointF point)
inline

Definition at line 370 of file qpathclipper_p.h.

371 {
372  m_points << point;
373  return m_points.size() - 1;
374 }
QDataBuffer< QPointF > m_points
int size() const
Definition: qdatabuffer_p.h:83

◆ elementBounds()

const QRectF & QPathSegments::elementBounds ( int  index) const
inline

Definition at line 387 of file qpathclipper_p.h.

Referenced by QIntersectionFinder::hasIntersections().

388 {
389  return m_segments.at(index).bounds;
390 }
QDataBuffer< Segment > m_segments
quint16 index

◆ intersectionAt()

const QPathSegments::Intersection * QPathSegments::intersectionAt ( int  index) const
inline

Definition at line 397 of file qpathclipper_p.h.

398 {
399  const int intersection = m_segments.at(index).intersection;
400  if (intersection < 0)
401  return 0;
402  else
403  return &m_intersections.at(intersection);
404 }
QDataBuffer< Segment > m_segments
quint16 index
QDataBuffer< Intersection > m_intersections

◆ intersections()

int QPathSegments::intersections ( ) const
inline

Definition at line 406 of file qpathclipper_p.h.

407 {
408  return m_intersections.size();
409 }
QDataBuffer< Intersection > m_intersections

◆ lineAt()

const QLineF QPathSegments::lineAt ( int  index) const
inline

Definition at line 381 of file qpathclipper_p.h.

Referenced by QIntersectionFinder::hasIntersections().

382 {
383  const Segment &segment = m_segments.at(index);
384  return QLineF(m_points.at(segment.va), m_points.at(segment.vb));
385 }
QDataBuffer< QPointF > m_points
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
QDataBuffer< Segment > m_segments
Type & at(int i)
Definition: qdatabuffer_p.h:86
quint16 index

◆ mergePoints()

void QPathSegments::mergePoints ( )

Definition at line 770 of file qpathclipper.cpp.

771 {
772  QKdPointTree tree(*this);
773 
774  if (tree.rootNode()) {
775  QDataBuffer<QPointF> mergedPoints(points());
776  QDataBuffer<int> pointIndices(points());
777 
778  for (int i = 0; i < points(); ++i) {
779  QKdPointFinder finder(i, *this, tree);
780  QT_PREPEND_NAMESPACE(qTraverseKdPointTree<QKdPointFinder>)(*tree.rootNode(), finder);
781 
782  Q_ASSERT(finder.result() != -1);
783 
784  if (finder.result() >= mergedPoints.size())
785  mergedPoints << m_points.at(i);
786 
787  pointIndices << finder.result();
788  }
789 
790  for (int i = 0; i < m_segments.size(); ++i) {
791  m_segments.at(i).va = pointIndices.at(m_segments.at(i).va);
792  m_segments.at(i).vb = pointIndices.at(m_segments.at(i).vb);
793  }
794 
795  for (int i = 0; i < m_intersections.size(); ++i)
796  m_intersections.at(i).vertex = pointIndices.at(m_intersections.at(i).vertex);
797 
798  m_points.swap(mergedPoints);
799  }
800 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QDataBuffer< QPointF > m_points
QDataBuffer< Segment > m_segments
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
Type & at(int i)
Definition: qdatabuffer_p.h:86
void swap(QDataBuffer< Type > &other)
int points() const
QDataBuffer< Intersection > m_intersections

◆ pathId()

int QPathSegments::pathId ( int  index) const
inline

Definition at line 392 of file qpathclipper_p.h.

393 {
394  return m_segments.at(index).path;
395 }
QDataBuffer< Segment > m_segments
quint16 index

◆ pointAt()

const QPointF & QPathSegments::pointAt ( int  vertex) const
inline

Definition at line 365 of file qpathclipper_p.h.

Referenced by QKdPointFinder::QKdPointFinder().

366 {
367  return m_points.at(i);
368 }
QDataBuffer< QPointF > m_points
Type & at(int i)
Definition: qdatabuffer_p.h:86

◆ points()

int QPathSegments::points ( ) const
inline

Definition at line 360 of file qpathclipper_p.h.

361 {
362  return m_points.size();
363 }
QDataBuffer< QPointF > m_points
int size() const
Definition: qdatabuffer_p.h:83

◆ segmentAt()

const QPathSegments::Segment & QPathSegments::segmentAt ( int  index) const
inline

Definition at line 376 of file qpathclipper_p.h.

377 {
378  return m_segments.at(index);
379 }
QDataBuffer< Segment > m_segments
quint16 index

◆ segments()

int QPathSegments::segments ( ) const
inline

Definition at line 355 of file qpathclipper_p.h.

Referenced by QIntersectionFinder::hasIntersections(), and QIntersectionFinder::produceIntersections().

356 {
357  return m_segments.size();
358 }
QDataBuffer< Segment > m_segments

◆ setPath()

void QPathSegments::setPath ( const QPainterPath path)

Definition at line 916 of file qpathclipper.cpp.

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

917 {
918  m_points.reset();
919  m_intersections.reset();
920  m_segments.reset();
921 
922  m_pathId = 0;
923 
924  addPath(path);
925 }
QDataBuffer< QPointF > m_points
QDataBuffer< Segment > m_segments
void reset()
Definition: qdatabuffer_p.h:79
QDataBuffer< Intersection > m_intersections
void addPath(const QPainterPath &path)

Properties

◆ m_intersections

QDataBuffer<Intersection> QPathSegments::m_intersections
private

Definition at line 227 of file qpathclipper_p.h.

Referenced by addIntersection(), intersectionAt(), and intersections().

◆ m_pathId

int QPathSegments::m_pathId
private

Definition at line 229 of file qpathclipper_p.h.

◆ m_points

QDataBuffer<QPointF> QPathSegments::m_points
private

Definition at line 225 of file qpathclipper_p.h.

Referenced by addPoint(), lineAt(), pointAt(), and points().

◆ m_segments

QDataBuffer<Segment> QPathSegments::m_segments
private

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