diff --git a/CHANGELOG.md b/CHANGELOG.md index 428a801106d..2e71105f9b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CORE ---- + +### Graphics +- ofPolyline::removeVertex( ... ) added. + ### utils - ofXML - provided access to the underlying pugi::xml_node method "getParent()" diff --git a/libs/openFrameworks/graphics/ofPolyline.h b/libs/openFrameworks/graphics/ofPolyline.h index a02089c6fb7..f09054a795e 100644 --- a/libs/openFrameworks/graphics/ofPolyline.h +++ b/libs/openFrameworks/graphics/ofPolyline.h @@ -108,6 +108,15 @@ class ofPolyline_ { void insertVertex(const T &p, int index); void insertVertex(float x, float y, float z, int index); + + /// \brief Remove a vertex at a given index. + /// + /// This function print an error and ignore the input if the index is + /// invalid. When a vertex is removed, the internal caches are cleared. + /// + /// \param index The index of the vertex to remove. + void removeVertex(int index); + /// \brief Resize the number of points in the ofPolyline to the value /// passed in. void resize(size_t size); diff --git a/libs/openFrameworks/graphics/ofPolyline.inl b/libs/openFrameworks/graphics/ofPolyline.inl index 10adf11fba6..1ec02f90d8c 100644 --- a/libs/openFrameworks/graphics/ofPolyline.inl +++ b/libs/openFrameworks/graphics/ofPolyline.inl @@ -93,6 +93,19 @@ void ofPolyline_::insertVertex(float x, float y, float z, int index) { } +//---------------------------------------------------------- +template +void ofPolyline_::removeVertex(int index) { + if(index >= points.size()){ + ofLogError("ofPolyline") << "removeVertex(): ignoring out of range index " << index << ", number of vertices is" << points.size(); + }else{ + curveVertices.clear(); + points.erase(points.begin()+index); + flagHasChanged(); + } +} + + //---------------------------------------------------------- template size_t ofPolyline_::size() const {