Skip to content

Commit

Permalink
Format code.
Browse files Browse the repository at this point in the history
- Removed unnecessary whitespace in ManyBoneIK3D::_bind_methods()
- Removed empty line at the end of ManyBoneIK3D::ManyBoneIK3D()
- Removed empty line at the end of void ManyBoneIK3D::add_constraint() in many_bone_ik_3d.cpp
- Updated indentation and spacing in test cases in test_ik_node_3d.h
- Updated indentation and spacing in test cases in test_qcp.h
  • Loading branch information
fire committed Nov 5, 2023
1 parent b8f59da commit 63bcf47
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 106 deletions.
3 changes: 1 addition & 2 deletions src/many_bone_ik_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void ManyBoneIK3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "constraint_mode"), "set_constraint_mode", "get_constraint_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "ui_selected_bone", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_ui_selected_bone", "get_ui_selected_bone");
ADD_PROPERTY(PropertyInfo(Variant::INT, "stabilization_passes"), "set_stabilization_passes", "get_stabilization_passes");
}
}

ManyBoneIK3D::ManyBoneIK3D() {
}
Expand Down Expand Up @@ -1166,4 +1166,3 @@ void ManyBoneIK3D::add_constraint() {
bone_resistance.write[old_count] = 0.0f;
set_dirty();
}

78 changes: 39 additions & 39 deletions tests/test_ik_node_3d.h
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
#ifndef TEST_IKNODE3D_H
#define TEST_IKNODE3D_H

#include "tests/test_macros.h"
#include "modules/many_bone_ik/src/math/ik_node_3d.h"
#include "tests/test_macros.h"

namespace TestIKNode3D {

TEST_CASE("[Modules][IKNode3D] Transform operations") {
Ref<IKNode3D> node = memnew(IKNode3D);

// Test set_transform and get_transform
Transform3D t;
t.origin = Vector3(1, 2, 3);
node->set_transform(t);
CHECK(node->get_transform() == t);

// Test set_global_transform and get_global_transform
Transform3D gt;
gt.origin = Vector3(4, 5, 6);
node->set_global_transform(gt);
CHECK(node->get_global_transform() == gt);
Ref<IKNode3D> node = memnew(IKNode3D);

// Test set_transform and get_transform
Transform3D t;
t.origin = Vector3(1, 2, 3);
node->set_transform(t);
CHECK(node->get_transform() == t);

// Test set_global_transform and get_global_transform
Transform3D gt;
gt.origin = Vector3(4, 5, 6);
node->set_global_transform(gt);
CHECK(node->get_global_transform() == gt);
}

TEST_CASE("[Modules][IKNode3D] Scale operations") {
Ref<IKNode3D> node = memnew(IKNode3D);
Ref<IKNode3D> node = memnew(IKNode3D);

// Test set_disable_scale and is_scale_disabled
node->set_disable_scale(true);
CHECK(node->is_scale_disabled() == true);
// Test set_disable_scale and is_scale_disabled
node->set_disable_scale(true);
CHECK(node->is_scale_disabled() == true);
}

TEST_CASE("[Modules][IKNode3D] Parent operations") {
Ref<IKNode3D> node = memnew(IKNode3D);
Ref<IKNode3D> parent = memnew(IKNode3D);
Ref<IKNode3D> node = memnew(IKNode3D);
Ref<IKNode3D> parent = memnew(IKNode3D);

// Test set_parent and get_parent
node->set_parent(parent);
CHECK(node->get_parent() == parent);
// Test set_parent and get_parent
node->set_parent(parent);
CHECK(node->get_parent() == parent);
}

TEST_CASE("[Modules][IKNode3D] Coordinate transformations") {
Ref<IKNode3D> node = memnew(IKNode3D);
Ref<IKNode3D> node = memnew(IKNode3D);

// Test to_local and to_global
Vector3 global(1, 2, 3);
Vector3 local = node->to_local(global);
CHECK(node->to_global(local) == global);
// Test to_local and to_global
Vector3 global(1, 2, 3);
Vector3 local = node->to_local(global);
CHECK(node->to_global(local) == global);
}

TEST_CASE("[Modules][IKNode3D] Test local transform calculation") {
Ref<IKNode3D> node = memnew(IKNode3D);
Ref<IKNode3D> node = memnew(IKNode3D);

Transform3D node_transform;
node_transform.origin = Vector3(1.0, 2.0, 3.0); // Translation by (1, 2, 3)
node->set_global_transform(node_transform);
Transform3D node_transform;
node_transform.origin = Vector3(1.0, 2.0, 3.0); // Translation by (1, 2, 3)
node->set_global_transform(node_transform);

Ref<IKNode3D> parent_node = memnew(IKNode3D);
Ref<IKNode3D> parent_node = memnew(IKNode3D);

Transform3D parent_transform;
parent_transform.origin = Vector3(4.0, 5.0, 6.0); // Translation by (4, 5, 6)
parent_node->set_global_transform(parent_transform);
Transform3D parent_transform;
parent_transform.origin = Vector3(4.0, 5.0, 6.0); // Translation by (4, 5, 6)
parent_node->set_global_transform(parent_transform);

node->set_parent(parent_node);
node->set_parent(parent_node);

Transform3D expected_local_transform = parent_node->get_global_transform().affine_inverse() * node->get_global_transform();
Transform3D expected_local_transform = parent_node->get_global_transform().affine_inverse() * node->get_global_transform();

CHECK(node->get_transform() == expected_local_transform);
CHECK(node->get_transform() == expected_local_transform);
}
} // namespace TestIKNode3D

