Test that _getPln does the right thing with different arguments
()
| 2061 | |
| 2062 | |
| 2063 | def test_constraint_getPln(): |
| 2064 | """ |
| 2065 | Test that _getPln does the right thing with different arguments |
| 2066 | """ |
| 2067 | ids = (0, 1) |
| 2068 | sublocs = (cq.Location(), cq.Location()) |
| 2069 | |
| 2070 | def make_constraint(shape0): |
| 2071 | return cq.Constraint(ids, (shape0, shape0), sublocs, "PointInPlane", 0) |
| 2072 | |
| 2073 | def fail_this(shape0): |
| 2074 | with pytest.raises(ValueError): |
| 2075 | make_constraint(shape0) |
| 2076 | |
| 2077 | def resulting_pln(shape0): |
| 2078 | c0 = make_constraint(shape0) |
| 2079 | return c0._getPln(c0.args[0]) |
| 2080 | |
| 2081 | def resulting_plane(shape0): |
| 2082 | p0 = resulting_pln(shape0) |
| 2083 | return cq.Plane( |
| 2084 | cq.Vector(p0.Location()), |
| 2085 | cq.Vector(p0.XAxis().Direction()), |
| 2086 | cq.Vector(p0.Axis().Direction()), |
| 2087 | ) |
| 2088 | |
| 2089 | # point should fail |
| 2090 | fail_this(cq.Vertex.makeVertex(0, 0, 0)) |
| 2091 | |
| 2092 | # line should fail |
| 2093 | fail_this(cq.Edge.makeLine(cq.Vector(1, 0, 0), cq.Vector(0, 0, 0))) |
| 2094 | |
| 2095 | # planar edge (circle) should succeed |
| 2096 | origin = cq.Vector(1, 2, 3) |
| 2097 | direction = cq.Vector(4, 5, 6).normalized() |
| 2098 | p1 = resulting_plane(cq.Edge.makeCircle(1, pnt=origin, dir=direction)) |
| 2099 | assert p1.zDir == direction |
| 2100 | assert p1.origin == origin |
| 2101 | |
| 2102 | # planar edge (spline) should succeed |
| 2103 | # it's a touch risky calling a spline a planar edge, but lets see if it's within tolerance |
| 2104 | points0 = [cq.Vector(x) for x in [(-1, 0, 1), (0, 1, 1), (1, 0, 1), (0, -1, 1)]] |
| 2105 | planar_spline = cq.Edge.makeSpline(points0, periodic=True) |
| 2106 | p2 = resulting_plane(planar_spline) |
| 2107 | assert p2.origin == planar_spline.Center() |
| 2108 | assert p2.zDir == cq.Vector(0, 0, 1) |
| 2109 | |
| 2110 | # non-planar edge should fail |
| 2111 | points1 = [cq.Vector(x) for x in [(-1, 0, -1), (0, 1, 1), (1, 0, -1), (0, -1, 1)]] |
| 2112 | nonplanar_spline = cq.Edge.makeSpline(points1, periodic=True) |
| 2113 | fail_this(nonplanar_spline) |
| 2114 | |
| 2115 | # make a triangle in the XZ plane |
| 2116 | points2 = [cq.Vector(x) for x in [(-1, 0, -1), (0, 0, 1), (1, 0, -1)]] |
| 2117 | points2.append(points2[0]) |
| 2118 | triangle = cq.Wire.makePolygon(points2) |
| 2119 | p3 = resulting_plane(triangle) |
| 2120 | assert p3.origin == triangle.Center() |
nothing calls this directly
no test coverage detected