Skip to content

Commit 05fa4e0

Browse files
committed
fixed bug in polyline shorten and extend not reseting the lines attribute
1 parent d0083cd commit 05fa4e0

File tree

3 files changed

+20
-44
lines changed

3 files changed

+20
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
204204
* Fixed bug in `compas.datastructures.Mesh.insert_vertex`.
205205
* Fixed bug in `compas.geometry.angle_vectors_signed`.
206206
* Changed `compas.artists.MeshArtist` default colors.
207+
* Fixed bug in `compas.geometry.curves.Polyline` shorten and extend methods.
207208

208209
### Removed
209210

src/compas/geometry/curves/polyline.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,10 @@ def extend(self, length):
578578
"""
579579
try:
580580
start, end = length
581-
self.points[0] = self.points[0] + self.lines[0].vector.unitized().scaled(-start)
581+
self[0] = self[0] + self.lines[0].vector.unitized().scaled(-start)
582582
except TypeError:
583583
start = end = length
584-
self.points[-1] = self.points[-1] + self.lines[-1].vector.unitized().scaled(end)
584+
self[-1] = self[-1] + self.lines[-1].vector.unitized().scaled(end)
585585

586586
def extended(self, length):
587587
"""Returns a copy of this polyline extended by a given length.
@@ -643,6 +643,7 @@ def shorten(self, length):
643643
else:
644644
self.points[-1] = line.start + line.vector.unitized().scaled(total_length - end)
645645
break
646+
self._lines = None
646647

647648
def shortened(self, length):
648649
"""Returns a copy of this polyline shortened by a given length.

tests/compas/geometry/test_curves_polyline.py

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -432,54 +432,28 @@ def test_polyline_tangent_at_point(coords, input, expected):
432432

433433

434434
@pytest.mark.parametrize(
435-
"coords,input,expected",
435+
"coords,input,expected,length",
436436
[
437-
(
438-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
439-
1.5,
440-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 3.5, 0]],
441-
),
442-
(
443-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
444-
-2.5,
445-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, -0.5, 0]],
446-
),
447-
(
448-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
449-
(2, 2),
450-
[[-2, 0, 0], [1, 0, 0], [2, 0, 0], [2, 4, 0]],
451-
),
452-
(
453-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
454-
(2, 0),
455-
[[-2, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
456-
),
437+
([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], 1.5, [[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 3.5, 0]], 5.5),
438+
([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], -2.5, [[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, -0.5, 0]], 2.5),
439+
([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], (2, 2), [[-2, 0, 0], [1, 0, 0], [2, 0, 0], [2, 4, 0]], 8),
440+
([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], (2, 0), [[-2, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], 6),
457441
],
458442
)
459-
def test_polyline_extend(coords, input, expected):
460-
assert expected == Polyline(coords).extended(input)
443+
def test_polyline_extend(coords, input, expected, length):
444+
polyline = Polyline(coords).extended(input)
445+
assert expected == polyline and length == polyline.length
461446

462447

463448
@pytest.mark.parametrize(
464-
"coords,input,expected",
449+
"coords,input,expected,length",
465450
[
466-
(
467-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
468-
0.5,
469-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 1.5, 0]],
470-
),
471-
(
472-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
473-
2,
474-
[[0, 0, 0], [1, 0, 0], [2, 0, 0]],
475-
),
476-
(
477-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
478-
(0.5, 2.5),
479-
[[0.5, 0, 0], [1, 0, 0], [1.5, 0, 0]],
480-
),
481-
([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], (1, 2), [[1, 0, 0], [2, 0, 0]]),
451+
([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], 0.5, [[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 1.5, 0]], 3.5),
452+
([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], 2, [[0, 0, 0], [1, 0, 0], [2, 0, 0]], 2),
453+
([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], (0.5, 2.5), [[0.5, 0, 0], [1, 0, 0], [1.5, 0, 0]], 1),
454+
([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], (1, 2), [[1, 0, 0], [2, 0, 0]], 1),
482455
],
483456
)
484-
def test_polyline_shortened(coords, input, expected):
485-
assert expected == Polyline(coords).shortened(input)
457+
def test_polyline_shortened(coords, input, expected, length):
458+
polyline = Polyline(coords).shortened(input)
459+
assert expected == polyline and length == polyline.length

0 commit comments

Comments
 (0)