compas-dev / compas_fab

Robotic fabrication package for the COMPAS Framework.
https://compas.dev/compas_fab/
MIT License
108 stars 32 forks source link

Fix Addition error in Duration() #417

Closed yck011522 closed 2 months ago

yck011522 commented 2 months ago

Changed the behavior of Duration class when accepting both seconds (float) and nanoseconds (int) where the decimal point of seconds and the nanoseconds add up to more than 1 second.

In the following test (existing), the total duration is expected to be 3.1 seconds.

def test_sec_remainder_add_to_nsec():
    d = Duration(2.6, 5e8)
    assert d.seconds == 3.1

However, existing implementation did not carry on the values from nsec to sec when the total value adds up. The following test explains the more desirable behavior:

def test_sec_remainder_add_to_nsec():
    d = Duration(2.6, 5e8)
    assert d.secs == 3
    assert d.nsecs == 1e8
    assert d.seconds == 3.1

What type of change is this?

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.