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

Method testWorkplaneCenterOptions

tests/test_cadquery.py:4053–4162  ·  view source on GitHub ↗

Test options for specifying origin of workplane

(self)

Source from the content-addressed store, hash-verified

4051 self.assertFalse(solid.isInside((55, 55, 55)))
4052
4053 def testWorkplaneCenterOptions(self):
4054 """
4055 Test options for specifying origin of workplane
4056 """
4057 decimal_places = 9
4058
4059 pts = [(0, 0), (90, 0), (90, 30), (30, 30), (30, 60), (0.0, 60)]
4060
4061 r = Workplane("XY").polyline(pts).close().extrude(10.0)
4062
4063 origin = (
4064 r.faces(">Z")
4065 .workplane(centerOption="ProjectedOrigin")
4066 .plane.origin.toTuple()
4067 )
4068 self.assertTupleAlmostEquals(origin, (0.0, 0.0, 10.0), decimal_places)
4069
4070 origin = (
4071 r.faces(">Z").workplane(centerOption="CenterOfMass").plane.origin.toTuple()
4072 )
4073 self.assertTupleAlmostEquals(origin, (37.5, 22.5, 10.0), decimal_places)
4074
4075 origin = (
4076 r.faces(">Z")
4077 .workplane(centerOption="CenterOfBoundBox")
4078 .plane.origin.toTuple()
4079 )
4080 self.assertTupleAlmostEquals(origin, (45.0, 30.0, 10.0), decimal_places)
4081
4082 origin = (
4083 r.faces(">Z")
4084 .workplane(centerOption="ProjectedOrigin", origin=(30, 10, 20))
4085 .plane.origin.toTuple()
4086 )
4087 self.assertTupleAlmostEquals(origin, (30.0, 10.0, 10.0), decimal_places)
4088
4089 origin = (
4090 r.faces(">Z")
4091 .workplane(centerOption="ProjectedOrigin", origin=Vector(30, 10, 20))
4092 .plane.origin.toTuple()
4093 )
4094 self.assertTupleAlmostEquals(origin, (30.0, 10.0, 10.0), decimal_places)
4095
4096 with self.assertRaises(ValueError):
4097 origin = r.faces(">Z").workplane(centerOption="undefined")
4098
4099 # test case where plane origin is shifted with center call
4100 r = (
4101 r.faces(">Z")
4102 .workplane(centerOption="ProjectedOrigin")
4103 .center(30, 0)
4104 .hole(90)
4105 )
4106
4107 origin = (
4108 r.faces(">Z")
4109 .workplane(centerOption="ProjectedOrigin")
4110 .plane.origin.toTuple()

Callers

nothing calls this directly

Calls 11

WorkplaneClass · 0.85
VectorClass · 0.85
extrudeMethod · 0.80
polylineMethod · 0.80
workplaneMethod · 0.80
holeMethod · 0.80
centerMethod · 0.80
closeMethod · 0.45
toTupleMethod · 0.45
facesMethod · 0.45

Tested by

no test coverage detected