Skip to content

Commit db32ebc

Browse files
authored
Merge branch 'main' into meshobject
2 parents dd4b962 + a8ee4e2 commit db32ebc

File tree

31 files changed

+354
-5
lines changed

31 files changed

+354
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
* Added `_guid_mesh`, `_guids_vertices`, `_guids_edges`, `_guids_faces`, `_guids_vertexlabels`, `_guids_edgelables`, `_guids_facelabels`, `_guids_vertexnormals`, `_guids_facenormals`, `_guids_spheres`, `_guids_pipes`, `disjoint` attributes to `compas_rhino.scene.MeshObject`.
1414
* Added `_guids_nodes`, `_guids_edges`, `_guids_nodelabels`, `_guids_edgelables`, `_guids_spheres`, `_guids_pipes` attributes to `compas_rhino.scene.GraphObject`.
1515
* Added `_guids_vertices`, `_guids_edges`, `_guids_faces`, `_guids_cells`, `_guids_vertexlabels`, `_guids_edgelables`, `_guids_facelabels`, `_guids_celllabels`, `disjoint` attributes to `compas_rhino.scene.MeshObject`.
16+
* Added test for `compas.scene.Scene` serialisation.
1617

1718
### Changed
1819

1920
* Changed `compas.scene.Mesh`'s `show_vertices`, `show_edges`, `show_faces` to optionally accept a sequence of keys.
2021
* Changed `compas.scene.Graph`'s `show_nodes`, `show_edges` to optionally accept a sequence of keys.
2122
* Changed `compas.scene.VolMesh`'s `show_vertices`, `show_edges`, `show_faces`, `show_cells` to optionally accept a sequence of keys.
23+
* Fixed missing implementation of `Sphere.base`.
24+
* Fixed bug in `intersection_sphere_sphere`.
2225

2326
### Removed
2427

@@ -44,6 +47,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4447
* Added `compas_ghpython.unload_modules`.
4548
* Added `compas_ghpython.sets`.
4649
* Added `compas_ghpython.timer`.
50+
* Added `scale` and `scaled` to `compas.datastructures.Datastructure`.
51+
* Added `rotate` and `rotated` to `compas.datastructures.Datastructure`.
52+
* Added `translate` and `translated` to `compas.datastructures.Datastructure`.
4753

4854
### Changed
4955

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
attrs >=17.4
2-
black ==22.12.0
2+
black
33
bump2version >=1.0.1
44
check-manifest >=0.36
55
compas_invocations

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# flake8: noqa
2-
jsonschema >= 4.17, < 4.18
2+
jsonschema
33
networkx >= 3.0
44
numpy >= 1.15.4
55
scipy >= 1.1

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def read(*names, **kwargs):
4040
"Operating System :: Microsoft :: Windows",
4141
"Programming Language :: Python",
4242
"Programming Language :: Python :: 3",
43-
"Programming Language :: Python :: 3.7",
4443
"Programming Language :: Python :: 3.8",
4544
"Programming Language :: Python :: 3.9",
4645
"Programming Language :: Python :: 3.10",

src/compas/_iotools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""For the time being, these functions are only for internal use."""
2+
23
from contextlib import contextmanager
34
import io
45

src/compas/datastructures/_mutablemapping.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- https://github.com/compas-dev/compas/issues/562
1010
- https://github.com/compas-dev/compas/issues/649
1111
"""
12+
1213
from __future__ import absolute_import
1314
from __future__ import division
1415
from __future__ import print_function

src/compas/datastructures/datastructure.py

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
from __future__ import division
33
from __future__ import print_function
44

5+
try:
6+
from typing import TypeVar # noqa: F401
7+
except ImportError:
8+
pass
9+
else:
10+
G = TypeVar("G", bound="Datastructure")
11+
512
from compas.data import Data
613

714

