Skip to content

Commit

Permalink
Use igl::PI in tests too
Browse files Browse the repository at this point in the history
  • Loading branch information
zfergus committed Sep 8, 2021
1 parent 1fb021c commit 8424dca
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 37 deletions.
18 changes: 10 additions & 8 deletions tests/interval/test_interval.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <catch2/catch.hpp>

#include <igl/PI.h>

#include <interval/interval.hpp>
#include <logger.hpp>
#include <physics/pose.hpp>
Expand Down Expand Up @@ -41,10 +43,10 @@ TEST_CASE("Cosine interval arithmetic", "[interval]")

double shift;
SECTION("No shift") { shift = 0; }
SECTION("2π shift") { shift = 2 * M_PI; }
SECTION("-2π shift") { shift = -2 * M_PI; }
SECTION("100π shift") { shift = 100 * M_PI; }
SECTION("-100π shift") { shift = -100 * M_PI; }
SECTION("2π shift") { shift = 2 * igl::PI; }
SECTION("-2π shift") { shift = -2 * igl::PI; }
SECTION("100π shift") { shift = 100 * igl::PI; }
SECTION("-100π shift") { shift = -100 * igl::PI; }

CAPTURE(shift);

Expand All @@ -69,10 +71,10 @@ TEST_CASE("Sine interval arithmetic", "[interval]")

double shift = M_PI_2;
SECTION("No shift") { shift += 0; }
SECTION("2π shift") { shift += 2 * M_PI; }
SECTION("-2π shift") { shift += -2 * M_PI; }
SECTION("100π shift") { shift += 100 * M_PI; }
SECTION("-100π shift") { shift += -100 * M_PI; }
SECTION("2π shift") { shift += 2 * igl::PI; }
SECTION("-2π shift") { shift += -2 * igl::PI; }
SECTION("100π shift") { shift += 100 * igl::PI; }
SECTION("-100π shift") { shift += -100 * igl::PI; }

CAPTURE(shift);

Expand Down
24 changes: 17 additions & 7 deletions tests/interval/test_interval_root_finder.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#include <catch2/catch.hpp>

#include <igl/PI.h>

#include <interval/interval_root_finder.hpp>
#include <constants.hpp>
#include <logger.hpp>

