Throw an error if multiple orientation specifiers are used in the same element.

- Applies to [orientation specifiers](https://mujoco.readthedocs.io/en/latest/modeling.html#frame-orientations) in `body`, `inertial`, `geom`, `site`, `camera`.
- Before this change the check was done only for multiple *alternative* specifiers, but not for `quat` and an alternative specifier.
- Moved the check from the compiler to the parser.
- Added tests.

PiperOrigin-RevId: 453201981
Change-Id: I20907361f211dae904e734cd083e9df0efe4f654
This commit is contained in:
Alessio Quaglino
2022-06-06 08:12:32 -07:00
committed by Copybara-Service
parent 652bab3eec
commit 16baac9353
4 changed files with 52 additions and 16 deletions
+8 -5
View File
@@ -52,9 +52,12 @@ void mjXBase::SetModel(mjCModel* _model) {
// read alternative orientation specification
void mjXBase::ReadAlternative(XMLElement* elem, mjCAlternative& alt) {
string text;
ReadAttr(elem, "axisangle", 4, alt.axisangle, text);
ReadAttr(elem, "xyaxes", 6, alt.xyaxes, text);
ReadAttr(elem, "zaxis", 3, alt.zaxis, text);
ReadAttr(elem, "euler", 3, alt.euler, text);
ReadAttr(elem, "fullinertia", 6, alt.fullinertia, text);
int read = (int)(elem->Attribute("quat") != 0) +
(ReadAttr(elem, "axisangle", 4, alt.axisangle, text) ? 1 : 0) +
(ReadAttr(elem, "xyaxes", 6, alt.xyaxes, text) ? 1 : 0) +
(ReadAttr(elem, "zaxis", 3, alt.zaxis, text) ? 1 : 0) +
(ReadAttr(elem, "euler", 3, alt.euler, text) ? 1 : 0) +
(ReadAttr(elem, "fullinertia", 6, alt.fullinertia, text) ? 1 : 0);
if (read > 1)
throw mjXError(elem, "multiple orientation specifiers for the same field are not allowed");
}