Skip to content

Commit 927a4e4

Browse files
authored
Merge pull request #1472 from compas-dev/fix-polyhedron-discretisation
Small fixes
2 parents bac708f + c13e0e4 commit 927a4e4

File tree

11 files changed

+117
-11
lines changed

11 files changed

+117
-11
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
* Added `compas.scene.Scene.add_group()` for adding group.
1313
* Added `compas.scene.Group.add_from_list()` for adding a list of items to a group.
14+
* Added implementation for `compas.geometry.SphericalSurface.isocurve_u`.
15+
* Added implementation for `compas.geometry.SphericalSurface.isocurve_v`.
16+
* Added implementation for `compas.geometry.CylindricalSurface.isocurve_u`.
17+
* Added implementation for `compas.geometry.CylindricalSurface.isocurve_v`.
1418

1519
### Changed
1620

1721
* Fixed error in `circle_to_compas` from Rhino.
1822
* Fixed Rhino to Rhino brep serialization.
1923
* Upated `compas.scene.Group.add()` to pass on group kwargs as default for child items.
24+
* Fixed bug in context detection, which wrongly defaults to `Viewer` instead of `None`.
25+
* Fixed bug in calculation of `compas.geometry.Polyhedron.edges` if geometry is computed using numpy.
26+
* Fixed bug in `Grpah.from_pointcloud` which uses degree parameter wrongly.
2027

2128
### Removed
2229

src/compas/datastructures/graph/graph.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from ast import literal_eval
66
from itertools import combinations
77
from random import sample
8+
from random import choice
9+
from random import shuffle
810

911
import compas
1012

@@ -159,7 +161,13 @@ def __from_data__(cls, data):
159161
graph._max_node = data.get("max_node", graph._max_node)
160162
return graph
161163

162-
def __init__(self, default_node_attributes=None, default_edge_attributes=None, name=None, **kwargs):
164+
def __init__(
165+
self,
166+
default_node_attributes=None,
167+
default_edge_attributes=None,
168+
name=None,
169+
**kwargs
170+
): # fmt: skip
163171
super(Graph, self).__init__(kwargs, name=name)
164172
self._max_node = -1
165173
self.node = {}
@@ -375,8 +383,16 @@ def from_pointcloud(cls, cloud, degree=3):
375383
graph = cls()
376384
for x, y, z in cloud:
377385
graph.add_node(x=x, y=y, z=z)
386+
nodes = list(graph.nodes())
378387
for u in graph.nodes():
379-
for v in graph.node_sample(size=degree):
388+
shuffle(nodes)
389+
for v in nodes:
390+
if v == u:
391+
continue
392+
if graph.degree(v) == degree:
393+
continue
394+
if graph.degree(u) == degree:
395+
break
380396
graph.add_edge(u, v)
381397
return graph
382398

src/compas/datastructures/mesh/mesh.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,14 @@ def __from_data__(cls, data):
229229

230230
return mesh
231231

232-
def __init__(self, default_vertex_attributes=None, default_edge_attributes=None, default_face_attributes=None, name=None, **kwargs): # fmt: skip
232+
def __init__(
233+
self,
234+
default_vertex_attributes=None,
235+
default_edge_attributes=None,
236+
default_face_attributes=None,
237+
name=None,
238+
**kwargs
239+
): # fmt: skip
233240
super(Mesh, self).__init__(kwargs, name=name)
234241
self._max_vertex = -1
235242
self._max_face = -1

src/compas/geometry/polyhedron.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ def faces(self, faces):
301301
def edges(self):
302302
seen = set()
303303
for face in self.faces:
304-
for u, v in pairwise(face + face[:1]):
304+
for i in range(-1, len(face) - 1):
305+
u = face[i]
306+
v = face[i + 1]
305307
if (u, v) not in seen:
306308
seen.add((u, v))
307309
seen.add((v, u))

src/compas/geometry/surfaces/cylindrical.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from compas.geometry import Circle
1010
from compas.geometry import Frame
11+
from compas.geometry import Line
1112
from compas.geometry import Point
1213
from compas.geometry import Vector
1314

@@ -162,6 +163,39 @@ def from_three_points(cls, a, b, c):
162163
# Methods
163164
# =============================================================================
164165

