diff --git a/src/engine/engine_derivative.c b/src/engine/engine_derivative.c index 76a56439..265597ff 100644 --- a/src/engine/engine_derivative.c +++ b/src/engine/engine_derivative.c @@ -15,7 +15,6 @@ #include "engine/engine_derivative.h" #include -#include #include #include "engine/engine_core_constraint.h" #include "engine/engine_crossplatform.h" @@ -829,7 +828,7 @@ static mjtNum mjd_muscleGain_vel(mjtNum len, mjtNum vel, const mjtNum lengthrang // scale force if negative if (force < 0) { - force = scale / mjMAX(mjMINVAL, acc0); + force = scale / mju_max(mjMINVAL, acc0); } // mid-ranges @@ -838,25 +837,25 @@ static mjtNum mjd_muscleGain_vel(mjtNum len, mjtNum vel, const mjtNum lengthrang mjtNum x; // optimum length - mjtNum L0 = (lengthrange[1]-lengthrange[0]) / mjMAX(mjMINVAL, range[1]-range[0]); + mjtNum L0 = (lengthrange[1]-lengthrange[0]) / mju_max(mjMINVAL, range[1]-range[0]); // normalized length and velocity - mjtNum L = range[0] + (len-lengthrange[0]) / mjMAX(mjMINVAL, L0); - mjtNum V = vel / mjMAX(mjMINVAL, L0*vmax); + mjtNum L = range[0] + (len-lengthrange[0]) / mju_max(mjMINVAL, L0); + mjtNum V = vel / mju_max(mjMINVAL, L0*vmax); // length curve mjtNum FL = 0; if (L >= lmin && L <= a) { - x = (L-lmin) / mjMAX(mjMINVAL, a-lmin); + x = (L-lmin) / mju_max(mjMINVAL, a-lmin); FL = 0.5*x*x; } else if (L <= 1) { - x = (1-L) / mjMAX(mjMINVAL, 1-a); + x = (1-L) / mju_max(mjMINVAL, 1-a); FL = 1 - 0.5*x*x; } else if (L <= b) { - x = (L-1) / mjMAX(mjMINVAL, b-1); + x = (L-1) / mju_max(mjMINVAL, b-1); FL = 1 - 0.5*x*x; } else if (L <= lmax) { - x = (lmax-L) / mjMAX(mjMINVAL, lmax-b); + x = (lmax-L) / mju_max(mjMINVAL, lmax-b); FL = 0.5*x*x; } @@ -870,15 +869,15 @@ static mjtNum mjd_muscleGain_vel(mjtNum len, mjtNum vel, const mjtNum lengthrang // FV = (V+1)*(V+1) dFV = 2*V + 2; } else if (V <= y) { - // FV = fvmax - (y-V)*(y-V) / mjMAX(mjMINVAL, y) - dFV = (-2*V + 2*y) / mjMAX(mjMINVAL, y); + // FV = fvmax - (y-V)*(y-V) / mju_max(mjMINVAL, y) + dFV = (-2*V + 2*y) / mju_max(mjMINVAL, y); } else { // FV = fvmax dFV = 0; } // compute FVL and scale, make it negative - return -force*FL*dFV/mjMAX(mjMINVAL, L0*vmax); + return -force*FL*dFV/mju_max(mjMINVAL, L0*vmax); } diff --git a/src/engine/engine_sensor.c b/src/engine/engine_sensor.c index 4fbf5b1e..ca10adaa 100644 --- a/src/engine/engine_sensor.c +++ b/src/engine/engine_sensor.c @@ -17,7 +17,6 @@ #include #include -#include #include #include #include "engine/engine_callback.h" @@ -59,7 +58,7 @@ static void add_noise(const mjModel* m, mjData* d, mjtStage stage) { if (m->sensor_datatype[i] == mjDATATYPE_POSITIVE) { // add noise only if positive, keep it positive if (d->sensordata[adr+j] > 0) { - d->sensordata[adr+j] = mjMAX(0, d->sensordata[adr+j]+rnd[0]*noise); + d->sensordata[adr+j] = mju_max(0, d->sensordata[adr+j]+rnd[0]*noise); } } diff --git a/src/engine/engine_support.c b/src/engine/engine_support.c index ad6ab7c6..734772e7 100644 --- a/src/engine/engine_support.c +++ b/src/engine/engine_support.c @@ -19,7 +19,6 @@ #include #include -#include #include #include "engine/engine_core_constraint.h" #include "engine/engine_crossplatform.h" @@ -1543,7 +1542,7 @@ mjtNum mj_getTotalmass(const mjModel* m) { // scale all body masses and inertias to achieve specified total mass void mj_setTotalmass(mjModel* m, mjtNum newmass) { // compute scale factor, avoid zeros - mjtNum scale = mjMAX(mjMINVAL, newmass / mjMAX(mjMINVAL, mj_getTotalmass(m))); + mjtNum scale = mju_max(mjMINVAL, newmass / mju_max(mjMINVAL, mj_getTotalmass(m))); // scale all masses and inertias for (int i=1; i < m->nbody; i++) { diff --git a/src/render/render_gl3.c b/src/render/render_gl3.c index 74b83c48..b2608c35 100644 --- a/src/render/render_gl3.c +++ b/src/render/render_gl3.c @@ -22,7 +22,6 @@ #include #include #include -#include "engine/engine_array_safety.h" #include "engine/engine_crossplatform.h" #include "engine/engine_vis_init.h" #include "render/render_context.h" diff --git a/src/user/user_composite.cc b/src/user/user_composite.cc index 7a8558c6..b150f27b 100644 --- a/src/user/user_composite.cc +++ b/src/user/user_composite.cc @@ -1260,7 +1260,7 @@ void mjCComposite::BoxProject(double* pos) { // cylinder else if (type==mjCOMPTYPE_CYLINDER) { - double L0 = mjMAX(mju_abs(pos[0]), mju_abs(pos[1])); + double L0 = mju_max(mju_abs(pos[0]), mju_abs(pos[1])); mjuu_normvec(pos, 2); pos[0] *= size[0]*L0; pos[1] *= size[1]*L0; diff --git a/src/user/user_mesh.cc b/src/user/user_mesh.cc index deaaa2cc..5877d108 100644 --- a/src/user/user_mesh.cc +++ b/src/user/user_mesh.cc @@ -13,7 +13,6 @@ // limitations under the License. #include -#include #include #include #include @@ -53,6 +52,7 @@ #include "engine/engine_resource.h" #include "engine/engine_util_blas.h" #include "engine/engine_util_errmem.h" +#include "engine/engine_util_misc.h" #include "engine/engine_util_solve.h" #include "engine/engine_util_spatial.h" #include "user/user_model.h" @@ -709,7 +709,7 @@ void mjCMesh::FitGeom(mjCGeom* geom, double* meshpos) { case mjGEOM_CAPSULE: geom->size[0] = (boxsz[0] + boxsz[1])/2; - geom->size[1] = mjMAX(0, boxsz[2] - geom->size[0]/2); + geom->size[1] = mju_max(0, boxsz[2] - geom->size[0]/2); break; case mjGEOM_CYLINDER: @@ -747,7 +747,7 @@ void mjCMesh::FitGeom(mjCGeom* geom, double* meshpos) { for (int i=0; isize[0] = mjMAX(geom->size[0], dst); + geom->size[0] = mju_max(geom->size[0], dst); } break; @@ -760,11 +760,11 @@ void mjCMesh::FitGeom(mjCGeom* geom, double* meshpos) { double v[3] = {vert_[3*i], vert_[3*i+1], vert_[3*i+2]}; double dst = sqrt((v[0]-cen[0])*(v[0]-cen[0]) + (v[1]-cen[1])*(v[1]-cen[1])); - geom->size[0] = mjMAX(geom->size[0], dst); + geom->size[0] = mju_max(geom->size[0], dst); // proceed with z: valid for cylinder double dst2 = fabs(v[2]-cen[2]); - geom->size[1] = mjMAX(geom->size[1], dst2); + geom->size[1] = mju_max(geom->size[1], dst2); } // special handling of capsule: consider curved cap @@ -779,7 +779,7 @@ void mjCMesh::FitGeom(mjCGeom* geom, double* meshpos) { // get spherical elevation at horizontal distance dst double h = geom->size[0] * sin(acos(dst/geom->size[0])); - geom->size[1] = mjMAX(geom->size[1], dst2-h); + geom->size[1] = mju_max(geom->size[1], dst2-h); } } break; @@ -1399,8 +1399,8 @@ void mjCMesh::Process() { vert_[3*i+j] = (float) res[j]; // axis-aligned bounding box - aabb_[j+0] = mjMIN(aabb_[j+0], res[j]); - aabb_[j+3] = mjMAX(aabb_[j+3], res[j]); + aabb_[j+0] = mju_min(aabb_[j+0], res[j]); + aabb_[j+3] = mju_max(aabb_[j+3], res[j]); } } for (int i=0; i0) { // fix minimum - mass = mjMAX(mass, model->boundmass); - inertia[0] = mjMAX(inertia[0], model->boundinertia); - inertia[1] = mjMAX(inertia[1], model->boundinertia); - inertia[2] = mjMAX(inertia[2], model->boundinertia); + mass = mju_max(mass, model->boundmass); + inertia[0] = mju_max(inertia[0], model->boundinertia); + inertia[1] = mju_max(inertia[1], model->boundinertia); + inertia[2] = mju_max(inertia[2], model->boundinertia); // check for negative values if (mass<0 || inertia[0]<0 || inertia[1]<0 ||inertia[2]<0) { @@ -1438,7 +1438,7 @@ double mjCGeom::GetRBound(void) { return sqrt(size[0]*size[0]+size[1]*size[1]); case mjGEOM_ELLIPSOID: - return mjMAX(mjMAX(size[0], size[1]), size[2]); + return mju_max(mju_max(size[0], size[1]), size[2]); case mjGEOM_BOX: return sqrt(size[0]*size[0]+size[1]*size[1]+size[2]*size[2]); @@ -1446,9 +1446,9 @@ double mjCGeom::GetRBound(void) { case mjGEOM_MESH: case mjGEOM_SDF: aabb = model->meshes[meshid]->aabb(); - haabb[0] = mjMAX(fabs(aabb[0]), fabs(aabb[3])); - haabb[1] = mjMAX(fabs(aabb[1]), fabs(aabb[4])); - haabb[2] = mjMAX(fabs(aabb[2]), fabs(aabb[5])); + haabb[0] = mju_max(fabs(aabb[0]), fabs(aabb[3])); + haabb[1] = mju_max(fabs(aabb[1]), fabs(aabb[4])); + haabb[2] = mju_max(fabs(aabb[2]), fabs(aabb[5])); return sqrt(haabb[0]*haabb[0] + haabb[1]*haabb[1] + haabb[2]*haabb[2]); default: @@ -1761,9 +1761,9 @@ void mjCGeom::Compile(void) { size[2] = 0.5*(model->hfields[hfieldid]->size[2]+model->hfields[hfieldid]->size[3]); } else if (type==mjGEOM_MESH || type==mjGEOM_SDF) { const double* aabb = model->meshes[meshid]->aabb(); - size[0] = mjMAX(fabs(aabb[0]), fabs(aabb[3])); - size[1] = mjMAX(fabs(aabb[1]), fabs(aabb[4])); - size[2] = mjMAX(fabs(aabb[2]), fabs(aabb[5])); + size[0] = mju_max(fabs(aabb[0]), fabs(aabb[3])); + size[1] = mju_max(fabs(aabb[1]), fabs(aabb[4])); + size[2] = mju_max(fabs(aabb[2]), fabs(aabb[5])); } for (double s : size) { @@ -3132,9 +3132,9 @@ void mjCPair::Compile(void) { // friction: max if (!mjuu_defined(friction[0])) { - friction[0] = friction[1] = mjMAX(pg1->friction[0], pg2->friction[0]); - friction[2] = mjMAX(pg1->friction[1], pg2->friction[1]); - friction[3] = friction[4] = mjMAX(pg1->friction[2], pg2->friction[2]); + friction[0] = friction[1] = mju_max(pg1->friction[0], pg2->friction[0]); + friction[2] = mju_max(pg1->friction[1], pg2->friction[1]); + friction[3] = friction[4] = mju_max(pg1->friction[2], pg2->friction[2]); } // solver mix factor diff --git a/src/user/user_util.cc b/src/user/user_util.cc index 1a8ccee3..c8a145f2 100644 --- a/src/user/user_util.cc +++ b/src/user/user_util.cc @@ -22,10 +22,10 @@ #include #include -#include #include #include #include "engine/engine_crossplatform.h" +#include "engine/engine_util_misc.h" #include "engine/engine_util_spatial.h" using std::isnan; @@ -443,9 +443,9 @@ void mjuu_offcenter(double* res, const double mass, const double* vec) { void mjuu_visccoef(double* visccoef, double mass, const double* inertia, double scl) { // compute equivalent box double equivbox[3]; - equivbox[0] = sqrt(mjMAX(mjMINVAL, (inertia[1] + inertia[2] - inertia[0])) / mass * 6.0); - equivbox[1] = sqrt(mjMAX(mjMINVAL, (inertia[0] + inertia[2] - inertia[1])) / mass * 6.0); - equivbox[2] = sqrt(mjMAX(mjMINVAL, (inertia[0] + inertia[1] - inertia[2])) / mass * 6.0); + equivbox[0] = sqrt(mju_max(mjMINVAL, (inertia[1] + inertia[2] - inertia[0])) / mass * 6.0); + equivbox[1] = sqrt(mju_max(mjMINVAL, (inertia[0] + inertia[2] - inertia[1])) / mass * 6.0); + equivbox[2] = sqrt(mju_max(mjMINVAL, (inertia[0] + inertia[1] - inertia[2])) / mass * 6.0); // apply formula for box (or rather cross) viscosity diff --git a/src/xml/xml_native_reader.cc b/src/xml/xml_native_reader.cc index 115ee4bd..8c843e1c 100644 --- a/src/xml/xml_native_reader.cc +++ b/src/xml/xml_native_reader.cc @@ -14,13 +14,10 @@ #include "xml/xml_native_reader.h" -#include #include -#include #include #include #include -#include #include #include #include @@ -2314,10 +2311,12 @@ void mjXReader::Custom(XMLElement* section) { // read attributes ReadAttrTxt(elem, "name", pnum->name, true); - if (ReadAttrInt(elem, "size", &pnum->size)) - for (int i=0; isize, 500); i++) { + if (ReadAttrInt(elem, "size", &pnum->size)) { + int sz = pnum->size < 500 ? pnum->size : 500; + for (int i=0; isize = 501; } int len = ReadAttr(elem, "data", pnum->size, data, text, false, false);