<commit_before>//// This file is a part of the OpenSurgSim project.
//// Copyright 2013, SimQuest Solutions Inc.
////
//// Licensed under the Apache License, Version 2.0 (the "License");
//// you may not use this file except in compliance with the License.
//// You may obtain a copy of the License at
////
////     http://www.apache.org/licenses/LICENSE-2.0
////
//// Unless required by applicable law or agreed to in writing, software
//// distributed under the License is distributed on an "AS IS" BASIS,
//// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//// See the License for the specific language governing permissions and
//// limitations under the License.

#include <time.h>

#include <gtest/gtest.h>

#include <SurgSim/Math/Vector.h>

#include <SurgSim/Physics/Shapes.h>

/* CUBE
     3*----------*2
     /          /|
   7*----------* |
    |         6| |
    | *0       | *1
    |          |/
   4*----------*5
*/
static const int cubeNumPoints = 8;
static const SurgSim::Math::Vector3d cubePoints[8]=
{
	SurgSim::Math::Vector3d(-1.0/2.0, -1.0/2.0, -1.0/2.0),
	SurgSim::Math::Vector3d( 1.0/2.0, -1.0/2.0, -1.0/2.0),
	SurgSim::Math::Vector3d( 1.0/2.0,  1.0/2.0, -1.0/2.0),
	SurgSim::Math::Vector3d(-1.0/2.0,  1.0/2.0, -1.0/2.0),

	SurgSim::Math::Vector3d(-1.0/2.0, -1.0/2.0,  1.0/2.0),
	SurgSim::Math::Vector3d( 1.0/2.0, -1.0/2.0,  1.0/2.0),
	SurgSim::Math::Vector3d( 1.0/2.0,  1.0/2.0,  1.0/2.0),
	SurgSim::Math::Vector3d(-1.0/2.0,  1.0/2.0,  1.0/2.0)
};

static const int cubeNumEdges = 12;
static const int cubeEdges[12][2] =
{
	{0, 1}, {3, 2}, {4, 5}, {7, 6}, // +X
	{0, 3}, {1, 2}, {4, 7}, {5 ,6}, // +Y
	{0, 4}, {1, 5}, {2, 6}, {3, 7}  // +Z
};

static const int cubeNumTriangles = 12;
static const int cubeTrianglesCCW[12][3] =
{
	{6, 2, 3}, {6, 3, 7}, // Top    ( 0  1  0) [6237]
	{0, 1, 5}, {0, 5, 4}, // Bottom ( 0 -1  0) [0154]
	{4, 5, 6}, {4, 6, 7}, // Front  ( 0  0  1) [4567]
	{0, 3, 2}, {0, 2, 1}, // Back   ( 0  0 -1) [0321]
	{1, 2, 6}, {1, 6, 5}, // Right  ( 1  0  0) [1265]
	{0, 4, 7}, {0, 7, 3}  // Left   (-1  0  0) [0473]
};

class EmptyData
{
public:
	bool operator ==(const EmptyData& e) const
	{
		return true;
	}
};

class CubeMeshTest : public ::testing::Test
{
public:
	typedef SurgSim::DataStructures::TriangleMesh<EmptyData,EmptyData,EmptyData> TriangleMesh;
	typedef SurgSim::DataStructures::MeshElement<2,EmptyData> EdgeElement;
	typedef SurgSim::DataStructures::MeshElement<3,EmptyData> TriangleElement;

	void SetUp()
	{
		m_numIterations = 100;

		srand((unsigned int)time(nullptr));
	}

	void TearDown()
	{
	}

	/// Number of iterations to test
	int m_numIterations;
};

