Fix level alignment when levels have no measurements #212
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug fix
Fixed bug
Legacy traffic editor allows having levels with no measurements, it actually only uses measurements for the reference level and uses fiducials instead to compute the transform between other levels and the reference.
The code path would do a divide by 0 if there was a level with no measurements and result in a NaN alignment / silent failure in importing the project.
Fix applied
This PR makes sure we don't divide by 0 and initializes the scale to the same "sensible" default that is used in traffic editor (5 cm per pixel).
To test it, try to run the site editor and import https://github.com/open-rmf/roscon_workshop/blob/main/roscon_maps/maps/workshop/workshop.building.yaml before and after this PR. The first will panic (panic is actually caused by an external library when we pass it NaN values, not the site editor), with the PR it should load correctly.
I checked and the map seems to be imported with the same scale as traffic editor after the fix.