MCPcopy
hub / github.com/CadQuery/cadquery / test_Plane_from_Location

Function test_Plane_from_Location

tests/test_geom.py:53–137  ·  view source on GitHub ↗
(plargs, expectedrot, useproperty)

Source from the content-addressed store, hash-verified

51 ],
52)
53def test_Plane_from_Location(plargs, expectedrot, useproperty):
54 # Test conversion between Plane and Location by converting multiple
55 # times between them, such that two Plane and two Location can be
56 # compared respectively.
57
58 # If there are three things in plargs, ensure that xDir and normal are
59 # orthogonal. That should be ensured by an exception in Plane.__init__.
60 # This here makes the normal orthogonal to xDir by subtracting its
61 # projection on xDir.
62 # If no normal is given, the default normal is assumed.
63 # Packed and unpacked arguments to Plane are kept the same.
64 if len(plargs) == 1:
65 (origin,) = plargs
66 elif len(plargs) == 2:
67 plargs = (
68 *plargs,
69 (0, 0, 1),
70 )
71 # If len(plargs) was 2, it is now 3, and the normal still needs to be
72 # made orthogonal to xDir.
73 if len(plargs) == 3:
74 origin, xDir, normal = plargs
75 xDir = Vector(xDir)
76 normal = Vector(normal)
77 normal -= normal.projectToLine(xDir)
78 xDir = xDir.toTuple()
79 normal = normal.toTuple()
80 plargs = (
81 origin,
82 xDir,
83 normal,
84 )
85
86 # Start from random Plane with classical __init__
87 # Use keyword arguments on purpose, as they still need to work after
88 # having @multidispatch added to that __init__.
89 # Test that on cases, where plargs has three elements and was unpacked.
90 if len(plargs) == 3:
91 originalpl = Plane(origin=origin, xDir=xDir, normal=normal)
92 else:
93 originalpl = Plane(*plargs)
94
95 # Convert back and forth, such that comparable pairs are created.
96 # Depending on test fixture, call constructor directly or use properties
97 if useproperty:
98 locforth = originalpl.location
99 plback = locforth.plane
100 locback = plback.location
101 else:
102 locforth = Location(originalpl)
103 plback = Plane(locforth)
104 locback = Location(plback)
105
106 # Create raw locations, which are flat tuples of raw numbers, suitable for
107 # assertion with pytest.approx
108 locraws = list()
109 for loc in (locforth, locback):
110 loc = loc.toTuple()

Callers

nothing calls this directly

Calls 6

projectToLineMethod · 0.95
toTupleMethod · 0.95
VectorClass · 0.90
PlaneClass · 0.90
LocationClass · 0.90
appendMethod · 0.80

Tested by

no test coverage detected