Expand Down
130 changes: 65 additions & 65 deletions tests/test_qcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,85 @@
#define TEST_QCP_H

#include "core/math/quaternion.h"
#include "tests/test_macros.h"
#include "modules/many_bone_ik/src/math/qcp.h"
#include "tests/test_macros.h"

namespace TestQCP {

TEST_CASE("[Modules][QCP] Weighted Superpose") {
double epsilon = CMP_EPSILON;
QCP qcp(epsilon);
TEST_CASE("[Modules][QCP] Weighted Superpose") {
double epsilon = CMP_EPSILON;
QCP qcp(epsilon);

Quaternion expected = Quaternion(0, 0, sqrt(2)/2, sqrt(2)/2);
PackedVector3Array moved = { Vector3(4, 5, 6), Vector3(7, 8, 9), Vector3(1, 2, 3) };
PackedVector3Array target = moved;
for(Vector3 &element : target) {
element = expected.xform(element);
}
Vector<double> weight = { 1.0, 1.0, 1.0 }; // Equal weights
Quaternion expected = Quaternion(0, 0, sqrt(2) / 2, sqrt(2) / 2);
PackedVector3Array moved = { Vector3(4, 5, 6), Vector3(7, 8, 9), Vector3(1, 2, 3) };
PackedVector3Array target = moved;
for (Vector3 &element : target) {
element = expected.xform(element);
}
Vector<double> weight = { 1.0, 1.0, 1.0 }; // Equal weights

Quaternion result = qcp.weighted_superpose(moved, target, weight, false);
CHECK(abs(result.x - expected.x) < epsilon);
CHECK(abs(result.y - expected.y) < epsilon);
CHECK(abs(result.z - expected.z) < epsilon);
CHECK(abs(result.w - expected.w) < epsilon);
}
Quaternion result = qcp.weighted_superpose(moved, target, weight, false);
CHECK(abs(result.x - expected.x) < epsilon);
CHECK(abs(result.y - expected.y) < epsilon);
CHECK(abs(result.z - expected.z) < epsilon);
CHECK(abs(result.w - expected.w) < epsilon);
}

TEST_CASE("[Modules][QCP] Weighted Translation") {
double epsilon = CMP_EPSILON;
QCP qcp(epsilon);
TEST_CASE("[Modules][QCP] Weighted Translation") {
double epsilon = CMP_EPSILON;
QCP qcp(epsilon);

Quaternion expected;
PackedVector3Array moved = { Vector3(4, 5, 6), Vector3(7, 8, 9), Vector3(1, 2, 3) };
PackedVector3Array target = moved;
Vector3 translation_vector = Vector3(1, 2, 3);
for(Vector3 &element : target) {
element = expected.xform(element + translation_vector);
}
Vector<double> weight = { 1.0, 1.0, 1.0 }; // Equal weights
bool translate = true;
Quaternion expected;
PackedVector3Array moved = { Vector3(4, 5, 6), Vector3(7, 8, 9), Vector3(1, 2, 3) };
PackedVector3Array target = moved;
Vector3 translation_vector = Vector3(1, 2, 3);
for (Vector3 &element : target) {
element = expected.xform(element + translation_vector);
}
Vector<double> weight = { 1.0, 1.0, 1.0 }; // Equal weights
bool translate = true;

Quaternion result = qcp.weighted_superpose(moved, target, weight, translate);
CHECK(abs(result.x - expected.x) < epsilon);
CHECK(abs(result.y - expected.y) < epsilon);
CHECK(abs(result.z - expected.z) < epsilon);
CHECK(abs(result.w - expected.w) < epsilon);
Quaternion result = qcp.weighted_superpose(moved, target, weight, translate);
CHECK(abs(result.x - expected.x) < epsilon);
CHECK(abs(result.y - expected.y) < epsilon);
CHECK(abs(result.z - expected.z) < epsilon);
CHECK(abs(result.w - expected.w) < epsilon);

// Check if translation occurred
CHECK(translate == true);
Vector3 translation_result = expected.xform_inv(qcp.get_translation());
CHECK(abs(translation_result.x - translation_vector.x) < epsilon);
CHECK(abs(translation_result.y - translation_vector.y) < epsilon);
CHECK(abs(translation_result.z - translation_vector.z) < epsilon);
}
// Check if translation occurred
CHECK(translate == true);
Vector3 translation_result = expected.xform_inv(qcp.get_translation());
CHECK(abs(translation_result.x - translation_vector.x) < epsilon);
CHECK(abs(translation_result.y - translation_vector.y) < epsilon);
CHECK(abs(translation_result.z - translation_vector.z) < epsilon);
}

TEST_CASE("[Modules][QCP] Weighted Translation Shortest Path") {
double epsilon = CMP_EPSILON;
QCP qcp(epsilon);
TEST_CASE("[Modules][QCP] Weighted Translation Shortest Path") {
double epsilon = CMP_EPSILON;
QCP qcp(epsilon);

Quaternion expected = Quaternion(1, 2, 3, 4).normalized();
PackedVector3Array moved = { Vector3(4, 5, 6), Vector3(7, 8, 9), Vector3(1, 2, 3) };
PackedVector3Array target = moved;
Vector3 translation_vector = Vector3(1, 2, 3);
for(Vector3 &element : target) {
element = expected.xform(element + translation_vector);
}
Vector<double> weight = { 1.0, 1.0, 1.0 }; // Equal weights
bool translate = true;
Quaternion expected = Quaternion(1, 2, 3, 4).normalized();
PackedVector3Array moved = { Vector3(4, 5, 6), Vector3(7, 8, 9), Vector3(1, 2, 3) };
PackedVector3Array target = moved;
Vector3 translation_vector = Vector3(1, 2, 3);
for (Vector3 &element : target) {
element = expected.xform(element + translation_vector);
}
Vector<double> weight = { 1.0, 1.0, 1.0 }; // Equal weights
bool translate = true;

Quaternion result = qcp.weighted_superpose(moved, target, weight, translate);
CHECK(abs(result.x - expected.x) > epsilon);
CHECK(abs(result.y - expected.y) > epsilon);
CHECK(abs(result.z - expected.z) > epsilon);
CHECK(abs(result.w - expected.w) > epsilon);
Quaternion result = qcp.weighted_superpose(moved, target, weight, translate);
CHECK(abs(result.x - expected.x) > epsilon);
CHECK(abs(result.y - expected.y) > epsilon);
CHECK(abs(result.z - expected.z) > epsilon);
CHECK(abs(result.w - expected.w) > epsilon);

// Check if translation occurred
CHECK(translate == true);
Vector3 translation_result = expected.xform_inv(qcp.get_translation());
CHECK(abs(translation_result.x - translation_vector.x) > epsilon);
CHECK(abs(translation_result.y - translation_vector.y) > epsilon);
CHECK(abs(translation_result.z - translation_vector.z) > epsilon);
}
// Check if translation occurred
CHECK(translate == true);
Vector3 translation_result = expected.xform_inv(qcp.get_translation());
CHECK(abs(translation_result.x - translation_vector.x) > epsilon);
CHECK(abs(translation_result.y - translation_vector.y) > epsilon);
CHECK(abs(translation_result.z - translation_vector.z) > epsilon);
}
} // namespace TestQCP

#endif // TEST_QCP_H

0 comments on commit 63bcf47

Please sign in to comment.