|
8 | 8 | from compas_rhino.conversions import point_to_rhino |
9 | 9 | from compas_rhino.conversions import xform_to_rhino |
10 | 10 | from compas_rhino.conversions import frame_to_rhino |
| 11 | +from compas_rhino.conversions import cylinder_to_rhino |
11 | 12 |
|
12 | 13 | import Rhino |
13 | 14 |
|
@@ -166,6 +167,23 @@ def from_box(cls, box): |
166 | 167 | rhino_box = box_to_rhino(box) |
167 | 168 | return cls.from_brep(rhino_box.ToBrep()) |
168 | 169 |
|
| 170 | + @classmethod |
| 171 | + def from_cylinder(cls, cylinder): |
| 172 | + """Create a RhinoBrep from a box. |
| 173 | +
|
| 174 | + Parameters |
| 175 | + ---------- |
| 176 | + box : :class:`~compas.geometry.Box` |
| 177 | + The box geometry of the brep. |
| 178 | +
|
| 179 | + Returns |
| 180 | + ------- |
| 181 | + :class:`~compas_rhino.geometry.RhinoBrep` |
| 182 | +
|
| 183 | + """ |
| 184 | + rhino_cylinder = cylinder_to_rhino(cylinder) |
| 185 | + return cls.from_brep(rhino_cylinder.ToBrep(True, True)) |
| 186 | + |
169 | 187 | # ============================================================================== |
170 | 188 | # Methods |
171 | 189 | # ============================================================================== |
@@ -211,6 +229,81 @@ def trim(self, trimming_plane, tolerance=TOLERANCE): |
211 | 229 |
|
212 | 230 | self._brep = results[0] |
213 | 231 |
|
| 232 | + @classmethod |
| 233 | + def from_boolean_difference(cls, breps_a, breps_b): |
| 234 | + """Construct a Brep from the boolean difference of two groups of Breps. |
| 235 | +
|
| 236 | + Parameters |
| 237 | + ---------- |
| 238 | + brep_a : :class:`~compas_rhino.geometry.RhinoBrep` or list(:class:`~compas_rhino.geometry.RhinoBrep`) |
| 239 | + brep_b : :class:`~compas_rhino.geometry.RhinoBrep` or list(:class:`~compas_rhino.geometry.RhinoBrep`) |
| 240 | +
|
| 241 | + Returns |
| 242 | + ------- |
| 243 | + list(:class:`~compas_rhino.geometry.RhinoBrep`) |
| 244 | + list of one or more resulting Breps. |
| 245 | +
|
| 246 | + """ |
| 247 | + if not isinstance(brep_a, list): |
| 248 | + brep_a = [brep_a] |
| 249 | + if not isinstance(brep_b, list): |
| 250 | + brep_b = [brep_b] |
| 251 | + resulting_breps = Rhino.Geometry.Brep.CreateBooleanDifference( |
| 252 | + [b.native_brep for b in brep_a], |
| 253 | + [b.native_brep for b in brep_b], |
| 254 | + TOLERANCE |
| 255 | + ) |
| 256 | + return [RhinoBrep.from_brep(brep) for brep in resulting_breps] |
| 257 | + |
| 258 | + @classmethod |
| 259 | + def from_boolean_union(cls, breps_a, breps_b): |
| 260 | + """Construct a Brep from the boolean union of two groups of Breps. |
| 261 | +
|
| 262 | + Parameters |
| 263 | + ---------- |
| 264 | + brep_a : :class:`~compas_rhino.geometry.RhinoBrep` or list(:class:`~compas_rhino.geometry.RhinoBrep`) |
| 265 | + brep_b : :class:`~compas_rhino.geometry.RhinoBrep` or list(:class:`~compas_rhino.geometry.RhinoBrep`) |
| 266 | +
|
| 267 | + Returns |
| 268 | + ------- |
| 269 | + list(:class:`~compas_rhino.geometry.RhinoBrep`) |
| 270 | + list of one or more resulting Breps. |
| 271 | +
|
| 272 | + """ |
| 273 | + if not isinstance(brep_a, list): |
| 274 | + brep_a = [brep_a] |
| 275 | + if not isinstance(brep_b, list): |
| 276 | + brep_b = [brep_b] |
| 277 | + |
| 278 | + resulting_breps = Rhino.Geometry.Brep.CreateBooleanUnion([b.native_brep for b in brep_a + brep_b], TOLERANCE) |
| 279 | + return [RhinoBrep.from_brep(brep) for brep in resulting_breps] |
| 280 | + |
| 281 | + @classmethod |
| 282 | + def from_boolean_intersection(cls, brep_a, brep_b): |
| 283 | + """Construct a Brep from the boolean intersection of two groups of Breps. |
| 284 | +
|
| 285 | + Parameters |
| 286 | + ---------- |
| 287 | + brep_a : :class:`~compas_rhino.geometry.RhinoBrep` or list(:class:`~compas_rhino.geometry.RhinoBrep`) |
| 288 | + brep_b : :class:`~compas_rhino.geometry.RhinoBrep` or list(:class:`~compas_rhino.geometry.RhinoBrep`) |
| 289 | +
|
| 290 | + Returns |
| 291 | + ------- |
| 292 | + list(:class:`~compas_rhino.geometry.RhinoBrep`) |
| 293 | + list of one or more resulting Breps. |
| 294 | +
|
| 295 | + """ |
| 296 | + if not isinstance(brep_a, list): |
| 297 | + brep_a = [brep_a] |
| 298 | + if not isinstance(brep_b, list): |
| 299 | + brep_b = [brep_b] |
| 300 | + resulting_breps = Rhino.Geometry.Brep.CreateBooleanIntersection( |
| 301 | + [b.native_brep for b in brep_a], |
| 302 | + [b.native_brep for b in brep_b], |
| 303 | + TOLERANCE |
| 304 | + ) |
| 305 | + return [RhinoBrep.from_brep(brep) for brep in resulting_breps] |
| 306 | + |
214 | 307 | # ============================================================================== |
215 | 308 | # Other Methods |
216 | 309 | # ============================================================================== |
|
0 commit comments