Skip to content

Commit 2bead6e

Browse files
committed
use default values other than None for compound objects
1 parent 0f8abaf commit 2bead6e

File tree

5 files changed

+56
-58
lines changed

5 files changed

+56
-58
lines changed

src/compas_rhino/geometry/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
66
.. currentmodule:: compas_rhino.geometry
77
8-
.. rst-class:: lead
9-
10-
Wrappers for Rhino objects that can be used to convert Rhino geometry and data to COMPAS objects.
11-
128
Classes
139
=======
1410

src/compas_rhino/objects/__init__.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,16 @@
55
66
.. currentmodule:: compas_rhino.objects
77
8+
Classes
9+
=======
810
9-
NetworkObject
10-
=============
11-
12-
.. autoclass:: NetworkObject
13-
:members: clear, draw, select_nodes, select_edges, modify_nodes, modify_edges
14-
:no-show-inheritance:
15-
16-
----
17-
18-
MeshObject
19-
==========
20-
21-
.. autoclass:: MeshObject
22-
:members: clear, draw, select_vertices, select_faces, select_edges, modify_vertices, modify_faces, modify_edges
23-
:no-show-inheritance:
24-
25-
----
26-
27-
VolMeshObject
28-
=============
29-
30-
.. autoclass:: VolMeshObject
31-
:members: clear, draw, select_vertices, select_faces, select_edges, modify_vertices, modify_faces, modify_edges
32-
:no-show-inheritance:
11+
.. autosummary::
12+
:toctree: generated/
13+
:nosignatures:
3314
15+
MeshObject
16+
NetworkObject
17+
VolMeshObject
3418
3519
"""
3620
from __future__ import absolute_import

src/compas_rhino/objects/meshobject.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ def location(self):
120120
Setting this location will make a copy of the provided point object.
121121
Moving the original point will thus not affect the object's location.
122122
"""
123+
if not self._location:
124+
self._location = Point(0, 0, 0)
123125
return self._location
124126

125127
@location.setter
@@ -132,6 +134,8 @@ def scale(self):
132134
A uniform scaling factor for the object in the scene.
133135
The scale is applied relative to the location of the object in the scene.
134136
"""
137+
if not self._scale:
138+
self._scale = 1
135139
return self._scale
136140

137141
@scale.setter
@@ -144,6 +148,8 @@ def rotation(self):
144148
The rotation angles around the 3 axis of the coordinate system
145149
with the origin placed at the location of the object in the scene.
146150
"""
151+
if not self._rotation:
152+
self._rotation = [0, 0, 0]
147153
return self._rotation
148154

149155
@rotation.setter
@@ -153,24 +159,24 @@ def rotation(self, rotation):
153159
@property
154160
def vertex_xyz(self):
155161
"""dict: The view coordinates of the mesh object."""
162+
origin = Point(0, 0, 0)
156163
stack = []
157-
if self.anchor is not None and self.location is not None:
158-
xyz = self.mesh.vertex_attributes(self.anchor, 'xyz')
159-
origin = Point(0, 0, 0)
160-
point = Point(* xyz)
161-
T1 = Translation.from_vector(origin - point)
162-
stack.append(T1)
163-
if self.scale is not None:
164+
if self.scale != 1:
164165
S = Scale.from_factors([self.scale] * 3)
165166
stack.append(S)
166-
if self.rotation is not None:
167+
if self.rotation != [0, 0, 0]:
167168
R = Rotation.from_euler_angles(self.rotation)
168169
stack.append(R)
169-
if self.location is not None:
170+
if self.location != origin:
171+
if self.anchor is not None:
172+
xyz = self.mesh.vertex_attributes(self.anchor, 'xyz')
173+
point = Point(* xyz)
174+
T1 = Translation.from_vector(origin - point)
175+
stack.insert(0, T1)
170176
T2 = Translation.from_vector(self.location)
171177
stack.append(T2)
172178
if stack:
173-
X = reduce(mul, stack)
179+
X = reduce(mul, stack[::-1])
174180
mesh = self.mesh.transformed(X)
175181
else:
176182
mesh = self.mesh

src/compas_rhino/objects/networkobject.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def location(self):
9696
Setting this location will make a copy of the provided point object.
9797
Moving the original point will thus not affect the object's location.
9898
"""
99+
if not self._location:
100+
self._location = Point(0, 0, 0)
99101
return self._location
100102

101103
@location.setter
@@ -108,6 +110,8 @@ def scale(self):
108110
A uniform scaling factor for the object in the scene.
109111
The scale is applied relative to the location of the object in the scene.
110112
"""
113+
if not self._scale:
114+
self._scale = 1.0
111115
return self._scale
112116

