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

Classes

struct  Node
 

Public Types

enum  Traversal { TraverseBoth, TraverseLeft, TraverseRight, TraverseNone }
 

Public Functions

int build (int begin, int end, int depth=0)
 
int nextId ()
 
 QKdPointTree (const QPathSegments &segments)
 
NoderootNode ()
 

Properties

int m_id
 
QDataBuffer< Nodem_nodes
 
int m_rootNode
 
const QPathSegmentsm_segments
 

Detailed Description

Definition at line 602 of file qpathclipper.cpp.

Enumerations

◆ Traversal

Enumerator
TraverseBoth 
TraverseLeft 
TraverseRight 
TraverseNone 

Definition at line 605 of file qpathclipper.cpp.

Constructors and Destructors

◆ QKdPointTree()

QKdPointTree::QKdPointTree ( const QPathSegments segments)
inline

Definition at line 620 of file qpathclipper.cpp.

621  : m_segments(&segments)
623  , m_id(0)
624  {
625  m_nodes.resize(m_segments->points());
626 
627  for (int i = 0; i < m_nodes.size(); ++i) {
628  m_nodes.at(i).point = i;
629  m_nodes.at(i).id = -1;
630  }
631 
632  m_rootNode = build(0, m_nodes.size());
633  }
QDataBuffer< Node > m_nodes
const QPathSegments * m_segments
int build(int begin, int end, int depth=0)
int points() const

Functions

◆ build()

int QKdPointTree::build ( int  begin,
int  end,
int  depth = 0 
)

Definition at line 677 of file qpathclipper.cpp.

678 {
679  Q_ASSERT(end > begin);
680 
681  const qreal pivot = component(m_segments->pointAt(m_nodes.at(begin).point), depth & 1);
682 
683  int first = begin + 1;
684  int last = end - 1;
685 
686  while (first <= last) {
687  const qreal value = component(m_segments->pointAt(m_nodes.at(first).point), depth & 1);
688 
689  if (value < pivot)
690  ++first;
691  else {
692  qSwap(m_nodes.at(first), m_nodes.at(last));
693  --last;
694  }
695  }
696 
697  qSwap(m_nodes.at(last), m_nodes.at(begin));
698 
699  if (last > begin)
700  m_nodes.at(last).left = &m_nodes.at(build(begin, last, depth + 1));
701  else
702  m_nodes.at(last).left = 0;
703 
704  if (last + 1 < end)
705  m_nodes.at(last).right = &m_nodes.at(build(last + 1, end, depth + 1));
706  else
707  m_nodes.at(last).right = 0;
708 
709  return last;
710 }
double qreal
Definition: qglobal.h:1193
QDataBuffer< Node > m_nodes
const QPathSegments * m_segments
int build(int begin, int end, int depth=0)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static qreal component(const QPointF &point, unsigned int i)
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
const QPointF & pointAt(int vertex) const
static const KeyPair *const end

◆ nextId()

int QKdPointTree::nextId ( )
inline

Definition at line 642 of file qpathclipper.cpp.

643  {
644  return m_id++;
645  }

◆ rootNode()

Node* QKdPointTree::rootNode ( )
inline

Definition at line 637 of file qpathclipper.cpp.

Referenced by QPathSegments::mergePoints().

638  {
639  return &m_nodes.at(m_rootNode);
640  }
QDataBuffer< Node > m_nodes

Properties

◆ m_id

int QKdPointTree::m_id
private

Definition at line 652 of file qpathclipper.cpp.

◆ m_nodes

QDataBuffer<Node> QKdPointTree::m_nodes
private

Definition at line 649 of file qpathclipper.cpp.

◆ m_rootNode

int QKdPointTree::m_rootNode
private

Definition at line 651 of file qpathclipper.cpp.

◆ m_segments

const QPathSegments* QKdPointTree::m_segments
private

Definition at line 648 of file qpathclipper.cpp.


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