Skip to content
Snippets Groups Projects
Commit be033bcf authored by Tom Fischer's avatar Tom Fischer
Browse files

added method Polyline::removePoint()

parent 98535439
No related branches found
No related tags found
No related merge requests found
......@@ -105,6 +105,38 @@ void Polyline::insertPoint(size_t pos, size_t pnt_id)
}
}
void Polyline::removePoint(std::size_t pos)
{
if (pos >= _ply_pnt_ids.size())
return;
_ply_pnt_ids.erase(_ply_pnt_ids.begin()+pos);
if (pos == _ply_pnt_ids.size()-1) {
_length.erase(_length.begin()+pos);
return;
}
const size_t n_ply_pnt_ids(_ply_pnt_ids.size());
if (pos == 0) {
double seg_length(_length[0]);
for (unsigned k(0); k<n_ply_pnt_ids; k++) {
_length[k] = _length[k+1] - seg_length;
}
_length.pop_back();
} else {
const double len_seg0(_length[pos] - _length[pos-1]);
const double len_seg1(_length[pos+1] - _length[pos]);
_length.erase(_length.begin()+pos);
const double len_new_seg(sqrt(MathLib::sqrDist(_ply_pnts[_ply_pnt_ids[pos-1]], _ply_pnts[pos])));
double seg_length_diff(len_new_seg - len_seg0 - len_seg1);
for (unsigned k(pos); k<n_ply_pnt_ids; k++) {
_length[k] += seg_length_diff;
}
}
}
size_t Polyline::getNumberOfPoints() const
{
return _ply_pnt_ids.size();
......
......@@ -80,6 +80,13 @@ public:
*/
virtual void insertPoint(std::size_t pos, std::size_t pnt_id);
/**
* Method removes a point from the polyline. The connecting line segments will
* be removed and the length of the polyline will be changed.
* @param pos a valid position within the polyline
*/
virtual void removePoint(std::size_t pos);
/**
* Closes a polyline by adding a line segment that connects start- and end-point.
* \param ply A Polyline containing at least three points.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment