19 Index startIndex, endIndex;
20 if (getIndexLimitedToMapRange(gridMap, start, end, startIndex)
21 && getIndexLimitedToMapRange(gridMap, end, start, endIndex)) {
22 initialize(gridMap, startIndex, endIndex);
25 throw std::invalid_argument(
"Failed to construct LineIterator.");
31 initialize(gridMap, start, end);
56 return (index_ != other.
index_).any();
59 const Index& LineIterator::operator *()
const 66 numerator_ += numeratorAdd_;
67 if (numerator_ >= denominator_) {
68 numerator_ -= denominator_;
78 bool LineIterator::isPastEnd()
const 80 return iCell_ >= nCells_;
90 bufferSize_ = gridMap.
getSize();
92 initializeIterationParameters();
101 Vector direction = (end - start).normalized();
102 while (!gridMap.
getIndex(newStart, index)) {
103 newStart += (gridMap.
getResolution() - std::numeric_limits<double>::epsilon()) * direction;
104 if ((end - newStart).norm() < gridMap.
getResolution() - std::numeric_limits<double>::epsilon())
110 void LineIterator::initializeIterationParameters()
117 const Size delta = (unwrappedEnd - unwrappedStart).abs();
119 if (unwrappedEnd.x() >= unwrappedStart.x()) {
125 increment1_.x() = -1;
126 increment2_.x() = -1;
129 if (unwrappedEnd.y() >= unwrappedStart.y()) {
135 increment1_.y() = -1;
136 increment2_.y() = -1;
139 if (delta.x() >= delta.y()) {
143 denominator_ = delta.x();
144 numerator_ = delta.x() / 2;
145 numeratorAdd_ = delta.y();
146 nCells_ = delta.x() + 1;
151 denominator_ = delta.y();
152 numerator_ = delta.y() / 2;
153 numeratorAdd_ = delta.x();
154 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.