| 51 | ], |
| 52 | ) |
| 53 | def 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() |