From 247a4608ee27fb95481af91e95a9439b81e7a702 Mon Sep 17 00:00:00 2001 From: Chen Kasirer Date: Mon, 10 Jul 2023 11:24:49 +0200 Subject: [PATCH 01/10] fixed wrong attribute name in plotter artists --- CHANGELOG.md | 1 + src/compas_plotters/artists/polylineartist.py | 2 +- src/compas_plotters/artists/segmentartist.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35bfe1e1f5a..5e293246fb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ 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`. ### Removed 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() From 35a6b7b33b54d2ba6da9756c4b0018bfbf09bc71 Mon Sep 17 00:00:00 2001 From: Chen Kasirer Date: Mon, 24 Jul 2023 18:18:39 +0200 Subject: [PATCH 02/10] fixed graph serialization in assembly --- CHANGELOG.md | 1 + src/compas/datastructures/assembly/assembly.py | 4 ++-- tests/compas/datastructures/test_assembly.py | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e293246fb4..f584964771b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * 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. ### 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/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 From e9aed45a01e285ec56509d035acc181ffcda2bac Mon Sep 17 00:00:00 2001 From: Gonzalo Casas Date: Tue, 13 Jun 2023 23:14:18 +0200 Subject: [PATCH 03/10] fix volmesh artists --- src/compas_blender/artists/volmeshartist.py | 2 +- src/compas_ghpython/artists/volmeshartist.py | 2 +- src/compas_rhino/artists/volmeshartist.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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_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, From e4bbf7c2ff50ce2fa8599dafbc2625d0cc4b8023 Mon Sep 17 00:00:00 2001 From: Gonzalo Casas Date: Tue, 13 Jun 2023 23:15:16 +0200 Subject: [PATCH 04/10] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f584964771b..bf2f7520c0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * 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. ### Removed From 88fc9c9956886b048510eaa1f89e3d956d53f40b Mon Sep 17 00:00:00 2001 From: baehrjo Date: Thu, 23 Mar 2023 12:25:33 +0100 Subject: [PATCH 05/10] bug fix on `is_polygon_in_polygon_xy` --- CHANGELOG.md | 1 + src/compas/geometry/predicates/predicates_2.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf2f7520c0f..5b1f0874d1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * 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/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: From fc4b9caf1dbb37606e5fcfb1134b98265342e61a Mon Sep 17 00:00:00 2001 From: baehrjo Date: Thu, 23 Mar 2023 16:27:31 +0100 Subject: [PATCH 06/10] add test to is_polygon_in_polygon_xy fix report --- .../geometry/predicates/test_predicates_2.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/compas/geometry/predicates/test_predicates_2.py b/tests/compas/geometry/predicates/test_predicates_2.py index 310a1a0f617..50cafdba3c9 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,16 @@ 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) is True + + polygon_outside = Polygon([(15, 5, 0), (20, 5, 0), (20, 10 ,0), (15, 10, 0)]) + assert is_polygon_in_polygon_xy(polygon_contour, polygon_outside) is False + + polygon_intersecting = Polygon([(10, 5, 0), (15, 5, 0), (15, 10 ,0), (10, 10, 0)]) + assert is_polygon_in_polygon_xy(polygon_contour, polygon_intersecting) is False + From 22a355d0fba21ed3d8c12ee1b84ce3886f73e565 Mon Sep 17 00:00:00 2001 From: baehrjo Date: Tue, 28 Mar 2023 18:13:31 +0200 Subject: [PATCH 07/10] comment test method --- tests/compas/geometry/predicates/test_predicates_2.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/compas/geometry/predicates/test_predicates_2.py b/tests/compas/geometry/predicates/test_predicates_2.py index 50cafdba3c9..0690de4b35b 100644 --- a/tests/compas/geometry/predicates/test_predicates_2.py +++ b/tests/compas/geometry/predicates/test_predicates_2.py @@ -35,6 +35,9 @@ def test_is_polygon_in_polygon_xy(): polygon_outside = Polygon([(15, 5, 0), (20, 5, 0), (20, 10 ,0), (15, 10, 0)]) assert is_polygon_in_polygon_xy(polygon_contour, polygon_outside) is False - polygon_intersecting = Polygon([(10, 5, 0), (15, 5, 0), (15, 10 ,0), (10, 10, 0)]) + polygon_intersecting = Polygon([(10, 10, 0), (10, 5, 0), (15, 5, 0), (15, 10 ,0)]) assert is_polygon_in_polygon_xy(polygon_contour, polygon_intersecting) is False - + + # 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 is_polygon_in_polygon_xy(polygon_contour, polygon_intersecting_shifted) is False \ No newline at end of file From 7b713b6e8019f9eb10c0d26bfaa716312bad3254 Mon Sep 17 00:00:00 2001 From: baehrjo Date: Tue, 28 Mar 2023 18:21:23 +0200 Subject: [PATCH 08/10] little lint check again --- tests/compas/geometry/predicates/test_predicates_2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/compas/geometry/predicates/test_predicates_2.py b/tests/compas/geometry/predicates/test_predicates_2.py index 0690de4b35b..c6d20bcb9a8 100644 --- a/tests/compas/geometry/predicates/test_predicates_2.py +++ b/tests/compas/geometry/predicates/test_predicates_2.py @@ -32,10 +32,10 @@ def test_is_polygon_in_polygon_xy(): 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) is True - polygon_outside = Polygon([(15, 5, 0), (20, 5, 0), (20, 10 ,0), (15, 10, 0)]) + polygon_outside = Polygon([(15, 5, 0), (20, 5, 0), (20, 10, 0), (15, 10, 0)]) assert is_polygon_in_polygon_xy(polygon_contour, polygon_outside) is False - polygon_intersecting = Polygon([(10, 10, 0), (10, 5, 0), (15, 5, 0), (15, 10 ,0)]) + polygon_intersecting = Polygon([(10, 10, 0), (10, 5, 0), (15, 5, 0), (15, 10, 0)]) assert is_polygon_in_polygon_xy(polygon_contour, polygon_intersecting) is False # shifting the vertices list of the same polygon shouldn't affect the containment check output anymore From dbdcb515be7396ee519f383304129607b012014d Mon Sep 17 00:00:00 2001 From: Tom Van Mele Date: Tue, 20 Jun 2023 16:18:23 +0200 Subject: [PATCH 09/10] Remove lint in test_predicates_2.py --- tests/compas/geometry/predicates/test_predicates_2.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/compas/geometry/predicates/test_predicates_2.py b/tests/compas/geometry/predicates/test_predicates_2.py index c6d20bcb9a8..7879e950980 100644 --- a/tests/compas/geometry/predicates/test_predicates_2.py +++ b/tests/compas/geometry/predicates/test_predicates_2.py @@ -29,15 +29,15 @@ def test_is_point_in_circle_xy_class_input(): 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) is True + 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 is_polygon_in_polygon_xy(polygon_contour, polygon_outside) is False + 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 is_polygon_in_polygon_xy(polygon_contour, polygon_intersecting) is False + 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 is_polygon_in_polygon_xy(polygon_contour, polygon_intersecting_shifted) is False \ No newline at end of file + assert not is_polygon_in_polygon_xy(polygon_contour, polygon_intersecting_shifted) From 9f5a476a25286bf77145a376dea5233503493c12 Mon Sep 17 00:00:00 2001 From: Tom Van Mele Date: Tue, 20 Jun 2023 17:15:16 +0200 Subject: [PATCH 10/10] Update test_predicates_2.py --- tests/compas/geometry/predicates/test_predicates_2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/compas/geometry/predicates/test_predicates_2.py b/tests/compas/geometry/predicates/test_predicates_2.py index 7879e950980..56a528f0243 100644 --- a/tests/compas/geometry/predicates/test_predicates_2.py +++ b/tests/compas/geometry/predicates/test_predicates_2.py @@ -29,7 +29,7 @@ def test_is_point_in_circle_xy_class_input(): 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)]) + 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)])