Skip to content

Commit 95eaa00

Browse files
authored
Merge pull request #1409 from compas-dev/fix-friday
Fix friday
2 parents 1aabc04 + 91b210d commit 95eaa00

File tree

6 files changed

+160
-64
lines changed

6 files changed

+160
-64
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
* Added key conversion map to `compas.colors.ColorDict` to avoid serialisation problems with tuple keys when used in combination with edges.
13+
* Added `Scene.find_all_by_itemtype`.
1314

1415
### Changed
1516

1617
* Fixed bug in `VolMesh.delete_cell`.
1718
* Fixed `NoneType` error when calling `compas.geometry.Sphere.edges`.
18-
19+
* Fixed bug in `VolMesh.vertex_halffaces`.
20+
* Fixed bug in `VolMesh.vertex_cells`.
21+
* Fixed bug in `VolMesh.is_halfface_on_boundary`.
1922

2023
### Removed
2124

25+
* Removed `VolMesh.halfface_adjacent_halfface` because of general nonsensicalness, and because it is (and probably always has been) completely broken.
26+
2227

2328
## [2.5.0] 2024-10-25
2429

src/compas/datastructures/volmesh/volmesh.py

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def from_obj(cls, filepath, precision=None):
383383

384384
@classmethod
385385
def from_vertices_and_cells(cls, vertices, cells):
386-
# type: (list[list[float]], list[list[list[int]]]) -> VolMesh
386+
# type: (list[list[float]] | dict[int, list[float]], list[list[list[int]]]) -> VolMesh
387387
"""Construct a volmesh object from vertices and cells.
388388
389389
Parameters
@@ -407,11 +407,11 @@ def from_vertices_and_cells(cls, vertices, cells):
407407
volmesh = cls()
408408

409409
if isinstance(vertices, Mapping):
410-
for key, xyz in vertices.items():
410+
for key, xyz in vertices.items(): # type: ignore
411411
volmesh.add_vertex(key=key, attr_dict=dict(zip(("x", "y", "z"), xyz)))
412412
else:
413-
for x, y, z in iter(vertices):
414-
volmesh.add_vertex(x=x, y=y, z=z)
413+
for x, y, z in iter(vertices): # type: ignore
414+
volmesh.add_vertex(x=x, y=y, z=z) # type: ignore
415415

416416
for cell in cells:
417417
volmesh.add_cell(cell)
@@ -531,9 +531,9 @@ def to_obj(self, filepath, precision=None, **kwargs):
531531
the faces to the file.
532532
533533
"""
534-
meshes = [self.cell_to_mesh(cell) for cell in self.cells()]
534+
meshes = [self.cell_to_mesh(cell) for cell in self.cells()] # type: ignore
535535
obj = OBJ(filepath, precision=precision)
536-
obj.write(meshes, **kwargs)
536+
obj.write(meshes, **kwargs) # type: ignore
537537

538538
def to_vertices_and_cells(self):
539539
# type: () -> tuple[list[list[float]], list[list[list[int]]]]
@@ -659,7 +659,7 @@ def vertex_sample(self, size=1):
659659
:meth:`edge_sample`, :meth:`face_sample`, :meth:`cell_sample`
660660
661661
"""
662-
return sample(list(self.vertices()), size)
662+
return sample(list(self.vertices()), size) # type: ignore
663663

664664
def edge_sample(self, size=1):
665665
# type: (int) -> list[tuple[int, int]]
@@ -680,7 +680,7 @@ def edge_sample(self, size=1):
680680
:meth:`vertex_sample`, :meth:`face_sample`, :meth:`cell_sample`
681681
682682
"""
683-
return sample(list(self.edges()), size)
683+
return sample(list(self.edges()), size) # type: ignore
684684

685685
def face_sample(self, size=1):
686686
# type: (int) -> list[int]
@@ -701,7 +701,7 @@ def face_sample(self, size=1):
701701
:meth:`vertex_sample`, :meth:`edge_sample`, :meth:`cell_sample`
702702
703703
"""
704-
return sample(list(self.faces()), size)
704+
return sample(list(self.faces()), size) # type: ignore
705705

706706
def cell_sample(self, size=1):
707707
# type: (int) -> list[int]
@@ -722,7 +722,7 @@ def cell_sample(self, size=1):
722722
:meth:`vertex_sample`, :meth:`edge_sample`, :meth:`face_sample`
723723
724724
"""
725-
return sample(list(self.cells()), size)
725+
return sample(list(self.cells()), size) # type: ignore
726726

