Skip to content

Commit 3497094

Browse files
committed
Merge remote-tracking branch 'origin/main' into main
2 parents a462ca4 + 636bccb commit 3497094

File tree

3 files changed

+20
-42
lines changed

3 files changed

+20
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
232232
* Fixed bug in `compas.geometry.angle_vectors_signed`.
233233
* Fixed bug in `compas.geometry.Polyline.split_at_corners` where angles were sometimes wrongly calculated.
234234
* Changed `compas.artists.MeshArtist` default colors.
235+
* Fixed bug in `compas.geometry.curves.Polyline` shorten and extend methods.
235236
* Changed internal _plane storage of the `compas.datastructures.Halfface` from `_plane[u][v][w]` to `_plane[u][v][fkey]`
236237
* Fixed `SyntaxError` when importing COMPAS in GHPython.
237238

src/compas/geometry/curves/polyline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,11 @@ def extend(self, length):
637637
try:
638638
start, end = length
639639
self.points[0] = self.points[0] + self.lines[0].vector.unitized().scaled(-start)
640+
self._lines = None
640641
except TypeError:
641642
start = end = length
642643
self.points[-1] = self.points[-1] + self.lines[-1].vector.unitized().scaled(end)
644+
self._lines = None
643645

644646
def extended(self, length):
645647
"""Returns a copy of this polyline extended by a given length.
@@ -701,6 +703,7 @@ def shorten(self, length):
701703
else:
702704
self.points[-1] = line.start + line.vector.unitized().scaled(total_length - end)
703705
break
706+
self._lines = None
704707

705708
def shortened(self, length):
706709
"""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
@@ -460,54 +460,28 @@ def test_polyline_parameter_at(input, expected):
460460

461461

462462
@pytest.mark.parametrize(
463-
"coords,input,expected",
463+
"coords,input,expected,length",
464464
[
465-
(
466-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
467-
1.5,
468-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 3.5, 0]],
469-
),
470-
(
471-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
472-
-2.5,
473-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, -0.5, 0]],
474-
),
475-
(
476-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
477-
(2, 2),
478-
[[-2, 0, 0], [1, 0, 0], [2, 0, 0], [2, 4, 0]],
479-
),
480-
(
481-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
482-
(2, 0),
483-
[[-2, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
484-
),
465+
([[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),
466+
([[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),
467+
([[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),
468+
([[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),
485469
],
486470
)
487-
def test_polyline_extend(coords, input, expected):
488-
assert expected == Polyline(coords).extended(input)
471+
def test_polyline_extend(coords, input, expected, length):
472+
polyline = Polyline(coords).extended(input)
473+
assert expected == polyline and length == polyline.length
489474

490475

491476
@pytest.mark.parametrize(
492-
"coords,input,expected",
477+
"coords,input,expected,length",
493478
[
494-
(
495-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
496-
0.5,
497-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 1.5, 0]],
498-
),
499-
(
500-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
501-
2,
502-
[[0, 0, 0], [1, 0, 0], [2, 0, 0]],
503-
),
504-
(
505-
[[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]],
506-
(0.5, 2.5),
507-
[[0.5, 0, 0], [1, 0, 0], [1.5, 0, 0]],
508-
),
509-
([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], (1, 2), [[1, 0, 0], [2, 0, 0]]),
479+
([[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),
480+
([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], 2, [[0, 0, 0], [1, 0, 0], [2, 0, 0]], 2),
481+
([[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),
482+
([[0, 0, 0], [1, 0, 0], [2, 0, 0], [2, 2, 0]], (1, 2), [[1, 0, 0], [2, 0, 0]], 1),
510483
],
511484
)
512-
def test_polyline_shortened(coords, input, expected):
513-
assert expected == Polyline(coords).shortened(input)
485+
def test_polyline_shortened(coords, input, expected, length):
486+
polyline = Polyline(coords).shortened(input)
487+
assert expected == polyline and length == polyline.length

0 commit comments

Comments
 (0)