TEST_F(CubeMeshTest, MeshCubeVSBoxTest)
{
	for (int iterationID = 0; iterationID < m_numIterations; iterationID++)
	{
		double density = 1000.0 * (double)rand()/(double)RAND_MAX + 1.0;
		double lx = 10.0 * (double)rand()/(double)RAND_MAX + 1.0;
		double ly = 10.0 * (double)rand()/(double)RAND_MAX + 1.0;
		double lz = 10.0 * (double)rand()/(double)RAND_MAX + 1.0;

		// Cube
		std::shared_ptr<TriangleMesh> mesh = std::make_shared<TriangleMesh>();
		for (int i = 0; i < cubeNumPoints; i++)
		{
			EmptyData emptyData;
			SurgSim::Math::Vector3d p;
			p[0] = cubePoints[i][0] * lx;
			p[1] = cubePoints[i][1] * ly;
			p[2] = cubePoints[i][2] * lz;
			TriangleMesh::Vertex v(p, emptyData);
			mesh->addVertex(v);
		}
		for (int i = 0; i < cubeNumEdges; i++)
		{
			EmptyData emptyData;
			std::array<unsigned int,2> edgePoints;
			for (int j = 0; j < 2; j++)
			{
				edgePoints[j] = cubeEdges[i][j];
			}
			EdgeElement edgeElement(edgePoints, emptyData);
			TriangleMesh::Edge e(edgeElement);
			mesh->addEdge(e);
		}
		for (int i = 0; i < cubeNumTriangles; i++)
		{
			EmptyData emptyData;
			std::array<unsigned int,3> trianglePoints;
			for (int j = 0; j < 3; j++)
			{
				trianglePoints[j] = cubeTrianglesCCW[i][j];
			}
			TriangleElement triangleElement(trianglePoints, emptyData);
			TriangleMesh::Triangle t(triangleElement);
			mesh->addTriangle(t);
		}

		SurgSim::Physics::MeshShape<EmptyData, EmptyData, EmptyData> boxMesh(mesh);

		SurgSim::Physics::BoxShape boxShape(lx, ly, lz);

		SurgSim::Math::Matrix33d expectedInertia;
		SurgSim::Math::Vector3d expectedMassCenter;
		double expectedMass;
		expectedMass       = boxShape.calculateMass(density);
		expectedInertia    = boxShape.calculateInertia(density);
		expectedMassCenter = boxShape.calculateMassCenter();

		EXPECT_NEAR(boxShape.calculateVolume(), boxMesh.calculateVolume(), 1e-8);
		EXPECT_EQ(expectedMassCenter, boxMesh.calculateMassCenter());
		EXPECT_NEAR(expectedMass, boxMesh.calculateMass(density), 1e-8);
		EXPECT_TRUE(boxMesh.calculateInertia(density).isApprox(expectedInertia));
	}
}
<commit_msg>Changed the EXPECT_EQ to EXPECT_TRUE.<commit_after>//// This file is a part of the OpenSurgSim project.
//// Copyright 2013, SimQuest Solutions Inc.
////
//// Licensed under the Apache License, Version 2.0 (the "License");
//// you may not use this file except in compliance with the License.
//// You may obtain a copy of the License at
////
////     http://www.apache.org/licenses/LICENSE-2.0
////
//// Unless required by applicable law or agreed to in writing, software
//// distributed under the License is distributed on an "AS IS" BASIS,
//// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//// See the License for the specific language governing permissions and
//// limitations under the License.

#include <time.h>

#include <gtest/gtest.h>

#include <SurgSim/Math/Vector.h>

#include <SurgSim/Physics/Shapes.h>

/* CUBE
     3*----------*2
     /          /|
   7*----------* |
    |         6| |
    | *0       | *1
    |          |/
   4*----------*5
*/
static const int cubeNumPoints = 8;
static const SurgSim::Math::Vector3d cubePoints[8]=
{
	SurgSim::Math::Vector3d(-1.0/2.0, -1.0/2.0, -1.0/2.0),
	SurgSim::Math::Vector3d( 1.0/2.0, -1.0/2.0, -1.0/2.0),
	SurgSim::Math::Vector3d( 1.0/2.0,  1.0/2.0, -1.0/2.0),
	SurgSim::Math::Vector3d(-1.0/2.0,  1.0/2.0, -1.0/2.0),

	SurgSim::Math::Vector3d(-1.0/2.0, -1.0/2.0,  1.0/2.0),
	SurgSim::Math::Vector3d( 1.0/2.0, -1.0/2.0,  1.0/2.0),
	SurgSim::Math::Vector3d( 1.0/2.0,  1.0/2.0,  1.0/2.0),
	SurgSim::Math::Vector3d(-1.0/2.0,  1.0/2.0,  1.0/2.0)
};

static const int cubeNumEdges = 12;
static const int cubeEdges[12][2] =
{
	{0, 1}, {3, 2}, {4, 5}, {7, 6}, // +X
	{0, 3}, {1, 2}, {4, 7}, {5 ,6}, // +Y
	{0, 4}, {1, 5}, {2, 6}, {3, 7}  // +Z
};