166+
def isocurve_u(self, u):
167+
"""Compute the isoparametric curve at parameter u.
168+
169+
Parameters
170+
----------
171+
u : float
172+
173+
Returns
174+
-------
175+
:class:`compas.geometry.Line`
176+
177+
"""
178+
base = self.point_at(u=u, v=0.5)
179+
return Line.from_point_direction_length(base, self.frame.zaxis, 1.0)
180+
181+
def isocurve_v(self, v):
182+
"""Compute the isoparametric curve at parameter v.
183+
184+
Parameters
185+
----------
186+
v : float
187+
188+
Returns
189+
-------
190+
:class:`compas.geometry.Circle`
191+
192+
"""
193+
point = self.center + self.frame.zaxis * v
194+
xaxis = self.frame.xaxis
195+
yaxis = self.frame.yaxis
196+
frame = Frame(point, xaxis, yaxis)
197+
return Circle(radius=self.radius, frame=frame)
198+
165199
def point_at(self, u, v, world=True):
166200
"""Compute a point on the surface at the given parameters.
167201

src/compas/geometry/surfaces/spherical.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,44 @@ def from_points(cls, points):
191191
# Methods
192192
# =============================================================================
193193

194+
def isocurve_u(self, u):
195+
"""Compute the isoparametric curve at parameter u.
196+
197+
Parameters
198+
----------
199+
u : float
200+
201+
Returns
202+
-------
203+
:class:`compas.geometry.Circle`
204+
205+
"""
206+
origin = self.center
207+
xaxis = self.point_at(u=u, v=0) - origin
208+
yaxis = self.point_at(u=u, v=0.25) - origin
209+
frame = Frame(origin, xaxis, yaxis)
210+
return Circle(radius=xaxis.length, frame=frame)
211+
212+
def isocurve_v(self, v):
213+
"""Compute the isoparametric curve at parameter v.
214+
215+
Parameters
216+
----------
217+
v : float
218+
219+
Returns
220+
-------
221+
:class:`compas.geometry.Circle`
222+
223+
"""
224+
x = self.point_at(u=0, v=v)
225+
y = self.point_at(u=0.25, v=v)
226+
origin = self.center + self.frame.zaxis * (x - self.center).dot(self.frame.zaxis)
227+
xaxis = x - origin
228+
yaxis = y - origin
229+
frame = Frame(origin, xaxis, yaxis)
230+
return Circle(radius=xaxis.length, frame=frame)
231+
194232
def point_at(self, u, v, world=True):
195233
"""Construct a point on the sphere.
196234

src/compas/geometry/surfaces/surface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def isocurve_v(self, v):
474474
475475
Returns
476476
-------
477-
:class:`compas_occ.geometry.Curve`
477+
:class:`compas.geometry.Curve`
478478
479479
"""
480480
raise NotImplementedError

src/compas/rpc/dispatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def _dispatch(self, name, args):
122122
try:
123123
idict = json.loads(args[0], cls=DataDecoder)
124124
except (IndexError, TypeError):
125-
odict["error"] = "API methods require a single JSON encoded dictionary as input.\n" "For example: input = json.dumps({'param_1': 1, 'param_2': [2, 3]})"
125+
odict["error"] = "API methods require a single JSON encoded dictionary as input.\nFor example: input = json.dumps({'param_1': 1, 'param_2': [2, 3]})"
126126

127127
else:
128128
self._call(function, idict, odict)

src/compas/scene/context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ def detect_current_context():
112112
return "Rhino"
113113
if compas.is_blender():
114114
return "Blender"
115-
other_contexts = [v for v in ITEM_SCENEOBJECT.keys()]
116-
if other_contexts:
117-
return other_contexts[0]
115+
# other_contexts = [v for v in ITEM_SCENEOBJECT.keys()]
116+
# if other_contexts:
117+
# return other_contexts[0]
118118

119119
return None
120120

tests/compas/datastructures/test_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_graph_from_pointcloud():
8383
graph = Graph.from_pointcloud(cloud=cloud, degree=3)
8484
assert graph.number_of_nodes() == len(cloud)
8585
for node in graph.nodes():
86-
assert graph.degree(node) >= 3
86+
assert graph.degree(node) <= 3
8787

8888

8989
# ==============================================================================

0 commit comments

Comments
 (0)