727727
def vertex_index(self):
728728
# type: () -> dict[int, int]
@@ -739,7 +739,7 @@ def vertex_index(self):
739739
:meth:`index_vertex`
740740
741741
"""
742-
return {key: index for index, key in enumerate(self.vertices())}
742+
return {key: index for index, key in enumerate(self.vertices())} # type: ignore
743743

744744
def index_vertex(self):
745745
# type: () -> dict[int, int]
@@ -756,7 +756,7 @@ def index_vertex(self):
756756
:meth:`vertex_index`
757757
758758
"""
759-
return dict(enumerate(self.vertices()))
759+
return dict(enumerate(self.vertices())) # type: ignore
760760

761761
def vertex_gkey(self, precision=None):
762762
# type: (int | None) -> dict[int, str]
@@ -781,7 +781,7 @@ def vertex_gkey(self, precision=None):
781781
"""
782782
gkey = TOL.geometric_key
783783
xyz = self.vertex_coordinates
784-
return {vertex: gkey(xyz(vertex), precision) for vertex in self.vertices()}
784+
return {vertex: gkey(xyz(vertex), precision) for vertex in self.vertices()} # type: ignore
785785

786786
def gkey_vertex(self, precision=None):
787787
# type: (int | None) -> dict[str, int]
@@ -806,7 +806,7 @@ def gkey_vertex(self, precision=None):
806806
"""
807807
gkey = TOL.geometric_key
808808
xyz = self.vertex_coordinates
809-
return {gkey(xyz(vertex), precision): vertex for vertex in self.vertices()}
809+
return {gkey(xyz(vertex), precision): vertex for vertex in self.vertices()} # type: ignore
810810

811811
# --------------------------------------------------------------------------
812812
# Builders & Modifiers
@@ -1760,8 +1760,10 @@ def vertex_halffaces(self, vertex):
17601760
u = vertex
17611761
faces = []
17621762
for v in self._plane[u]:
1763-
for face in self._plane[u][v]:
1764-
if face is not None:
1763+
for w in self._plane[u][v]:
1764+
cell = self._plane[u][v][w]
1765+
if cell is not None:
1766+
face = self.cell_halfedge_face(cell, (u, v))
17651767
faces.append(face)
17661768
return faces
17671769

@@ -1789,7 +1791,8 @@ def vertex_cells(self, vertex):
17891791
for w in self._plane[u][v]:
17901792
cell = self._plane[u][v][w]
17911793
if cell is not None:
1792-
cells.append(cell)
1794+
if cell not in cells:
1795+
cells.append(cell)
17931796
return cells
17941797

17951798
def is_vertex_on_boundary(self, vertex):
@@ -3108,37 +3111,6 @@ def halfface_opposite_halfface(self, halfface):
31083111
nbr = self._plane[w][v][u]
31093112
return None if nbr is None else self._cell[nbr][w][v]
31103113

3111-
def halfface_adjacent_halfface(self, halfface, halfedge):
3112-
"""Return the halfface adjacent to the halfface across the halfedge.
3113-
3114-
Parameters
3115-
----------
3116-
halfface : int
3117-
The identifier of the halfface.
3118-
halfedge : tuple[int, int]
3119-
The identifier of the halfedge.
3120-
3121-
Returns
3122-
-------
3123-
int | None
3124-
The identifier of the adjacent half-face, or None if `halfedge` is on the boundary.
3125-
3126-
See Also
3127-
--------
3128-
:meth:`halfface_opposite_halfface`
3129-
3130-
Notes
3131-
-----
3132-
The adjacent face belongs a to one of the cell neighbors over faces of the initial cell.
3133-
A face and its adjacent face share two common vertices.
3134-
3135-
"""
3136-
u, v = halfedge
3137-
cell = self.halfface_cell(halfface)
3138-
nbr_halfface = self._cell[cell][v][u]
3139-
nbr_cell = self._plane[u][v][nbr_halfface]
3140-
return None if nbr_cell is None else self._cell[nbr_cell][v][u]
3141-
31423114
def halfface_vertex_ancestor(self, halfface, vertex):
31433115
"""Return the vertex before the specified vertex in a specific face.
31443116
@@ -3282,8 +3254,8 @@ def is_halfface_on_boundary(self, halfface):
32823254
:meth:`is_vertex_on_boundary`, :meth:`is_edge_on_boundary`, :meth:`is_cell_on_boundary`
32833255
32843256
"""
3285-
u, v = self._halfface[halfface][:2]
3286-
return self._plane[v][u][halfface] is None
3257+
u, v, w = self._halfface[halfface][:3]
3258+
return self._plane[w][v][u] is None
32873259

