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

from_data

Construct an object of this type from the provided data.

Inherited Methods

ToString

Converts the instance to a string.

apply

Apply this Feature to the given part.

copy

Make an independent copy of the data object.

from_json

Construct an object of this type from a JSON file.

from_jsonstring

Construct an object of this type from a JSON string.

sha256

Compute a hash of the data for comparison during version control using the sha256 algorithm.

to_data

Convert an object to its native data representation.

to_json

Convert an object to its native data representation and save it to a JSON file.

to_jsonstring

Convert an object to its native data representation and save it to a JSON string.

validate_data

Validate the data against the object's data schema.