Skip to content

Commit

Permalink
Merge pull request #1421 from compas-dev/bugfix_linecopy
Browse files Browse the repository at this point in the history
removed call to __init__ in __new__
  • Loading branch information
chenkasirer authored Jan 14, 2025
2 parents 645dc74 + 1837d4a commit 41abc62
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed vector comparison (`compas.geometry.Vector.__eq__`) to use `TOL.is_allclose` instead of raw coordinate comparison.
* Fixed bug in frame comparison (`compas.geometry.Frame.__eq__`).
* Fixed bug in `compas.geometry.oriented_bounding_box_numpy`.
* Fixed cannot copy `Line` using `deepcopy`.

### Removed

Expand Down
4 changes: 1 addition & 3 deletions src/compas/geometry/curves/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ class Line(Curve):
# overwriting the __new__ method is necessary
# to avoid triggering the plugin mechanism of the base curve class
def __new__(cls, *args, **kwargs):
curve = object.__new__(cls)
curve.__init__(*args, **kwargs)
return curve
return object.__new__(cls)

DATASCHEMA = {
"type": "object",
Expand Down
15 changes: 15 additions & 0 deletions tests/compas/geometry/test_curves_line.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import deepcopy
import pytest
import json
import compas
Expand Down Expand Up @@ -282,3 +283,17 @@ def test_line_flip(p1, p2):
flipped_line = Line(p1, p2).flipped()
assert TOL.is_zero(distance_point_point(flipped_line.start, p2))
assert TOL.is_zero(distance_point_point(flipped_line.end, p1))


def test_line_copy_deepcopy():
line = Line([0, 0, 0], [1, 0, 0])

line_copy = line.copy()

assert line is not line_copy
assert line == line_copy

line_deepcopy = deepcopy(line)

assert line is not line_deepcopy
assert line == line_deepcopy

0 comments on commit 41abc62

Please sign in to comment.