Skip to content

Commit

Permalink
small improovement for getResampledBySpacing (#6361)
Browse files Browse the repository at this point in the history
* small improovement for getResampledBySpacing

To avoid bigger gaps at the end of the resampled polyline, adding almost a full spacing will help adding a rather small last space than a big one. The last point is replaced anyway.

* fix as discussed
  • Loading branch information
jonasfehr authored and ofTheo committed Aug 27, 2019
1 parent 561a298 commit 459145e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libs/openFrameworks/graphics/ofPolyline.inl
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,15 @@ ofPolyline_<T> ofPolyline_<T>::getResampledBySpacing(float spacing) const {
if(spacing==0 || size() == 0) return *this;
ofPolyline_ poly;
float totalLength = getPerimeter();
for(float f=0; f<totalLength; f += spacing) {
float f=0;
for(f=0; f<=totalLength; f += spacing) {
poly.lineTo(getPointAtLength(f));
}

if(!isClosed()) {
if(poly.size() > 0) poly.points.back() = points.back();
if( f != totalLength ){
poly.lineTo(points.back());
}
poly.setClosed(false);
} else {
poly.setClosed(true);
Expand Down

0 comments on commit 459145e

Please sign in to comment.