diff --git a/CHANGELOG.md b/CHANGELOG.md index 35bfe1e1f5a..5b1f0874d1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fixed uninstall post-process. * Fixed `area_polygon` that was, in some cases, returning a negative area * Fixed support for `System.Decimal` data type on json serialization. +* Fixed `AttributeError` in Plotter's `PolylineArtist` and `SegementArtist`. +* Fixed wrong key type when de-serializing `Graph` with integer keys leading to node not found. +* Fixed bug in `VolMeshArtist.draw_cells` for Rhino, Blender and Grasshopper. +* Fixed bug in the `is_polygon_in_polygon_xy` that was not correctly generating all the edges of the second polygon before checking for intersections. ### Removed diff --git a/src/compas/datastructures/assembly/assembly.py b/src/compas/datastructures/assembly/assembly.py index 1d4b2a48db1..b1c08a5d3f6 100644 --- a/src/compas/datastructures/assembly/assembly.py +++ b/src/compas/datastructures/assembly/assembly.py @@ -58,14 +58,14 @@ def JSONSCHEMANAME(self): def data(self): data = { "attributes": self.attributes, - "graph": self.graph.data, + "graph": self.graph, } return data @data.setter def data(self, data): self.attributes.update(data["attributes"] or {}) - self.graph.data = data["graph"] + self.graph = data["graph"] self._parts = {part.guid: part.key for part in self.parts()} # ========================================================================== diff --git a/src/compas/geometry/predicates/predicates_2.py b/src/compas/geometry/predicates/predicates_2.py index 85e23410461..55f4c461e8b 100644 --- a/src/compas/geometry/predicates/predicates_2.py +++ b/src/compas/geometry/predicates/predicates_2.py @@ -383,7 +383,7 @@ def is_polygon_in_polygon_xy(polygon1, polygon2): for i in range(len(polygon1)): line = [polygon1[-i], polygon1[-i - 1]] for j in range(len(polygon2)): - line_ = [polygon2[-j], polygon2[j - 1]] + line_ = [polygon2[-j], polygon2[-j - 1]] if is_intersection_segment_segment_xy(line, line_): return False for pt in polygon2: diff --git a/src/compas_blender/artists/volmeshartist.py b/src/compas_blender/artists/volmeshartist.py index 84eb8317075..8e76fc55e73 100644 --- a/src/compas_blender/artists/volmeshartist.py +++ b/src/compas_blender/artists/volmeshartist.py @@ -310,7 +310,7 @@ def draw_cells( faces = self.volmesh.cell_faces(cell) vertex_index = dict((vertex, index) for index, vertex in enumerate(vertices)) vertices = [vertex_xyz[vertex] for vertex in vertices] - faces = [[vertex_index[vertex] for vertex in self.halfface_vertices(face)] for face in faces] + faces = [[vertex_index[vertex] for vertex in self.volmesh.halfface_vertices(face)] for face in faces] obj = compas_blender.draw_mesh( vertices, faces, diff --git a/src/compas_ghpython/artists/volmeshartist.py b/src/compas_ghpython/artists/volmeshartist.py index 4aa7e4bec07..db4065982e7 100644 --- a/src/compas_ghpython/artists/volmeshartist.py +++ b/src/compas_ghpython/artists/volmeshartist.py @@ -167,7 +167,7 @@ def draw_cells(self, cells=None, color=None): faces = self.volmesh.cell_faces(cell) vertex_index = dict((vertex, index) for index, vertex in enumerate(vertices)) vertices = [vertex_xyz[vertex] for vertex in vertices] - faces = [[vertex_index[vertex] for vertex in self.halfface_vertices(face)] for face in faces] + faces = [[vertex_index[vertex] for vertex in self.volmesh.halfface_vertices(face)] for face in faces] mesh = compas_ghpython.draw_mesh(vertices, faces, color=self.cell_color[cell].rgb255) meshes.append(mesh) return meshes diff --git a/src/compas_plotters/artists/polylineartist.py b/src/compas_plotters/artists/polylineartist.py index c3d5ad1e38a..779c9513df8 100644 --- a/src/compas_plotters/artists/polylineartist.py +++ b/src/compas_plotters/artists/polylineartist.py @@ -107,4 +107,4 @@ def redraw(self) -> None: self._mpl_line.set_xdata(x) self._mpl_line.set_ydata(y) self._mpl_line.set_color(self.color) - self._mpl_line.set_linewidth(self.width) + self._mpl_line.set_linewidth(self.linewidth) diff --git a/src/compas_plotters/artists/segmentartist.py b/src/compas_plotters/artists/segmentartist.py index 4367c6ffc79..adb2cdf903a 100644 --- a/src/compas_plotters/artists/segmentartist.py +++ b/src/compas_plotters/artists/segmentartist.py @@ -106,7 +106,7 @@ def redraw(self) -> None: self._mpl_line.set_xdata([self.line.start[0], self.line.end[0]]) self._mpl_line.set_ydata([self.line.start[1], self.line.end[1]]) self._mpl_line.set_color(self.color) - self._mpl_line.set_linewidth(self.width) + self._mpl_line.set_linewidth(self.linewidth) if self.draw_points: self._start_artist.redraw() self._end_artist.redraw() diff --git a/src/compas_rhino/artists/volmeshartist.py b/src/compas_rhino/artists/volmeshartist.py index 3772bf77eea..93e137b5196 100644 --- a/src/compas_rhino/artists/volmeshartist.py +++ b/src/compas_rhino/artists/volmeshartist.py @@ -268,7 +268,7 @@ def draw_cells(self, cells=None, color=None): faces = self.volmesh.cell_faces(cell) vertex_index = dict((vertex, index) for index, vertex in enumerate(vertices)) vertices = [vertex_xyz[vertex] for vertex in vertices] - faces = [[vertex_index[vertex] for vertex in self.halfface_vertices(face)] for face in faces] + faces = [[vertex_index[vertex] for vertex in self.volmesh.halfface_vertices(face)] for face in faces] guid = compas_rhino.draw_mesh( vertices, faces, diff --git a/tests/compas/datastructures/test_assembly.py b/tests/compas/datastructures/test_assembly.py index 66a94626dfe..01e5149acb3 100644 --- a/tests/compas/datastructures/test_assembly.py +++ b/tests/compas/datastructures/test_assembly.py @@ -1,5 +1,7 @@ import pytest +from compas.data import json_dumps +from compas.data import json_loads from compas.datastructures import Assembly from compas.datastructures import AssemblyError from compas.datastructures import Part @@ -69,9 +71,22 @@ def test_find_by_key(): assert assembly.find_by_key("100") is None -def test_find_by_key_after_deserialization(): +def test_find_by_key_after_from_data(): assembly = Assembly() part = Part() assembly.add_part(part, key=2) assembly = Assembly.from_data(assembly.to_data()) assert assembly.find_by_key(2) == part + + +def test_find_by_key_after_deserialization(): + assembly = Assembly() + part = Part(name="test_part") + assembly.add_part(part, key=2) + assembly = json_loads(json_dumps(assembly)) + + deserialized_part = assembly.find_by_key(2) + assert deserialized_part.name == part.name + assert deserialized_part.key == part.key + assert deserialized_part.guid == part.guid + assert deserialized_part.attributes == part.attributes diff --git a/tests/compas/geometry/predicates/test_predicates_2.py b/tests/compas/geometry/predicates/test_predicates_2.py index 310a1a0f617..56a528f0243 100644 --- a/tests/compas/geometry/predicates/test_predicates_2.py +++ b/tests/compas/geometry/predicates/test_predicates_2.py @@ -1,8 +1,9 @@ from compas.geometry import Circle from compas.geometry import Plane from compas.geometry import Point +from compas.geometry import Polygon from compas.geometry import Vector -from compas.geometry import is_point_in_circle_xy +from compas.geometry import is_point_in_circle_xy, is_polygon_in_polygon_xy def test_is_point_in_circle_xy(): @@ -24,3 +25,19 @@ def test_is_point_in_circle_xy_class_input(): pt_outside = Point(15, 15, 0) assert is_point_in_circle_xy(pt_outside, circle) is False + + +def test_is_polygon_in_polygon_xy(): + polygon_contour = Polygon([(0, 0, 0), (4, 2, 0), (10, 0, 0), (11, 10, 0), (8, 12, 0), (0, 10, 0)]) + polygon_inside = Polygon([(5, 5, 0), (10, 5, 0), (10, 10, 0), (5, 10, 0)]) + assert is_polygon_in_polygon_xy(polygon_contour, polygon_inside) + + polygon_outside = Polygon([(15, 5, 0), (20, 5, 0), (20, 10, 0), (15, 10, 0)]) + assert not is_polygon_in_polygon_xy(polygon_contour, polygon_outside) + + polygon_intersecting = Polygon([(10, 10, 0), (10, 5, 0), (15, 5, 0), (15, 10, 0)]) + assert not is_polygon_in_polygon_xy(polygon_contour, polygon_intersecting) + + # shifting the vertices list of the same polygon shouldn't affect the containment check output anymore + polygon_intersecting_shifted = Polygon(polygon_intersecting[1:] + polygon_intersecting[:1]) + assert not is_polygon_in_polygon_xy(polygon_contour, polygon_intersecting_shifted)