Skip to content

Commit

Permalink
--change test of UserDefined attributes to test for Vector4 and not quat
Browse files Browse the repository at this point in the history
For a ConfigValue populated from JSON to be saved as a quaternion, it has to be pre-initialized to be a Quat.
  • Loading branch information
jturner65 committed May 25, 2022
1 parent baab754 commit e10ee6f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 40 deletions.
18 changes: 7 additions & 11 deletions src/esp/metadata/attributes/SceneInstanceAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ class SceneObjectInstanceAttributes : public AbstractAttributes {
* @brief Set the translation from the origin of the described
* stage/object instance.
*/
void setTranslation(const Magnum::Vector3& translation) {
void setTranslation(const Mn::Vector3& translation) {
set("translation", translation);
}
/**
* @brief Get the translation from the origin of the described
* stage/object instance.
*/
Magnum::Vector3 getTranslation() const {
return get<Magnum::Vector3>("translation");
}
Mn::Vector3 getTranslation() const { return get<Mn::Vector3>("translation"); }

/**
* @brief Set a value representing the mechanism used to create this scene
Expand Down Expand Up @@ -92,15 +90,13 @@ class SceneObjectInstanceAttributes : public AbstractAttributes {
/**
* @brief Set the rotation of the object
*/
void setRotation(const Magnum::Quaternion& rotation) {
void setRotation(const Mn::Quaternion& rotation) {
set("rotation", rotation);
}
/**
* @brief Get the rotation of the object
*/
Magnum::Quaternion getRotation() const {
return get<Magnum::Quaternion>("rotation");
}
Mn::Quaternion getRotation() const { return get<Mn::Quaternion>("rotation"); }

/**
* @brief If not visible can add dynamic non-rendered object into a scene
Expand Down Expand Up @@ -181,15 +177,15 @@ class SceneObjectInstanceAttributes : public AbstractAttributes {
* @brief Get the non-uniform scale vector of the described stage/object
* instance.
*/
Magnum::Vector3 getNonUniformScale() const {
return get<Magnum::Vector3>("non_uniform_scale");
Mn::Vector3 getNonUniformScale() const {
return get<Mn::Vector3>("non_uniform_scale");
}

/**
* @brief Set the non-uniform scale vector of the described stage/object
* instance.
*/
void setNonUniformScale(const Magnum::Vector3& non_uniform_scale) {
void setNonUniformScale(const Mn::Vector3& non_uniform_scale) {
set("non_uniform_scale", non_uniform_scale);
}

Expand Down
60 changes: 31 additions & 29 deletions src/tests/AttributesConfigsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ struct AttributesConfigsTest : Cr::TestSuite::Tester {
* @param bool_val Expected boolean value
* @param double_val Exptected double value
* @param vec_val Expected Magnum::Vector3 value
* @param quat_val Expected Quaternion value - note that the JSON is read
* @param vec4_val Expected Magnum::Vector4 value
*
*
* Expected Quaternion value - note that the JSON is read
* with scalar at idx 0, whereas the quaternion constructor takes the vector
* component in the first position and the scalar in the second.
*/
Expand All @@ -101,7 +104,7 @@ struct AttributesConfigsTest : Cr::TestSuite::Tester {
int int_val,
double double_val,
Magnum::Vector3 vec_val,
Magnum::Quaternion quat_val);
Magnum::Vector4 vec4_val);

/**
* @brief This test will verify that the physics attributes' managers' JSON
Expand Down Expand Up @@ -228,7 +231,7 @@ void AttributesConfigsTest::testUserDefinedConfigVals(
int int_val,
double double_val,
Magnum::Vector3 vec_val,
Magnum::Quaternion quat_val) {
Magnum::Vector4 vec4_val) {
// user defined attributes from light instance
CORRADE_VERIFY(userConfig);
CORRADE_COMPARE(userConfig->get<std::string>("user_string"), str_val);
Expand All @@ -242,7 +245,7 @@ void AttributesConfigsTest::testUserDefinedConfigVals(
"`user_double`.";
}
CORRADE_COMPARE(userConfig->get<Magnum::Vector3>("user_vec3"), vec_val);
CORRADE_COMPARE(userConfig->get<Magnum::Quaternion>("user_quat"), quat_val);
CORRADE_COMPARE(userConfig->get<Magnum::Vector4>("user_vec4"), vec4_val);

} // AttributesConfigsTest::testUserDefinedConfigVals

Expand All @@ -262,7 +265,7 @@ void AttributesConfigsTest::testPhysicsAttrVals(
testUserDefinedConfigVals(physMgrAttr->getUserConfiguration(),
"pm defined string", true, 15, 12.6,
Magnum::Vector3(215.4, 217.6, 2110.1),
Magnum::Quaternion({5.2f, 6.2f, 7.2f}, 0.2f));
Magnum::Vector4(0.2f, 5.2f, 6.2f, 7.2f));
// remove added template
// remove json-string built attributes added for test
testRemoveAttributesBuiltByJSONString(physicsAttributesManager_,
Expand All @@ -285,7 +288,7 @@ void AttributesConfigsTest::testPhysicsJSONLoad() {
"user_int" : 15,
"user_double" : 12.6,
"user_vec3" : [215.4, 217.6, 2110.1],
"user_quat" : [0.2, 5.2, 6.2, 7.2]
"user_vec4" : [0.2, 5.2, 6.2, 7.2]
}
})";
auto physMgrAttr =
Expand Down Expand Up @@ -336,7 +339,7 @@ void AttributesConfigsTest::testLightAttrVals(
testUserDefinedConfigVals(lightLayoutAttr->getUserConfiguration(),
"light attribs defined string", true, 23, 2.3,
Magnum::Vector3(1.1, 3.3, 5.5),
Magnum::Quaternion({0.6f, 0.7f, 0.8f}, 0.5f));
Magnum::Vector4(0.5f, 0.6f, 0.7f, 0.8f));
CORRADE_COMPARE(lightLayoutAttr->getPositiveIntensityScale(), 2.0);
CORRADE_COMPARE(lightLayoutAttr->getNegativeIntensityScale(), 1.5);
auto lightAttr0 = lightLayoutAttr->getLightInstance("test0");
Expand Down Expand Up @@ -375,7 +378,7 @@ void AttributesConfigsTest::testLightAttrVals(
testUserDefinedConfigVals(lightAttr1->getUserConfiguration(),
"light instance defined string", false, 42, 1.2,
Magnum::Vector3(0.1, 2.3, 4.5),
Magnum::Quaternion({0.2f, 0.3f, 0.4f}, 0.1f));
Magnum::Vector4(0.1f, 0.2f, 0.3f, 0.4f));

// remove json-string built attributes added for test
testRemoveAttributesBuiltByJSONString(lightLayoutAttributesManager_,
Expand Down Expand Up @@ -412,7 +415,7 @@ void AttributesConfigsTest::testLightJSONLoad() {
"user_int" : 42,
"user_double" : 1.2,
"user_vec3" : [0.1, 2.3, 4.5],
"user_quat" : [0.1, 0.2, 0.3, 0.4]
"user_vec4" : [0.1, 0.2, 0.3, 0.4]
}
}
},
Expand All @@ -422,7 +425,7 @@ void AttributesConfigsTest::testLightJSONLoad() {
"user_int" : 23,
"user_double" : 2.3,
"user_vec3" : [1.1, 3.3, 5.5],
"user_quat" : [0.5, 0.6, 0.7, 0.8]
"user_vec4" : [0.5, 0.6, 0.7, 0.8]
},
"positive_intensity_scale" : 2.0,
"negative_intensity_scale" : 1.5
Expand Down Expand Up @@ -484,7 +487,7 @@ void AttributesConfigsTest::testSceneInstanceAttrVals(
testUserDefinedConfigVals(sceneAttr->getUserConfiguration(),
"scene instance defined string", true, 99, 9.1,
Magnum::Vector3(12.3, 32.5, 25.07),
Magnum::Quaternion({3.2f, 2.6f, 5.1f}, 0.3f));
Magnum::Vector4(0.3f, 3.2f, 2.6f, 5.1f));

// verify objects
auto objectInstanceList = sceneAttr->getObjectInstances();
Expand All @@ -506,7 +509,7 @@ void AttributesConfigsTest::testSceneInstanceAttrVals(
testUserDefinedConfigVals(objInstance->getUserConfiguration(),
"obj0 instance defined string", false, 12, 2.3,
Magnum::Vector3(1.3, 3.5, 5.7),
Magnum::Quaternion({0.2f, 0.6f, 0.1f}, 0.3f));
Magnum::Vector4(0.3f, 0.2f, 0.6f, 0.1f));

objInstance = objectInstanceList[1];
CORRADE_COMPARE(objInstance->getHandle(), "test_object_template1");
Expand All @@ -523,7 +526,7 @@ void AttributesConfigsTest::testSceneInstanceAttrVals(
testUserDefinedConfigVals(objInstance->getUserConfiguration(),
"obj1 instance defined string", false, 1, 1.1,
Magnum::Vector3(10.3, 30.5, -5.07),
Magnum::Quaternion({1.2f, 1.6f, 1.1f}, 1.3f));
Magnum::Vector4(1.3f, 1.2f, 1.6f, 1.1f));

// verify articulated object instances
auto artObjInstances = sceneAttr->getArticulatedObjectInstances();
Expand Down Expand Up @@ -562,7 +565,7 @@ void AttributesConfigsTest::testSceneInstanceAttrVals(
"test_urdf_template0 instance defined string",
false, 2, 1.22,
Magnum::Vector3(120.3f, 302.5f, -25.07f),
Magnum::Quaternion({1.22f, 1.26f, 1.21f}, 1.23f));
Magnum::Vector4(1.23f, 1.22f, 1.26f, 1.21f));

// test nested configuration
auto artObjNestedConfig =
Expand All @@ -587,7 +590,7 @@ void AttributesConfigsTest::testSceneInstanceAttrVals(
"test_urdf_template1 instance defined string",
false, 21, 11.22,
Magnum::Vector3(190.3f, 902.5f, -95.07f),
Magnum::Quaternion({9.22f, 9.26f, 0.21f}, 1.25f));
Magnum::Vector4(1.25f, 9.22f, 9.26f, 0.21f));
// verify stage populated properly
auto stageInstance = sceneAttr->getStageInstance();
CORRADE_COMPARE(stageInstance->getHandle(), "test_stage_template");
Expand All @@ -605,7 +608,7 @@ void AttributesConfigsTest::testSceneInstanceAttrVals(
testUserDefinedConfigVals(stageInstance->getUserConfiguration(),
"stage instance defined string", true, 11, 2.2,
Magnum::Vector3(1.2, 3.4, 5.6),
Magnum::Quaternion({0.5f, 0.6f, 0.7f}, 0.4f));
Magnum::Vector4(0.4f, 0.5f, 0.6f, 0.7f));

// remove json-string built attributes added for test
testRemoveAttributesBuiltByJSONString(sceneInstanceAttributesManager_,
Expand All @@ -629,7 +632,7 @@ void AttributesConfigsTest::testSceneInstanceJSONLoad() {
"user_int" : 11,
"user_double" : 2.2,
"user_vec3" : [1.2, 3.4, 5.6],
"user_quat" : [0.4, 0.5, 0.6, 0.7]
"user_vec4" : [0.4, 0.5, 0.6, 0.7]
}
},
"object_instances": [
Expand All @@ -647,7 +650,7 @@ void AttributesConfigsTest::testSceneInstanceJSONLoad() {
"user_int" : 12,
"user_double" : 2.3,
"user_vec3" : [1.3, 3.5, 5.7],
"user_quat" : [0.3, 0.2, 0.6, 0.1]
"user_vec4" : [0.3, 0.2, 0.6, 0.1]
}
},
{
Expand All @@ -663,7 +666,7 @@ void AttributesConfigsTest::testSceneInstanceJSONLoad() {
"user_int" : 1,
"user_double" : 1.1,
"user_vec3" : [10.3, 30.5, -5.07],
"user_quat" : [1.3, 1.2, 1.6, 1.1]
"user_vec4" : [1.3, 1.2, 1.6, 1.1]
}
}
],
Expand All @@ -684,7 +687,7 @@ void AttributesConfigsTest::testSceneInstanceJSONLoad() {
"user_int" : 2,
"user_double" : 1.22,
"user_vec3" : [120.3, 302.5, -25.07],
"user_quat" : [1.23, 1.22, 1.26, 1.21],
"user_vec4" : [1.23, 1.22, 1.26, 1.21],
"user_def_obj" : {
"position" : [0.1, 0.2, 0.3],
"rotation" : [0.5, 0.3, 0.1]
Expand All @@ -704,7 +707,7 @@ void AttributesConfigsTest::testSceneInstanceJSONLoad() {
"user_int" : 21,
"user_double" : 11.22,
"user_vec3" : [190.3, 902.5, -95.07],
"user_quat" : [1.25, 9.22, 9.26, 0.21]
"user_vec4" : [1.25, 9.22, 9.26, 0.21]
}
}
],
Expand All @@ -717,7 +720,7 @@ void AttributesConfigsTest::testSceneInstanceJSONLoad() {
"user_int" : 99,
"user_double" : 9.1,
"user_vec3" : [12.3, 32.5, 25.07],
"user_quat" : [0.3, 3.2, 2.6, 5.1]
"user_vec4" : [0.3, 3.2, 2.6, 5.1]
}
})";

Expand Down Expand Up @@ -794,10 +797,9 @@ void AttributesConfigsTest::testStageAttrVals(
CORRADE_COMPARE(stageAttr->getSemanticAssetHandle(), assetPath);
CORRADE_COMPARE(stageAttr->getNavmeshAssetHandle(), assetPath);
// test stage attributes-level user config vals
testUserDefinedConfigVals(stageAttr->getUserConfiguration(),
"stage defined string", false, 3, 0.8,
Magnum::Vector3(5.4, 7.6, 10.1),
Magnum::Quaternion({1.5f, 2.6f, 3.7f}, 0.1f));
testUserDefinedConfigVals(
stageAttr->getUserConfiguration(), "stage defined string", false, 3, 0.8,
Magnum::Vector3(5.4, 7.6, 10.1), Magnum::Vector4(0.1f, 1.5f, 2.6f, 3.7f));

// remove json-string built attributes added for test
testRemoveAttributesBuiltByJSONString(stageAttributesManager_,
Expand Down Expand Up @@ -830,7 +832,7 @@ void AttributesConfigsTest::testStageJSONLoad() {
"user_int" : 3,
"user_double" : 0.8,
"user_vec3" : [5.4, 7.6, 10.1],
"user_quat" : [0.1, 1.5, 2.6, 3.7]
"user_vec4" : [0.1, 1.5, 2.6, 3.7]
}
})";

Expand Down Expand Up @@ -923,7 +925,7 @@ void AttributesConfigsTest::testObjectAttrVals(
testUserDefinedConfigVals(objAttr->getUserConfiguration(),
"object defined string", true, 5, 2.6,
Magnum::Vector3(15.4, 17.6, 110.1),
Magnum::Quaternion({5.5f, 6.6f, 7.7f}, 0.7f));
Magnum::Vector4(0.7f, 5.5f, 6.6f, 7.7f));

// remove json-string built attributes added for test
testRemoveAttributesBuiltByJSONString(objectAttributesManager_,
Expand Down Expand Up @@ -958,7 +960,7 @@ void AttributesConfigsTest::testObjectJSONLoad() {
"user_int" : 5,
"user_double" : 2.6,
"user_vec3" : [15.4, 17.6, 110.1],
"user_quat" : [0.7, 5.5, 6.6, 7.7]
"user_vec4" : [0.7, 5.5, 6.6, 7.7]
}
})";
auto objAttr =
Expand Down

0 comments on commit e10ee6f

Please sign in to comment.