@@ -77,3 +84,192 @@ def transformed_numpy(self, transformation):
7784
datastructure = self.copy()
7885
datastructure.transform_numpy(transformation)
7986
return datastructure
87+
88+
def scale(self, x, y=None, z=None):
89+
"""Scale the datastructure.
90+
91+
Parameters
92+
----------
93+
x : float
94+
The scaling factor in the x-direction.
95+
y : float, optional
96+
The scaling factor in the y-direction.
97+
Defaults to ``x``.
98+
z : float, optional
99+
The scaling factor in the z-direction.
100+
Defaults to ``x``.
101+
102+
Returns
103+
-------
104+
None
105+
106+
See Also
107+
--------
108+
scaled
109+
translate
110+
rotate
111+
transform
112+
113+
"""
114+
from compas.geometry import Scale
115+
116+
if y is None:
117+
y = x
118+
119+
if z is None:
120+
z = x
121+
122+
self.transform(Scale.from_factors([x, y, z]))
123+
124+
def scaled(self, x, y=None, z=None): # type: (...) -> G
125+
"""Returns a scaled copy of this geometry.
126+
127+
Parameters
128+
----------
129+
x : float
130+
The scaling factor in the x-direction.
131+
y : float, optional
132+
The scaling factor in the y-direction.
133+
Defaults to ``x``.
134+
z : float, optional
135+
The scaling factor in the z-direction.
136+
Defaults to ``x``.
137+
138+
Returns
139+
-------
140+
:class:`Geometry`
141+
The scaled geometry.
142+
143+
See Also
144+
--------
145+
scale
146+
translated
147+
rotated
148+
transformed
149+
150+
"""
151+
from compas.geometry import Scale
152+
153+
if y is None:
154+
y = x
155+
156+
if z is None:
157+
z = x
158+
159+
return self.transformed(Scale.from_factors([x, y, z]))
160+
161+
def translate(self, vector):
162+
"""Translate the datastructure.
163+
164+
Parameters
165+
----------
166+
vector : :class:`compas.geometry.Vector`
167+
The vector used to translate the datastructure.
168+
169+
Returns
170+
-------
171+
None
172+
173+
See Also
174+
--------
175+
translated
176+
rotate
177+
scale
178+
transform
179+
180+
"""
181+
from compas.geometry import Translation
182+
183+
self.transform(Translation.from_vector(vector))
184+
185+
def translated(self, vector): # type: (...) -> G
186+
"""Returns a translated copy of this geometry.
187+
188+
Parameters
189+
----------
190+
vector : :class:`compas.geometry.Vector`
191+
The vector used to translate the datastructure.
192+
193+
Returns
194+
-------
195+
:class:`Geometry`
196+
The translated geometry.
197+
198+
See Also
199+
--------
200+
translate
201+
rotated
202+
scaled
203+
transformed
204+
205+
"""
206+
from compas.geometry import Translation
207+
208+
return self.transformed(Translation.from_vector(vector))
209+
210+
def rotate(self, angle, axis=None, point=None):
211+
"""Rotate the datastructure.
212+
213+
Parameters
214+
----------
215+
angle : float
216+
The angle of rotation in radians.
217+
axis : :class:`compas.geometry.Vector`, optional
218+
The axis of rotation.
219+
Defaults to the z-axis.
220+
point : :class:`compas.geometry.Point`, optional
221+
The base point of the rotation axis.
222+
Defaults to the origin.
223+
224+
Returns
225+
-------
226+
None
227+
228+
See Also
229+
--------
230+
rotated
231+
translate
232+
scale
233+
transform
234+
235+
"""
236+
from compas.geometry import Rotation
237+
238+
if axis is None:
239+
axis = [0.0, 0.0, 1.0]
240+
241+
self.transform(Rotation.from_axis_and_angle(axis, angle, point))
242+
243+
def rotated(self, angle, axis=None, point=None): # type: (...) -> G
244+
"""Returns a rotated copy of this geometry.
245+
246+
Parameters
247+
----------
248+
angle : float
249+
The angle of rotation in radians.
250+
axis : :class:`compas.geometry.Vector`, optional
251+
The axis of rotation.
252+
Defaults to the z-axis.
253+
point : :class:`compas.geometry.Point`, optional
254+
The base point of the rotation axis.
255+
Defaults to the origin.
256+
257+
Returns
258+
-------
259+
:class:`Geometry`
260+
The rotated geometry.
261+
262+
See Also
263+
--------
264+
rotate
265+
translated
266+
scaled
267+
transformed
268+
269+
"""
270+
from compas.geometry import Rotation
271+
272+
if axis is None:
273+
axis = [0.0, 0.0, 1.0]
274+
275+
return self.transformed(Rotation.from_axis_and_angle(axis, angle, point))

src/compas/geometry/intersections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ def intersection_sphere_sphere(sphere1, sphere2):
495495
496496
"""
497497

498-
center1, radius1 = sphere1
499-
center2, radius2 = sphere2
498+
center1, radius1 = sphere1.base, sphere1.radius
499+
center2, radius2 = sphere2.base, sphere2.radius
500500

501501
distance = distance_point_point(center1, center2)
502502

src/compas/geometry/projection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Many thanks to Christoph Gohlke, Martin John Baker, Sachin Joglekar and Andrew
1111
Ippoliti for providing code and documentation.
1212
"""
13+
1314
from compas.utilities import flatten
1415
from compas.geometry import allclose
1516
from compas.geometry import decompose_matrix

src/compas/geometry/rotation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Many thanks to Christoph Gohlke, Martin John Baker, Sachin Joglekar and Andrew
1111
Ippoliti for providing code and documentation.
1212
"""
13+
1314
from compas.utilities import flatten
1415
from compas.geometry import normalize_vector
1516
from compas.geometry import cross_vectors

0 commit comments

Comments
 (0)