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

Method mirror

cadquery/cq.py:1113–1166  ·  view source on GitHub ↗

Mirror a single CQ object. :param mirrorPlane: the plane to mirror about :type mirrorPlane: string, one of "XY", "YX", "XZ", "ZX", "YZ", "ZY" the planes or the normal vector of the plane eg (1,0,0) or a Face object :param basePointVector: the base point

(
        self: T,
        mirrorPlane: Union[
            Literal["XY", "YX", "XZ", "ZX", "YZ", "ZY"], VectorLike, Face, "Workplane"
        ] = "XY",
        basePointVector: Optional[VectorLike] = None,
        union: bool = False,
    )

Source from the content-addressed store, hash-verified

1111 )
1112
1113 def mirror(
1114 self: T,
1115 mirrorPlane: Union[
1116 Literal["XY", "YX", "XZ", "ZX", "YZ", "ZY"], VectorLike, Face, "Workplane"
1117 ] = "XY",
1118 basePointVector: Optional[VectorLike] = None,
1119 union: bool = False,
1120 ) -> T:
1121 """
1122 Mirror a single CQ object.
1123
1124 :param mirrorPlane: the plane to mirror about
1125 :type mirrorPlane: string, one of "XY", "YX", "XZ", "ZX", "YZ", "ZY" the planes
1126 or the normal vector of the plane eg (1,0,0) or a Face object
1127 :param basePointVector: the base point to mirror about (this is overwritten if a Face is passed)
1128 :param union: If true will perform a union operation on the mirrored object
1129 """
1130
1131 mp: Union[Literal["XY", "YX", "XZ", "ZX", "YZ", "ZY"], Vector]
1132 bp: Vector
1133 face: Optional[Face] = None
1134
1135 # handle mirrorPLane
1136 if isinstance(mirrorPlane, Workplane):
1137 val = mirrorPlane.val()
1138 if isinstance(val, Face):
1139 mp = val.normalAt()
1140 face = val
1141 else:
1142 raise ValueError(f"Face required, got {val}")
1143 elif isinstance(mirrorPlane, Face):
1144 mp = mirrorPlane.normalAt()
1145 face = mirrorPlane
1146 elif not isinstance(mirrorPlane, str):
1147 mp = Vector(mirrorPlane)
1148 else:
1149 mp = mirrorPlane
1150
1151 # handle basePointVector
1152 if face and basePointVector is None:
1153 bp = face.Center()
1154 elif basePointVector is None:
1155 bp = Vector()
1156 else:
1157 bp = Vector(basePointVector)
1158
1159 newS = self.newObject(
1160 [obj.mirror(mp, bp) for obj in self.vals() if isinstance(obj, Shape)]
1161 )
1162
1163 if union:
1164 return self.union(newS)
1165 else:
1166 return newS
1167
1168 def translate(self: T, vec: VectorLike) -> T:
1169 """

Callers 7

test_mirrorMethod · 0.45
test_all_planesMethod · 0.45
test_bad_plane_inputMethod · 0.45
test_mirror_axisMethod · 0.45
test_mirror_workplaneMethod · 0.45
test_mirror_faceMethod · 0.45

Calls 7

newObjectMethod · 0.95
valsMethod · 0.95
unionMethod · 0.95
VectorClass · 0.85
valMethod · 0.45
normalAtMethod · 0.45
CenterMethod · 0.45

Tested by 7

test_mirrorMethod · 0.36
test_all_planesMethod · 0.36
test_bad_plane_inputMethod · 0.36
test_mirror_axisMethod · 0.36
test_mirror_workplaneMethod · 0.36
test_mirror_faceMethod · 0.36