Skip to content

Commit

Permalink
Extended test coverage for Issue gumyr#756
Browse files Browse the repository at this point in the history
  • Loading branch information
dalibor-frivaldsky committed Nov 7, 2024
1 parent e3fdefd commit e588107
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions tests/test_direct_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from IPython.lib import pretty

from OCP.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
from OCP.BRepGProp import BRepGProp
from OCP.gp import (
gp,
gp_Ax1,
Expand All @@ -28,6 +29,7 @@
gp_Vec,
gp_XYZ,
)
from OCP.GProp import GProp_GProps

from build123d.build_common import GridLocations, Locations, PolarLocations
from build123d.build_enums import (
Expand Down Expand Up @@ -2556,16 +2558,44 @@ def test_plane_init(self):
with self.assertRaises(TypeError):
Plane(Edge.make_line((0, 0), (0, 1)))

# can be instantiated from planar faces of different surface types
# this loft creates new faces of types Geom_Plane and Geom_BSplineSurface
# can be instantiated from planar faces of surface types other than Geom_Plane
# this loft creates the trapezoid faces of type Geom_BSplineSurface
lofted_solid = Solid.make_loft(
[
Rectangle(3, 1).wire(),
Pos(0, 0, 1) * Rectangle(1, 1).wire(),
]
)
for f in lofted_solid.faces():
Plane(f)

def face_props(f: Face) -> GProp_GProps:
assert f.wrapped is not None
f_props = GProp_GProps()
BRepGProp.SurfaceProperties_s(f.wrapped, f_props)
return f_props

expected = [
# Trapezoid face, negative y coordinate
(
lambda f: face_props(f).CentreOfMass(), # plane origin
lambda f: Axis.X.direction, # plane x_dir
lambda f: Axis.Z.direction, # plane y_dir
lambda f: -Axis.Y.direction, # plane z_dir
),
# Trapezoid face, positive y coordinate
(
lambda f: face_props(f).CentreOfMass(),
lambda f: -Axis.X.direction,
lambda f: Axis.Z.direction,
lambda f: Axis.Y.direction,
),
]
# assert properties of the trapezoid faces
for i, f in enumerate(lofted_solid.faces() | Plane.XZ > Axis.Y):
p = Plane(f)
self.assertVectorAlmostEquals(p.origin, expected[i][0](f), 6)
self.assertVectorAlmostEquals(p.x_dir, expected[i][1](f), 6)
self.assertVectorAlmostEquals(p.y_dir, expected[i][2](f), 6)
self.assertVectorAlmostEquals(p.z_dir, expected[i][3](f), 6)

def test_plane_neg(self):
p = Plane(
Expand Down

0 comments on commit e588107

Please sign in to comment.