gazebosim / gz-math

General purpose math library for robot applications.
https://gazebosim.org/libs/math
Apache License 2.0
53 stars 62 forks source link

Color: Invariant for channels within `[0, 1]` is not strictly enforced; implicity divison is weird #200

Open EricCousineau-TRI opened 3 years ago

EricCousineau-TRI commented 3 years ago

Environment

Description

Came across this during @jennuine's resolution of https://github.com/osrf/sdformat/issues/193

This is due to the following code: https://github.com/ignitionrobotics/ign-math/blob/ad0118e689ba531c93df9c332e0c78a5dcd84e6e/src/Color.cc#L498-L511

Steps to reproduce

See code

Output

N/A

\cc @azeey

EricCousineau-TRI commented 3 years ago

Per @jennuine's analysis, this invariant is now enforced in libsdformat XML parsing (https://github.com/osrf/sdformat/pull/519), but due to this issue, it can leak in via DOM mutators.

jwnimmer-tri commented 2 years ago

What's even weirder is that the copy constructor keeps dividing again on each copy, in case it was still over the limit: https://github.com/ignitionrobotics/ign-math/blob/797f67f89c6863b5e02b6e7b24b6c587396cc614/src/Color.cc#L47-L51

Whichever of #283 or #286 merges will fix that part, though, by marked the copy constructor as defaulted.