TEST_CASE("Root of simple function", "[ccd][interval]")
{
double yshift = GENERATE(
-1.1, -1.0 - 10 * ipc::rigid::Constants::INTERVAL_ROOT_FINDER_TOL, -1.0, -0.5,
-1e-4, 0.5, 1.0);
-1.1, -1.0 - 10 * ipc::rigid::Constants::INTERVAL_ROOT_FINDER_TOL, -1.0,
-0.5, -1e-4, 0.5, 1.0);
double a = 4, b = -4, c = 1 + yshift;
auto f = [&](const ipc::rigid::Interval& x) { return a * x * x + b * x + c; };
auto f = [&](const ipc::rigid::Interval& x) {
return a * x * x + b * x + c;
};
ipc::rigid::Interval sol;
bool found_root = ipc::rigid::interval_root_finder(
f, ipc::rigid::Interval(0, 1), ipc::rigid::Constants::INTERVAL_ROOT_FINDER_TOL, sol);
f, ipc::rigid::Interval(0, 1),
ipc::rigid::Constants::INTERVAL_ROOT_FINDER_TOL, sol);
CHECK(found_root == (yshift >= -1.0 && yshift <= 0.0));
if (found_root) {
double actual_sol = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
Expand All @@ -29,10 +34,13 @@ TEST_CASE("Root of simple function", "[ccd][interval]")
TEST_CASE("Root of trig function", "[ccd][interval]")
{
double yshift = GENERATE(0);
auto f = [&](const ipc::rigid::Interval& x) { return cos(2 * M_PI * x) + yshift; };
auto f = [&](const ipc::rigid::Interval& x) {
return cos(2 * igl::PI * x) + yshift;
};
ipc::rigid::Interval sol;
bool found_root = ipc::rigid::interval_root_finder(
f, ipc::rigid::Interval(0, 1), ipc::rigid::Constants::INTERVAL_ROOT_FINDER_TOL, sol);
f, ipc::rigid::Interval(0, 1),
ipc::rigid::Constants::INTERVAL_ROOT_FINDER_TOL, sol);
CHECK(found_root);
if (found_root) {
double actual_sol = 0.25;
Expand All @@ -47,7 +55,9 @@ TEST_CASE("Root of simple function with constraints", "[ccd][interval]")
{
double yshift = GENERATE(-1.1, -1.0 - 1e-7, -1.0, -0.5, 0.0, 0.5, 1.0);
double a = 4, b = -4, c = 1 + yshift;
auto f = [&](const ipc::rigid::Interval& x) { return a * x * x + b * x + c; };
auto f = [&](const ipc::rigid::Interval& x) {
return a * x * x + b * x + c;
};
auto constraint_predicate = [](const ipc::rigid::Interval& x) {
return x.lower() > 0.5;
};
Expand Down
4 changes: 2 additions & 2 deletions tests/physics/test_rigid_body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ TEST_CASE("2D Rigid Body Transform", "[RB][RB-transform]")
SECTION("90 Deg Rotation Case")
{
rb_step.position << 0.0, 0.0;
rb_step.rotation << 0.5 * M_PI;
rb_step.rotation << 0.5 * igl::PI;
vertices_step << 1.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, -1.0;
}

SECTION("Translation and Rotation Case")
{
rb_step.position << 0.5, 0.5;
rb_step.rotation << 0.5 * M_PI;
rb_step.rotation << 0.5 * igl::PI;
vertices_step << 1.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, -1.0;
vertices_step += rb_step.position.transpose().replicate(4, 1);
}
Expand Down
32 changes: 16 additions & 16 deletions tests/physics/test_rigid_body_problem.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <array>
igl::PI #include<array>
#include <iomanip>
#include <iostream>

Expand All @@ -10,7 +10,7 @@
#include <problems/split_distance_barrier_rb_problem.hpp>
#include <utils/not_implemented_error.hpp>

using namespace ipc;
using namespace ipc;
using namespace ipc::rigid;

RigidBody rb_from_displacements(
Expand Down Expand Up @@ -75,8 +75,8 @@ TEST_CASE(

SECTION("90 Deg Rotation Case")
{
rb1_pose_t1.rotation << 0.5 * M_PI;
rb2_pose_t1.rotation << M_PI;
rb1_pose_t1.rotation << 0.5 * igl::PI;
rb2_pose_t1.rotation << igl::PI;
dx = 0.5 * moment_inertia
* (rb1_pose_t1.rotation.squaredNorm()
+ rb2_pose_t1.rotation.squaredNorm());
Expand Down Expand Up @@ -124,15 +124,15 @@ TEST_CASE(

SECTION("90 Deg Rotation Case")
{
vel_1.rotation << 0.5 * M_PI;
vel_2.rotation << M_PI;
vel_1.rotation << 0.5 * igl::PI;
vel_2.rotation << igl::PI;
}
SECTION("Translation and Rotation Case")
{
vel_1.position << 0.5, 0.5;
vel_1.rotation << 0.5 * M_PI;
vel_1.rotation << 0.5 * igl::PI;
vel_2.position << 1.0, 1.0;
vel_2.rotation << M_PI;
vel_2.rotation << igl::PI;
}

std::vector<RigidBody> rbs;
Expand Down Expand Up @@ -173,15 +173,15 @@ TEST_CASE("Rigid Body Problem Hessian", "[RB][RB-Problem][RB-Problem-hessian]")

SECTION("90 Deg Rotation Case")
{
vel_1.rotation << 0.5 * M_PI;
vel_2.rotation << M_PI;
vel_1.rotation << 0.5 * igl::PI;
vel_2.rotation << igl::PI;
}
SECTION("Translation and Rotation Case")
{
vel_1.position << 0.5, 0.5;
vel_1.rotation << 0.5 * M_PI;
vel_1.rotation << 0.5 * igl::PI;
vel_2.position << 1.0, 1.0;
vel_2.rotation << M_PI;
vel_2.rotation << igl::PI;
}

std::vector<RigidBody> rbs;
Expand Down Expand Up @@ -224,15 +224,15 @@ TEST_CASE("dof -> poses -> dof", "[RB][RB-Problem]")

SECTION("90 Deg Rotation Case")
{
vel_1.rotation << 0.5 * M_PI;
vel_2.rotation << M_PI;
vel_1.rotation << 0.5 * igl::PI;
vel_2.rotation << igl::PI;
}
SECTION("Translation and Rotation Case")
{
vel_1.position << 0.5, 0.5;
vel_1.rotation << 0.5 * M_PI;
vel_1.rotation << 0.5 * igl::PI;
vel_2.position << 1.0, 1.0;
vel_2.rotation << M_PI;
vel_2.rotation << igl::PI;
}

std::vector<RigidBody> rbs = {
Expand Down
4 changes: 2 additions & 2 deletions tests/physics/test_rigid_body_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ TEST_CASE("Rigid Body System Transform", "[RB][RB-System][RB-System-transform]")

SECTION("90 Deg Rotation Case")
{
rb1_pose_t1.rotation << 0.5 * M_PI;
rb2_pose_t1.rotation << M_PI;
rb1_pose_t1.rotation << 0.5 * igl::PI;
rb2_pose_t1.rotation << igl::PI;
expected.resize(8, 2);
expected.block(0, 0, 4, 2) << 1.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, -1.0;
expected.block(4, 0, 4, 2) << 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, 1.0,
Expand Down
6 changes: 4 additions & 2 deletions tests/solvers/test_barrier_displacements_opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

//#include <catch2/catch.hpp>

// #include <igl/PI.h>
//#include <finitediff.hpp>

//#include <state.hpp>

//#include <Eigen/Geometry>
Expand Down Expand Up @@ -111,8 +113,8 @@
// state.getCollisionConstraint().update_collision_set = GENERATE(false,
// true); state.opt_method = ipc::rigid::OptimizationMethod::BARRIER_SOLVER;

// double theta1 = 2 * M_PI / NUM_ANGLES * GENERATE(range(0, NUM_ANGLES));
// double theta2 = 2 * M_PI / NUM_ANGLES * GENERATE(range(0, NUM_ANGLES));
// double theta1 = 2 * igl::PI / NUM_ANGLES * GENERATE(range(0, NUM_ANGLES));
// double theta2 = 2 * igl::PI / NUM_ANGLES * GENERATE(range(0, NUM_ANGLES));

// for (int i = 0; i < state.edges.rows(); i++) {
// Eigen::Rotation2D<double> R(i == 0 ? theta1 : theta2);
Expand Down

0 comments on commit 8424dca

Please sign in to comment.