static const int cubeNumTriangles = 12;
static const int cubeTrianglesCCW[12][3] =
{
	{6, 2, 3}, {6, 3, 7}, // Top    ( 0  1  0) [6237]
	{0, 1, 5}, {0, 5, 4}, // Bottom ( 0 -1  0) [0154]
	{4, 5, 6}, {4, 6, 7}, // Front  ( 0  0  1) [4567]
	{0, 3, 2}, {0, 2, 1}, // Back   ( 0  0 -1) [0321]
	{1, 2, 6}, {1, 6, 5}, // Right  ( 1  0  0) [1265]
	{0, 4, 7}, {0, 7, 3}  // Left   (-1  0  0) [0473]
};

class EmptyData
{
public:
	bool operator ==(const EmptyData& e) const
	{
		return true;
	}
};

class CubeMeshTest : public ::testing::Test
{
public:
	typedef SurgSim::DataStructures::TriangleMesh<EmptyData,EmptyData,EmptyData> TriangleMesh;
	typedef SurgSim::DataStructures::MeshElement<2,EmptyData> EdgeElement;
	typedef SurgSim::DataStructures::MeshElement<3,EmptyData> TriangleElement;

	void SetUp()
	{
		m_numIterations = 100;

		srand((unsigned int)time(nullptr));
	}

	void TearDown()
	{
	}

	/// Number of iterations to test
	int m_numIterations;
};

TEST_F(CubeMeshTest, MeshCubeVSBoxTest)
{
	for (int iterationID = 0; iterationID < m_numIterations; iterationID++)
	{
		double density = 1000.0 * (double)rand()/(double)RAND_MAX + 1.0;
		double lx = 10.0 * (double)rand()/(double)RAND_MAX + 1.0;
		double ly = 10.0 * (double)rand()/(double)RAND_MAX + 1.0;
		double lz = 10.0 * (double)rand()/(double)RAND_MAX + 1.0;

		// Cube
		std::shared_ptr<TriangleMesh> mesh = std::make_shared<TriangleMesh>();
		for (int i = 0; i < cubeNumPoints; i++)
		{
			EmptyData emptyData;
			SurgSim::Math::Vector3d p;
			p[0] = cubePoints[i][0] * lx;
			p[1] = cubePoints[i][1] * ly;
			p[2] = cubePoints[i][2] * lz;
			TriangleMesh::Vertex v(p, emptyData);
			mesh->addVertex(v);
		}
		for (int i = 0; i < cubeNumEdges; i++)
		{
			EmptyData emptyData;
			std::array<unsigned int,2> edgePoints;
			for (int j = 0; j < 2; j++)
			{
				edgePoints[j] = cubeEdges[i][j];
			}
			EdgeElement edgeElement(edgePoints, emptyData);
			TriangleMesh::Edge e(edgeElement);
			mesh->addEdge(e);
		}
		for (int i = 0; i < cubeNumTriangles; i++)
		{
			EmptyData emptyData;
			std::array<unsigned int,3> trianglePoints;
			for (int j = 0; j < 3; j++)
			{
				trianglePoints[j] = cubeTrianglesCCW[i][j];
			}
			TriangleElement triangleElement(trianglePoints, emptyData);
			TriangleMesh::Triangle t(triangleElement);
			mesh->addTriangle(t);
		}

		SurgSim::Physics::MeshShape<EmptyData, EmptyData, EmptyData> boxMesh(mesh);

		SurgSim::Physics::BoxShape boxShape(lx, ly, lz);

		SurgSim::Math::Matrix33d expectedInertia;
		SurgSim::Math::Vector3d expectedMassCenter;
		double expectedMass;
		expectedMass       = boxShape.calculateMass(density);
		expectedInertia    = boxShape.calculateInertia(density);
		expectedMassCenter = boxShape.calculateMassCenter();

		EXPECT_NEAR(boxShape.calculateVolume(), boxMesh.calculateVolume(), 1e-8);
		EXPECT_TRUE((expectedMassCenter - boxMesh.calculateMassCenter()).isZero());
		EXPECT_NEAR(expectedMass, boxMesh.calculateMass(density), 1e-8);
		EXPECT_TRUE(boxMesh.calculateInertia(density).isApprox(expectedInertia));
	}
}

{'fraction_non_alphanumeric': 0.1870655150621445, 'fraction_numerical': 0.06024857804929429, 'mean_word_length': 3.3296853625171, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6804700', 'n_tokens_mistral': 4216, 'n_tokens_neox': 3781, 'n_words': 876}