19 Index startIndex, endIndex;
20 if (getIndexLimitedToMapRange(gridMap, start, end, startIndex)
21 && getIndexLimitedToMapRange(gridMap, end, start, endIndex))
22 initialize(gridMap, startIndex, endIndex);
27 initialize(gridMap, start, end);
52 return (index_ != other.
index_).any();
55 const Index& LineIterator::operator *()
const 62 numerator_ += numeratorAdd_;
63 if (numerator_ >= denominator_) {
64 numerator_ -= denominator_;
74 bool LineIterator::isPastEnd()
const 76 return iCell_ >= nCells_;
86 bufferSize_ = gridMap.
getSize();
88 initializeIterationParameters();
97 Vector direction = (end - start).normalized();
98 while (!gridMap.
getIndex(newStart, index)) {
99 newStart += (gridMap.
getResolution() - std::numeric_limits<double>::epsilon()) * direction;
100 if ((end - newStart).norm() < gridMap.
getResolution() - std::numeric_limits<double>::epsilon())
106 void LineIterator::initializeIterationParameters()
113 const Size delta = (unwrappedEnd - unwrappedStart).abs();
115 if (unwrappedEnd.x() >= unwrappedStart.x()) {
121 increment1_.x() = -1;
122 increment2_.x() = -1;
125 if (unwrappedEnd.y() >= unwrappedStart.y()) {
131 increment1_.y() = -1;
132 increment2_.y() = -1;
135 if (delta.x() >= delta.y()) {
139 denominator_ = delta.x();
140 numerator_ = delta.x() / 2;
141 numeratorAdd_ = delta.y();
142 nCells_ = delta.x() + 1;
147 denominator_ = delta.y();
148 numerator_ = delta.y() / 2;
149 numeratorAdd_ = delta.x();
150 nCells_ = delta.y() + 1;
const Length & getLength() const
unsigned int iCell_
Current cell number.
const Index & getStartIndex() const
unsigned int nCells_
Number of cells in the line.
bool getPosition(const Index &index, Position &position) const
Index getIndexFromBufferIndex(const Index &bufferIndex, const Size &bufferSize, const Index &bufferStartIndex)
Index end_
Ending index of the line.
Length mapLength_
Map information needed to get position from iterator.
double getResolution() const
Size increment1_
Helper variables for Bresenham Line Drawing algorithm.
Index start_
Starting index of the line.
Index getBufferIndexFromIndex(const Index &index, const Size &bufferSize, const Index &bufferStartIndex)
bool getIndex(const Position &position, Index &index) const
const Size & getSize() const
Index index_
Current index.