32883260
# --------------------------------------------------------------------------
32893261
# Face Geometry

src/compas/scene/meshobject.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,6 @@ def mesh(self, mesh):
106106
self._item = mesh
107107
self._transformation = None
108108

109-
@property
110-
def transformation(self):
111-
# type: () -> compas.geometry.Transformation | None
112-
return self._transformation
113-
114-
@transformation.setter
115-
def transformation(self, transformation):
116-
# type: (compas.geometry.Transformation) -> None
117-
self._transformation = transformation
118-
119109
def draw_vertices(self):
120110
"""Draw the vertices of the mesh.
121111

src/compas/scene/scene.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ def redraw(self):
213213
self.draw()
214214

215215
def find_by_name(self, name):
216+
# type: (str) -> SceneObject
216217
"""Find the first scene object with the given name.
217218
218219
Parameters
@@ -225,10 +226,10 @@ def find_by_name(self, name):
225226
:class:`SceneObject`
226227
227228
"""
228-
# type: (str) -> SceneObject
229229
return self.get_node_by_name(name=name)
230230

231231
def find_by_itemtype(self, itemtype):
232+
# type: (...) -> SceneObject | None
232233
"""Find the first scene object with a data item of the given type.
233234
234235
Parameters
@@ -238,10 +239,29 @@ def find_by_itemtype(self, itemtype):
238239
239240
Returns
240241
-------
241-
:class:`SceneObject`
242+
:class:`SceneObject` or None
242243
243244
"""
244-
# type: (Type[compas.data.Data]) -> SceneObject
245245
for obj in self.objects:
246246
if isinstance(obj.item, itemtype):
247247
return obj
248+
249+
def find_all_by_itemtype(self, itemtype):
250+
# type: (...) -> list[SceneObject]
251+
"""Find all scene objects with a data item of the given type.
252+
253+
Parameters
254+
----------
255+
itemtype : :class:`compas.data.Data`
256+
The type of the data item associated with the scene object.
257+
258+
Returns
259+
-------
260+
list[:class:`SceneObject`]
261+
262+
"""
263+
sceneobjects = []
264+
for obj in self.objects:
265+
if isinstance(obj.item, itemtype):
266+
sceneobjects.append(obj)
267+
return sceneobjects

src/compas_rhino/scene/meshobject.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def clear(self):
7474
7575
"""
7676
compas_rhino.objects.delete_objects(self.guids, purge=True)
77+
self.guids = []
7778

7879
def clear_vertices(self):
7980
"""Delete all vertices drawn by this scene object.
@@ -84,6 +85,7 @@ def clear_vertices(self):
8485
8586
"""
8687
compas_rhino.objects.delete_objects(self._guid_vertex, purge=True)
88+
self._guid_vertex = {}
8789

8890
def clear_edges(self):
8991
"""Delete all edges drawn by this scene object.
@@ -94,6 +96,7 @@ def clear_edges(self):
9496
9597
"""
9698
compas_rhino.objects.delete_objects(self._guid_edge, purge=True)
99+
self._guid_edge = {}
97100

98101
def clear_faces(self):
99102
"""Delete all faces drawn by this scene object.
@@ -104,6 +107,7 @@ def clear_faces(self):
104107
105108
"""
106109
compas_rhino.objects.delete_objects(self._guid_face, purge=True)
110+
self._guid_face = {}
107111

108112
# ==========================================================================
109113
# draw

0 commit comments

Comments
 (0)