Fix minor formatting issues and use nullptr consistently.
PiperOrigin-RevId: 819178621 Change-Id: I3f6bfb6888075188d49e32110af2074b07c6b918
This commit is contained in:
committed by
Copybara-Service
parent
f7708954cb
commit
f1d45bd542
+24
-25
@@ -59,7 +59,7 @@
|
|||||||
#include <mujoco/mjmodel.h>
|
#include <mujoco/mjmodel.h>
|
||||||
#include <mujoco/mjplugin.h>
|
#include <mujoco/mjplugin.h>
|
||||||
#include <mujoco/mjtnum.h>
|
#include <mujoco/mjtnum.h>
|
||||||
#include "engine/engine_crossplatform.h"
|
#include "engine/engine_crossplatform.h" // IWYU pragma: keep
|
||||||
#include "engine/engine_plugin.h"
|
#include "engine/engine_plugin.h"
|
||||||
#include "engine/engine_util_errmem.h"
|
#include "engine/engine_util_errmem.h"
|
||||||
#include "user/user_cache.h"
|
#include "user/user_cache.h"
|
||||||
@@ -73,7 +73,6 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using mujoco::user::VectorToString;
|
|
||||||
using mujoco::user::FilePath;
|
using mujoco::user::FilePath;
|
||||||
using std::max;
|
using std::max;
|
||||||
using std::min;
|
using std::min;
|
||||||
@@ -211,8 +210,8 @@ mjCMesh::mjCMesh(mjCModel* _model, mjCDef* _def) {
|
|||||||
mjuu_setvec(aamm_, 1e10, 1e10, 1e10);
|
mjuu_setvec(aamm_, 1e10, 1e10, 1e10);
|
||||||
mjuu_setvec(aamm_+3, -1e10, -1e10, -1e10);
|
mjuu_setvec(aamm_+3, -1e10, -1e10, -1e10);
|
||||||
szgraph_ = 0;
|
szgraph_ = 0;
|
||||||
center_ = NULL;
|
center_ = nullptr;
|
||||||
graph_ = NULL;
|
graph_ = nullptr;
|
||||||
needhull_ = false;
|
needhull_ = false;
|
||||||
maxhullvert_ = -1;
|
maxhullvert_ = -1;
|
||||||
processed_ = false;
|
processed_ = false;
|
||||||
@@ -254,14 +253,14 @@ mjCMesh& mjCMesh::operator=(const mjCMesh& other) {
|
|||||||
this->center_ = (double*)mju_malloc(ncenter);
|
this->center_ = (double*)mju_malloc(ncenter);
|
||||||
memcpy(this->center_, other.center_, ncenter);
|
memcpy(this->center_, other.center_, ncenter);
|
||||||
} else {
|
} else {
|
||||||
this->center_ = NULL;
|
this->center_ = nullptr;
|
||||||
}
|
}
|
||||||
if (other.graph_) {
|
if (other.graph_) {
|
||||||
size_t szgraph = szgraph_*sizeof(int);
|
size_t szgraph = szgraph_*sizeof(int);
|
||||||
this->graph_ = (int*)mju_malloc(szgraph);
|
this->graph_ = (int*)mju_malloc(szgraph);
|
||||||
memcpy(this->graph_, other.graph_, szgraph);
|
memcpy(this->graph_, other.graph_, szgraph);
|
||||||
} else {
|
} else {
|
||||||
this->graph_ = NULL;
|
this->graph_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PointToLocal();
|
PointToLocal();
|
||||||
@@ -332,8 +331,8 @@ void mjCMesh::CopyFromSpec() {
|
|||||||
if (center_) mju_free(center_);
|
if (center_) mju_free(center_);
|
||||||
if (graph_) mju_free(graph_);
|
if (graph_) mju_free(graph_);
|
||||||
szgraph_ = 0;
|
szgraph_ = 0;
|
||||||
center_ = NULL;
|
center_ = nullptr;
|
||||||
graph_ = NULL;
|
graph_ = nullptr;
|
||||||
|
|
||||||
// use filename if name is missing
|
// use filename if name is missing
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
@@ -524,7 +523,7 @@ namespace {
|
|||||||
struct VertexKey {
|
struct VertexKey {
|
||||||
float v[3];
|
float v[3];
|
||||||
|
|
||||||
bool operator==(const VertexKey &other) const {
|
bool operator==(const VertexKey& other) const {
|
||||||
return (v[0] == other.v[0] && v[1] == other.v[1] && v[2] == other.v[2]);
|
return (v[0] == other.v[0] && v[1] == other.v[1] && v[2] == other.v[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1212,7 +1211,7 @@ void mjCMesh::LoadSTL(mjResource* resource) {
|
|||||||
|
|
||||||
// get file data in buffer
|
// get file data in buffer
|
||||||
char* buffer = 0;
|
char* buffer = 0;
|
||||||
int buffer_sz = mju_readResource(resource, (const void**) &buffer);
|
int buffer_sz = mju_readResource(resource, (const void**)&buffer);
|
||||||
|
|
||||||
// still not found
|
// still not found
|
||||||
if (buffer_sz < 0) {
|
if (buffer_sz < 0) {
|
||||||
@@ -1285,7 +1284,7 @@ void mjCMesh::LoadMSH(mjResource* resource, bool remove_repeated) {
|
|||||||
|
|
||||||
// get file data in buffer
|
// get file data in buffer
|
||||||
char* buffer = 0;
|
char* buffer = 0;
|
||||||
int buffer_sz = mju_readResource(resource, (const void**) &buffer);
|
int buffer_sz = mju_readResource(resource, (const void**)&buffer);
|
||||||
|
|
||||||
// still not found
|
// still not found
|
||||||
if (buffer_sz < 0) {
|
if (buffer_sz < 0) {
|
||||||
@@ -1880,7 +1879,7 @@ void mjCMesh::MakeGraph() {
|
|||||||
qh_zero(qh, stderr);
|
qh_zero(qh, stderr);
|
||||||
|
|
||||||
// qhull basic init
|
// qhull basic init
|
||||||
qh_init_A(qh, stdin, stdout, stderr, 0, NULL);
|
qh_init_A(qh, stdin, stdout, stderr, 0, nullptr);
|
||||||
|
|
||||||
// install longjmp error handler
|
// install longjmp error handler
|
||||||
exitcode = setjmp(qh->errexit);
|
exitcode = setjmp(qh->errexit);
|
||||||
@@ -1888,7 +1887,7 @@ void mjCMesh::MakeGraph() {
|
|||||||
if (!exitcode) {
|
if (!exitcode) {
|
||||||
// actual init
|
// actual init
|
||||||
qh_initflags(qh, const_cast<char*>(qhopt.c_str()));
|
qh_initflags(qh, const_cast<char*>(qhopt.c_str()));
|
||||||
qh_init_B(qh, vert_.data(), nvert(), 3, False);
|
qh_init_B(qh, vert_.data(), nvert(), 3, qh_False);
|
||||||
|
|
||||||
// construct convex hull
|
// construct convex hull
|
||||||
qh_qhull(qh);
|
qh_qhull(qh);
|
||||||
@@ -2661,10 +2660,11 @@ void mjCMesh::MakeNormal() {
|
|||||||
normal_[3*i+2]*normal_[3*i+2]);
|
normal_[3*i+2]*normal_[3*i+2]);
|
||||||
|
|
||||||
// divide by length
|
// divide by length
|
||||||
if (len > mjMINVAL)
|
if (len > mjMINVAL) {
|
||||||
for (int j=0; j < 3; j++) {
|
for (int j=0; j < 3; j++) {
|
||||||
normal_[3*i+j] /= len;
|
normal_[3*i+j] /= len;
|
||||||
}else {
|
}
|
||||||
|
} else {
|
||||||
normal_[3*i] = normal_[3*i+1] = 0;
|
normal_[3*i] = normal_[3*i+1] = 0;
|
||||||
normal_[3*i+2] = 1;
|
normal_[3*i+2] = 1;
|
||||||
}
|
}
|
||||||
@@ -3270,7 +3270,7 @@ void mjCSkin::Compile(const mjVFS* vfs) {
|
|||||||
// get index and check range
|
// get index and check range
|
||||||
int jj = vertid_[i][j];
|
int jj = vertid_[i][j];
|
||||||
if (jj < 0 || jj >= nvert) {
|
if (jj < 0 || jj >= nvert) {
|
||||||
throw mjCError(this, "vertid %d out of range in skin", NULL, jj);
|
throw mjCError(this, "vertid %d out of range in skin", nullptr, jj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// accumulate
|
// accumulate
|
||||||
@@ -3281,7 +3281,7 @@ void mjCSkin::Compile(const mjVFS* vfs) {
|
|||||||
// check coverage
|
// check coverage
|
||||||
for (int i=0; i < nvert; i++) {
|
for (int i=0; i < nvert; i++) {
|
||||||
if (vw[i] <= mjMINVAL) {
|
if (vw[i] <= mjMINVAL) {
|
||||||
throw mjCError(this, "vertex %d must have positive total weight in skin", NULL, i);
|
throw mjCError(this, "vertex %d must have positive total weight in skin", nullptr, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3314,7 +3314,7 @@ void mjCSkin::Compile(const mjVFS* vfs) {
|
|||||||
// load skin in SKN BIN format
|
// load skin in SKN BIN format
|
||||||
void mjCSkin::LoadSKN(mjResource* resource) {
|
void mjCSkin::LoadSKN(mjResource* resource) {
|
||||||
char* buffer = 0;
|
char* buffer = 0;
|
||||||
int buffer_sz = mju_readResource(resource, (const void**) &buffer);
|
int buffer_sz = mju_readResource(resource, (const void**)&buffer);
|
||||||
|
|
||||||
if (buffer_sz < 0) {
|
if (buffer_sz < 0) {
|
||||||
throw mjCError(this, "could not read SKN file '%s'", resource->name);
|
throw mjCError(this, "could not read SKN file '%s'", resource->name);
|
||||||
@@ -3589,8 +3589,8 @@ void inline ComputeBasis<Stencil2D>(double basis[9], const double* x,
|
|||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
basis[3*i+j] = ( basisL[i]*basisR[j] +
|
basis[3*i+j] = (basisL[i]*basisR[j] +
|
||||||
basisR[i]*basisL[j] ) / (8*volume*volume);
|
basisR[i]*basisL[j]) / (8*volume*volume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3625,8 +3625,8 @@ void inline ComputeBasis<Stencil3D>(double basis[9], const double* x,
|
|||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
basis[3*i+j] = ( normalL[i]*normalR[j] +
|
basis[3*i+j] = (normalL[i]*normalR[j] +
|
||||||
normalR[i]*normalL[j] ) / (36*2*volume*volume);
|
normalR[i]*normalL[j]) / (36*2*volume*volume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3898,7 +3898,7 @@ void inline ComputeLinearStiffness(std::vector<double>& K,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dof != n) { // SHOULD NOT OCCUR
|
if (dof != n) { // SHOULD NOT OCCUR
|
||||||
throw mjCError(NULL, "incorrect number of basis functions");
|
throw mjCError(nullptr, "incorrect number of basis functions");
|
||||||
}
|
}
|
||||||
|
|
||||||
// tensor contraction of the gradients of elastic strains
|
// tensor contraction of the gradients of elastic strains
|
||||||
@@ -4263,8 +4263,7 @@ void mjCFlex::Compile(const mjVFS* vfs) {
|
|||||||
for (int e = 0; e < kNumEdges[dim-1]; e++) {
|
for (int e = 0; e < kNumEdges[dim-1]; e++) {
|
||||||
auto pair = std::pair(
|
auto pair = std::pair(
|
||||||
min(v[eledge[dim-1][e][0]], v[eledge[dim-1][e][1]]),
|
min(v[eledge[dim-1][e][0]], v[eledge[dim-1][e][1]]),
|
||||||
max(v[eledge[dim-1][e][0]], v[eledge[dim-1][e][1]])
|
max(v[eledge[dim-1][e][0]], v[eledge[dim-1][e][1]]));
|
||||||
);
|
|
||||||
|
|
||||||
// if edge is already present in the vector only store its index
|
// if edge is already present in the vector only store its index
|
||||||
auto [it, inserted] = edge_indices.insert({pair, nedge});
|
auto [it, inserted] = edge_indices.insert({pair, nedge});
|
||||||
|
|||||||
Reference in New Issue
Block a user