Skip to content

Commit

Permalink
Add Plane.reverse() Issue #546
Browse files Browse the repository at this point in the history
  • Loading branch information
gumyr committed Feb 10, 2024
1 parent 4641d1d commit 594e5f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/build123d/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
limitations under the License.
"""

from __future__ import annotations

# pylint has trouble with the OCP imports
Expand Down Expand Up @@ -1953,6 +1954,10 @@ def __repr__(self):
z_dir_str = ", ".join((f"{v:.2f}" for v in self.z_dir.to_tuple()))
return f"Plane(o=({origin_str}), x=({x_dir_str}), z=({z_dir_str}))"

def reverse(self) -> Plane:
"""Reverse z direction of plane"""
return -self

@property
def origin(self) -> Vector:
"""Get the Plane origin"""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_direct_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2248,6 +2248,13 @@ def test_plane_neg(self):
self.assertVectorAlmostEquals(
p2.y_dir, (-p.z_dir).cross(p.x_dir).normalized(), 6
)
p3 = p.reverse()
self.assertVectorAlmostEquals(p3.origin, p.origin, 6)
self.assertVectorAlmostEquals(p3.x_dir, p.x_dir, 6)
self.assertVectorAlmostEquals(p3.z_dir, -p.z_dir, 6)
self.assertVectorAlmostEquals(
p3.y_dir, (-p.z_dir).cross(p.x_dir).normalized(), 6
)

def test_plane_mul(self):
p = Plane(origin=(1, 2, 3), x_dir=(1, 0, 0), z_dir=(0, 0, 1))
Expand Down

0 comments on commit 594e5f8

Please sign in to comment.