GeometricFeature
- class compas.datastructures.GeometricFeature[source]
Bases:
Feature
Base class for geometric feature which may be applied to a
compas.datastructures.Part
.Applies a binary operation on Part’s current geometry and the feature’s.
An implementation of this class may offer support for various geometry types by adding an entry to OPERATIONS mapping the geometry type to its corresponding operation.
Examples
>>> def trim_brep_plane(brep, plane): >>> # trim brep with plane, return trimmed brep >>> >>> def trim_mesh_plane(mesh, plane): >>> # trim mesh with plane, return trimmed mesh >>> >>> class TrimmingFeature(GeometricFeature): >>> OPERATIONS = {Brep: trim_brep_plane, Mesh: trim_mesh_plane} >>> >>> def __init__(self, trimming_plane): >>> super(TrimmingFeature, self).__init__() >>> self._geometry = trimming_plane >>> >>> def apply(self, part): >>> part_geometry = part.get_geometry(with_features=True) >>> type_ = Brep if isinstance(part_geometry, Brep) else Mesh >>> operation = OPERATIONS[type_] >>> return operation(part_geometry, self._geometry)
Methods
Construct an object of this type from the provided data.
Inherited Methods
Converts the instance to a string.
Apply this Feature to the given part.
Make an independent copy of the data object.
Construct an object of this type from a JSON file.
Construct an object of this type from a JSON string.
Compute a hash of the data for comparison during version control using the sha256 algorithm.
Convert an object to its native data representation.
Convert an object to its native data representation and save it to a JSON file.
Convert an object to its native data representation and save it to a JSON string.
Validate the data against the object's data schema.