Skip to content

Commit

Permalink
Merge branch 'main' into tolerance-singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed May 13, 2024
2 parents 182f8dc + 835f233 commit 89b8b7c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added `compas.geometry.Brep.from_plane`.
* Added `compas.tolerance.Tolerance.angulardeflection`.
* Added `compas.tolerance.Tolerance.update_from_dict`.
* Added `compas.scene.SceneObject.scene` attribute.

### Changed

Expand All @@ -36,6 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed use of `compas.geometry.close` to `compas.tolerance.TOL.is_close`.
* Changed imports of itertools to `compas.itertools` instead of `compas.utilities`.
* Changed `compas.tolerance.Tolerance` to a singleton, to ensure having only library-wide tolerance values.
* Updated `compas_rhino.conversions.point_to_compas` to allow for `Rhino.Geometry.Point` as input.
* Changed `compas.datastructures.Tree.print_hierarchy` to `compas.datastructures.Tree.__str__`.

### Removed

Expand All @@ -45,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Removed `compas.utilities.geometric_key` and replaced it by `compas.tolerance.TOL.geometric_key`.
* Removed `compas.utilities.geometric_key_xy` and replaced it by `compas.tolerance.TOL.geometric_key_xy`.
* Removed indexed attribute access from all geometry classes except `Point`, `Vector`, `Line`, `Polygon`, `Polyline`.
* Removed `compas.datastructures.Tree.print_hierarchy`.

## [2.1.0] 2024-03-01

Expand Down
36 changes: 20 additions & 16 deletions src/compas/datastructures/tree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,11 @@ class Tree(Datastructure):
>>> branch.add(leaf1)
>>> branch.add(leaf2)
>>> print(tree)
<Tree with 4 nodes, 1 branches, and 2 leaves>
>>> tree.print()
<TreeNode root>
<TreeNode branch>
<TreeNode leaf2>
<TreeNode leaf1>
<Tree with 4 nodes>
|--<TreeNode: root>
|-- <TreeNode: branch>
|-- <TreeNode: leaf1>
|-- <TreeNode: leaf2>
"""

Expand Down Expand Up @@ -281,6 +280,9 @@ def __init__(self, name=None, **kwargs):
super(Tree, self).__init__(kwargs, name=name)
self._root = None

def __str__(self):
return "<Tree with {} nodes>\n{}".format(len(list(self.nodes)), self.get_hierarchy_string(max_depth=3))

@property
def root(self):
return self._root
Expand Down Expand Up @@ -435,12 +437,9 @@ def get_nodes_by_name(self, name):
nodes.append(node)
return nodes

def __repr__(self):
return "<Tree with {} nodes>".format(len(list(self.nodes)))

def print_hierarchy(self, max_depth=None):
def get_hierarchy_string(self, max_depth=None):
"""
Print the spatial hierarchy of the tree.
Return string representation for the spatial hierarchy of the tree.
Parameters
----------
Expand All @@ -450,22 +449,27 @@ def print_hierarchy(self, max_depth=None):
Returns
-------
None
str
String representing the spatial hierarchy of the tree.
"""

def _print(node, prefix="", last=True, depth=0):
hierarchy = []

def traverse(node, hierarchy, prefix="", last=True, depth=0):

if max_depth is not None and depth > max_depth:
return

connector = "└── " if last else "├── "
print("{}{}{}".format(prefix, connector, node))
hierarchy.append("{}{}{}".format(prefix, connector, node))
prefix += " " if last else "│ "
for i, child in enumerate(node.children):
_print(child, prefix, i == len(node.children) - 1, depth + 1)
traverse(child, hierarchy, prefix, i == len(node.children) - 1, depth + 1)

traverse(self.root, hierarchy)

_print(self.root)
return "\n".join(hierarchy)

def to_graph(self, key_mapper=None):
"""Convert the tree to a graph.
Expand Down
7 changes: 7 additions & 0 deletions src/compas/scene/sceneobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class SceneObject(TreeNode):
The settings including necessary attributes for reconstructing the scene object besides the Data item.
context : str
The context in which the scene object is created.
scene : :class:`compas.scene.Scene`
The scene to which the scene object belongs.
"""

Expand Down Expand Up @@ -120,6 +122,11 @@ def __repr__(self):
# type: () -> str
return "<{}: {}>".format(self.__class__.__name__, self.name)

@property
def scene(self):
# type: () -> compas.scene.Scene
return self.tree

@property
def item(self):
# type: () -> compas.geometry.Geometry | compas.datastructures.Datastructure
Expand Down
1 change: 0 additions & 1 deletion src/compas_blender/scene/capsuleobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def draw(
vertices, faces = self.geometry.to_vertices_and_faces(u=u, v=v)
mesh = conversions.vertices_and_faces_to_blender_mesh(vertices, faces, name=self.geometry.name)
if shade_smooth:
print(dir(mesh))
mesh.shade_smooth()

obj = self.create_object(mesh, name=name)
Expand Down
11 changes: 9 additions & 2 deletions src/compas_rhino/conversions/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import print_function

import Rhino # type: ignore
from System import MissingMemberException # type: ignore

from compas.geometry import Frame
from compas.geometry import Plane
Expand Down Expand Up @@ -103,14 +104,20 @@ def point_to_compas(point):
Parameters
----------
point : :rhino:`Rhino.Geometry.Point3d`
point : :rhino:`Rhino.Geometry.Point3d` | :rhino:`Rhino.Geometry.Point`
Returns
-------
:class:`compas.geometry.Point`
"""
return Point(point.X, point.Y, point.Z)
try:
return Point(point.X, point.Y, point.Z)
except MissingMemberException:
try:
return Point(point.Location.X, point.Location.Y, point.Location.Z)
except MissingMemberException:
raise TypeError("Unexpected point type, got: {}".format(type(point)))


def vector_to_compas(vector):
Expand Down
1 change: 0 additions & 1 deletion src/compas_rhino/geometry/brep/brep.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ def slice(self, plane):
if isinstance(plane, Frame):
plane = Plane.from_frame(plane)
curves = Rhino.Geometry.Brep.CreateContourCurves(self._brep, plane_to_rhino(plane))
print("curves:{}".format(curves))
return [curve_to_compas(curve) for curve in curves]

def split(self, cutter):
Expand Down

0 comments on commit 89b8b7c

Please sign in to comment.