Skip to content

Commit 836c109

Browse files
authored
Merge pull request #804 from mattiskoh/polyline_fixes
Polyline fixes
2 parents be55894 + 3db6617 commit 836c109

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## Unreleased
1010

11+
1112
### Added
1213

1314
* Added Python 3.9 support.
@@ -19,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1920
### Changed
2021

2122
* Fixed box scaling.
23+
* Fixed a bug in `Polyline.divide_polyline_by_length` related to a floating point rounding error.
2224

2325
### Removed
2426

src/compas/geometry/primitives/polyline.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def transform(self, T):
266266
def split_at_corners(self, angle_threshold):
267267
"""Splits a polyline at corners larger than the given angle_threshold
268268
269-
Parameters:
269+
Parameters
270270
-----------
271271
angle_threshold : float
272272
In radians.
@@ -311,7 +311,7 @@ def split_at_corners(self, angle_threshold):
311311
def tangent_at_point_on_polyline(self, point):
312312
"""Calculates the tangent vector of a point on a polyline
313313
314-
Parameters:
314+
Parameters
315315
-----------
316316
point: :class:`compas.geometry.Point`
317317
@@ -327,7 +327,7 @@ def tangent_at_point_on_polyline(self, point):
327327
def divide_polyline(self, num_segments):
328328
"""Divide a polyline in equal segments.
329329
330-
Parameters:
330+
Parameters
331331
-----------
332332
num_segments : int
333333
@@ -340,16 +340,19 @@ def divide_polyline(self, num_segments):
340340

341341
return self.divide_polyline_by_length(segment_length, False)
342342

343-
def divide_polyline_by_length(self, length, strict=True):
344-
"""Splits a polyline in segments of a given length
343+
def divide_polyline_by_length(self, length, strict=True, tol=1e-06):
344+
"""Splits a polyline in segments of a given length.
345345
346-
Parameters:
346+
Parameters
347347
-----------
348348
length : float
349349
350350
strict : bool
351351
If set to ``False``, the remainder segment will be added even if it is smaller than the desired length
352352
353+
tol : float
354+
floating point error tolerance
355+
353356
Returns
354357
-------
355358
list
@@ -379,7 +382,7 @@ def divide_polyline_by_length(self, length, strict=True):
379382

380383
if strict is False and not self.is_closed() and len(division_pts) < num_pts+1:
381384
division_pts.append(new_polyline.points[-1])
382-
elif strict is False and division_pts[-1] != self.points[-1]:
385+
elif strict is False and division_pts[-1].distance_to_point(self.points[-1]) > tol:
383386
division_pts.append(self.points[-1])
384387

385388
return division_pts

0 commit comments

Comments
 (0)