Skip to content

Commit

Permalink
Merge pull request #1435 from mattiskoh/bugfix-plane-is-parallel
Browse files Browse the repository at this point in the history
fixed unexpected behavior for opposite parallel planes.
  • Loading branch information
tomvanmele authored Feb 6, 2025
2 parents e907f00 + 6065114 commit 961fdf8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
* Fixed unexpected behavior for method `Plane.is_parallel` for opposite normals.

### Added

Expand Down
6 changes: 5 additions & 1 deletion src/compas/geometry/plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,13 @@ def is_parallel(self, other, tol=None):
>>> plane2 = Plane([1.0, 1.0, 1.0], [0.0, 0.0, 1.0])
>>> plane1.is_parallel(plane2)
True
>>> plane1 = Plane.worldXY()
>>> plane2 = Plane([1.0, 1.0, 1.0], [0.0, 0.0, -1.0])
>>> plane1.is_parallel(plane2)
True
"""
return TOL.is_close(self.normal.dot(other.normal), 1, rtol=0, atol=tol)
return TOL.is_close(abs(self.normal.dot(other.normal)), 1, rtol=0, atol=tol)

def is_perpendicular(self, other, tol=None):
"""Verify if this plane is perpendicular to another plane.
Expand Down
10 changes: 10 additions & 0 deletions tests/compas/geometry/test_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,13 @@ def test_plane_from_three_points():

result = Plane.from_three_points(pt1, pt2, pt3)
assert result == ([0, 0, 0], [0, 0, 1])


def test_plane_is_parallel():
plane1 = Plane.worldXY()
plane2 = Plane([1.0, 1.0, 1.0], [0.0, 0.0, 1.0])
assert plane1.is_parallel(plane2)

plane1 = Plane.worldXY()
plane2 = Plane([1.0, 1.0, 1.0], [0.0, 0.0, -1.0])
assert plane1.is_parallel(plane2)

0 comments on commit 961fdf8

Please sign in to comment.