Add Plane.reverse() Issue #546

This commit is contained in:
gumyr 2024-02-10 09:25:09 -05:00
parent 4641d1d8db
commit 594e5f8a7c
2 changed files with 12 additions and 0 deletions

View file

@ -26,6 +26,7 @@ license:
limitations under the License.
"""
from __future__ import annotations
# pylint has trouble with the OCP imports
@ -1953,6 +1954,10 @@ class Plane(metaclass=PlaneMeta):
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"""

View file

@ -2248,6 +2248,13 @@ class TestPlane(DirectApiTestCase):
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))