Skip to content

Commit 33b2e27

Browse files
committed
fix itertools linspace
1 parent a084f03 commit 33b2e27

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
* Fixed bug in `compas.robots.Configuration`.
2727
* Rebuild part index after deserialization in `Assembly`.
2828
* Fixed bug in `compas.artists.colordict.ColorDict`.
29-
* Change `Mesh.mesh_dual` with option of including the boundary.
29+
* Change `Mesh.mesh_dual` with option of including the boundary.
30+
* Fixed bug in `compas.utilities.linspace` for number series with high precision start and stop values.
3031

3132
### Removed
3233

src/compas/utilities/itertools.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717

1818
__all__ = [
19-
'normalize_values',
20-
'remap_values',
21-
'meshgrid',
22-
'linspace',
23-
'flatten',
24-
'pairwise',
25-
'window',
26-
'iterable_like',
27-
'grouper'
19+
"normalize_values",
20+
"remap_values",
21+
"meshgrid",
22+
"linspace",
23+
"flatten",
24+
"pairwise",
25+
"window",
26+
"iterable_like",
27+
"grouper",
2828
]
2929

3030

@@ -57,12 +57,14 @@ def normalize_values(values, new_min=0.0, new_max=1.0):
5757
"""
5858
old_max = max(values)
5959
old_min = min(values)
60-
old_range = (old_max - old_min)
61-
new_range = (new_max - new_min)
60+
old_range = old_max - old_min
61+
new_range = new_max - new_min
6262
return [(((value - old_min) * new_range) / old_range) + new_min for value in values]
6363

6464

65-
def remap_values(values, target_min=0.0, target_max=1.0, original_min=None, original_max=None):
65+
def remap_values(
66+
values, target_min=0.0, target_max=1.0, original_min=None, original_max=None
67+
):
6668
"""Maps a list of numbers from one domain to another.
6769
6870
Parameters
@@ -94,7 +96,7 @@ def remap_values(values, target_min=0.0, target_max=1.0, original_min=None, orig
9496
return [target_min + ((value - original_min) * ratio) for value in values]
9597

9698

97-
def meshgrid(x, y, indexing='xy'):
99+
def meshgrid(x, y, indexing="xy"):
98100
"""Construct coordinate matrices from two coordinate vectors.
99101
100102
Parameters
@@ -153,7 +155,7 @@ def meshgrid(x, y, indexing='xy'):
153155
"""
154156
x = list(x)
155157
y = list(y)
156-
if indexing == 'xy':
158+
if indexing == "xy":
157159
X = [[x[j] for j in range(len(x))] for i in range(len(y))]
158160
Y = [[y[i] for j in range(len(x))] for i in range(len(y))]
159161
else:
@@ -193,8 +195,9 @@ def linspace(start, stop, num=50):
193195
194196
"""
195197
step = (stop - start) / (num - 1)
196-
for i in range(num):
198+
for i in range(num - 1):
197199
yield start + i * step
200+
yield stop
198201

199202

200203
def flatten(list_of_lists):
@@ -364,8 +367,7 @@ def padnone(iterable):
364367

365368

366369
def grouper(iterable, n, fillvalue=None):
367-
"""Collect data into fixed-length chunks or blocks.
368-
"""
370+
"""Collect data into fixed-length chunks or blocks."""
369371
args = [iter(iterable)] * n
370372
return zip_longest(*args, fillvalue=fillvalue)
371373

0 commit comments

Comments
 (0)