113117
@scale.setter
@@ -120,6 +124,8 @@ def rotation(self):
120124
The rotation angles around the 3 axis of the coordinate system
121125
with the origin placed at the location of the object in the scene.
122126
"""
127+
if not self._rotation:
128+
self._rotation = [0, 0, 0]
123129
return self._rotation
124130

125131
@rotation.setter
@@ -129,24 +135,24 @@ def rotation(self, rotation):
129135
@property
130136
def node_xyz(self):
131137
"""dict : The view coordinates of the mesh object."""
138+
origin = Point(0, 0, 0)
132139
stack = []
133-
if self.anchor is not None and self.location is not None:
134-
xyz = self.network.vertex_attributes(self.anchor, 'xyz')
135-
origin = Point(0, 0, 0)
136-
point = Point(* xyz)
137-
T1 = Translation.from_vector(origin - point)
138-
stack.append(T1)
139-
if self.scale is not None:
140+
if self.scale != 1.0:
140141
S = Scale.from_factors([self.scale] * 3)
141142
stack.append(S)
142-
if self.rotation is not None:
143+
if self.rotation != [0, 0, 0]:
143144
R = Rotation.from_euler_angles(self.rotation)
144145
stack.append(R)
145-
if self.location is not None:
146+
if self.location != origin:
147+
if self.anchor is not None:
148+
xyz = self.network.vertex_attributes(self.anchor, 'xyz')
149+
point = Point(* xyz)
150+
T1 = Translation.from_vector(origin - point)
151+
stack.insert(0, T1)
146152
T2 = Translation.from_vector(self.location)
147153
stack.append(T2)
148154
if stack:
149-
X = reduce(mul, stack)
155+
X = reduce(mul, stack[::-1])
150156
network = self.network.transformed(X)
151157
else:
152158
network = self.network

src/compas_rhino/objects/volmeshobject.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def location(self):
110110
Setting this location will make a copy of the provided point object.
111111
Moving the original point will thus not affect the object's location.
112112
"""
113+
if not self._location:
114+
self._location = Point(0, 0, 0)
113115
return self._location
114116

115117
@location.setter
@@ -122,6 +124,8 @@ def scale(self):
122124
A uniform scaling factor for the object in the scene.
123125
The scale is applied relative to the location of the object in the scene.
124126
"""
127+
if not self._scale:
128+
self._scale = 1.0
125129
return self._scale
126130

127131
@scale.setter
@@ -134,6 +138,8 @@ def rotation(self):
134138
The rotation angles around the 3 axis of the coordinate system
135139
with the origin placed at the location of the object in the scene.
136140
"""
141+
if not self._rotation:
142+
self._rotation = [0, 0, 0]
137143
return self._rotation
138144

139145
@rotation.setter
@@ -143,24 +149,24 @@ def rotation(self, rotation):
143149
@property
144150
def vertex_xyz(self):
145151
"""dict : The view coordinates of the volmesh object."""
152+
origin = Point(0, 0, 0)
146153
stack = []
147-
if self.anchor is not None and self.location is not None:
148-
xyz = self.volmesh.vertex_attributes(self.anchor, 'xyz')
149-
origin = Point(0, 0, 0)
150-
point = Point(* xyz)
151-
T1 = Translation.from_vector(origin - point)
152-
stack.append(T1)
153-
if self.scale is not None:
154+
if self.scale != 1.0:
154155
S = Scale.from_factors([self.scale] * 3)
155156
stack.append(S)
156-
if self.rotation is not None:
157+
if self.rotation != [0, 0, 0]:
157158
R = Rotation.from_euler_angles(self.rotation)
158159
stack.append(R)
159-
if self.location is not None:
160+
if self.location != origin:
161+
if self.anchor is not None:
162+
xyz = self.volmesh.vertex_attributes(self.anchor, 'xyz')
163+
point = Point(* xyz)
164+
T1 = Translation.from_vector(origin - point)
165+
stack.insert(0, T1)
160166
T2 = Translation.from_vector(self.location)
161167
stack.append(T2)
162168
if stack:
163-
X = reduce(mul, stack)
169+
X = reduce(mul, stack[::-1])
164170
volmesh = self.volmesh.transformed(X)
165171
else:
166172
volmesh = self.volmesh

0 commit comments

Comments
 (0)