Skip to content

Commit

Permalink
Merge pull request #1179 from compas-dev/lts-backports/sync-230905
Browse files Browse the repository at this point in the history
LTS backports/sync 230905
  • Loading branch information
gonzalocasas authored Sep 12, 2023
2 parents eb090a0 + 9f5a476 commit 35c9307
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/compas/datastructures/assembly/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}

# ==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/compas/geometry/predicates/predicates_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/compas_blender/artists/volmeshartist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/compas_ghpython/artists/volmeshartist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/compas_plotters/artists/polylineartist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/compas_plotters/artists/segmentartist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion src/compas_rhino/artists/volmeshartist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion tests/compas/datastructures/test_assembly.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
19 changes: 18 additions & 1 deletion tests/compas/geometry/predicates/test_predicates_2.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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)

0 comments on commit 35c9307

Please sign in to comment.