Skip to content

Commit 3d6b822

Browse files
authored
Merge pull request #374 from ebruun/duration_float_change
Duration class change, take float as sec variable
2 parents 899b061 + c56e047 commit 3d6b822

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

AUTHORS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ Authors
4747
* Beverly Lytle <[email protected]> `@beverlylytle <https://github.com/beverlylytle>`_
4848
* Yijiang Huang <[email protected]> `@yijiangh <https://github.com/yijiangh>`_
4949
* Chen Kasirer <[email protected]> `@chenkasirer <https://github.com/chenkasirer>`_
50+
* Edvard Bruun <[email protected]> `@ebruun <https://github.com/ebruun>`_
51+

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Unreleased
1919
**Changed**
2020

2121
* Changed behavior of ``Attach Tool`` GH component to only attach the tool but not add it to the planning scene state.
22+
* Duration class takes floats as ``sec`` variable
2223

2324
**Fixed**
2425

src/compas_fab/robots/time_.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,24 @@
88

99

1010
class Duration(object):
11-
"""Duration consists of two integers: seconds and nanoseconds.
11+
"""Duration consists of two values: seconds (float) and nanoseconds (int).
12+
The total number of seconds is the sum of these values.
13+
The decimal portion of the secs variable is converted to an integer and added to nsecs.
1214
1315
Attributes
1416
----------
15-
secs: int
16-
Integer representing number of seconds.
17+
secs: float
18+
Float representing number of seconds.
1719
nsecs: int
1820
Integer representing number of nanoseconds.
1921
"""
2022

2123
def __init__(self, secs, nsecs):
22-
self.secs = int(secs)
23-
self.nsecs = int(nsecs)
24+
sec_to_nano_factor = 1e9
25+
quotient, remainder = divmod(secs, 1)
26+
27+
self.secs = int(quotient)
28+
self.nsecs = int(remainder*sec_to_nano_factor) + int(nsecs)
2429

2530
def __str__(self):
2631
return 'Duration({!r}, {!r})'.format(self.secs, self.nsecs)

tests/robots/test_duration.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ def test_seconds():
66
assert d.seconds == 2.5
77

88

9-
def test_ctor_only_takes_integers():
10-
d = Duration(2.5, 5e+8)
11-
assert d.seconds == 2.5
9+
def test_ctor_takes_sec_as_float():
10+
d = Duration(2.6, 0)
11+
assert d.seconds == 2.6
12+
13+
14+
def test_sec_remainder_add_to_nsec():
15+
d = Duration(2.6, 5e+8)
16+
assert d.seconds == 3.1
1217

1318

1419
def test_repr():

0 commit comments

Comments
 (0)