Replace double- or single-precision-denominated function calls in the engine with the equivalent mjtNum-denominated calls. This avoids unnecessary casting or precision loss when MuJoCo is compiled for 32-bit float precision. Accordingly, remove #include <math.h> from all engine source files.
build / windows-2022 (push) Has been cancelled
build / macos-12 (push) Has been cancelled
build / ubuntu-20.04-clang-10 (push) Has been cancelled
build / ubuntu-20.04-clang-11 (push) Has been cancelled
build / ubuntu-20.04-clang-12 (push) Has been cancelled
build / ubuntu-22.04-clang-13 (push) Has been cancelled
build / ubuntu-22.04-clang-14 (push) Has been cancelled
build / ubuntu-22.04-gcc-10 (push) Has been cancelled
build / ubuntu-22.04-gcc-11 (push) Has been cancelled
build / ubuntu-22.04-gcc-12 (push) Has been cancelled
build / ubuntu-22.04-gcc-9 (push) Has been cancelled
build / windows-2022 (push) Has been cancelled
build / macos-12 (push) Has been cancelled
build / ubuntu-20.04-clang-10 (push) Has been cancelled
build / ubuntu-20.04-clang-11 (push) Has been cancelled
build / ubuntu-20.04-clang-12 (push) Has been cancelled
build / ubuntu-22.04-clang-13 (push) Has been cancelled
build / ubuntu-22.04-clang-14 (push) Has been cancelled
build / ubuntu-22.04-gcc-10 (push) Has been cancelled
build / ubuntu-22.04-gcc-11 (push) Has been cancelled
build / ubuntu-22.04-gcc-12 (push) Has been cancelled
build / ubuntu-22.04-gcc-9 (push) Has been cancelled
Also, minor type-related fixes in `user_mesh.cc`. PiperOrigin-RevId: 675082329 Change-Id: Icc5eb9f9eb4fbf09b08d7d4b9b2929f414e4a75c
This commit is contained in:
committed by
Copybara-Service
parent
dde25d039b
commit
fd17b2144a
+16
-15
@@ -28,7 +28,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include <mujoco/mjspec.h>
|
||||
#include <mujoco/mujoco.h>
|
||||
#include "user/user_api.h"
|
||||
|
||||
#ifdef MUJOCO_TINYOBJLOADER_IMPL
|
||||
@@ -73,6 +72,8 @@ extern "C" {
|
||||
namespace {
|
||||
using mujoco::user::VectorToString;
|
||||
using mujoco::user::FilePath;
|
||||
using std::max;
|
||||
using std::min;
|
||||
} // namespace
|
||||
|
||||
// compute triangle area, surface normal, center
|
||||
@@ -730,7 +731,7 @@ void mjCMesh::FitGeom(mjCGeom* geom, double* meshpos) {
|
||||
|
||||
case mjGEOM_CAPSULE:
|
||||
geom->size[0] = (boxsz[0] + boxsz[1])/2;
|
||||
geom->size[1] = mju_max(0, boxsz[2] - geom->size[0]/2);
|
||||
geom->size[1] = max(0.0, boxsz[2] - geom->size[0]/2);
|
||||
break;
|
||||
|
||||
case mjGEOM_CYLINDER:
|
||||
@@ -768,7 +769,7 @@ void mjCMesh::FitGeom(mjCGeom* geom, double* meshpos) {
|
||||
for (int i=0; i < nvert(); i++) {
|
||||
double v[3] = {vert_[3*i], vert_[3*i+1], vert_[3*i+2]};
|
||||
double dst = mjuu_dist3(v, cen);
|
||||
geom->size[0] = mju_max(geom->size[0], dst);
|
||||
geom->size[0] = max(geom->size[0], dst);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -781,11 +782,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] = mju_max(geom->size[0], dst);
|
||||
geom->size[0] = max(geom->size[0], dst);
|
||||
|
||||
// proceed with z: valid for cylinder
|
||||
double dst2 = fabs(v[2]-cen[2]);
|
||||
geom->size[1] = mju_max(geom->size[1], dst2);
|
||||
double dst2 = abs(v[2]-cen[2]);
|
||||
geom->size[1] = max(geom->size[1], dst2);
|
||||
}
|
||||
|
||||
// special handling of capsule: consider curved cap
|
||||
@@ -796,11 +797,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]));
|
||||
double dst2 = fabs(v[2]-cen[2]);
|
||||
double dst2 = abs(v[2]-cen[2]);
|
||||
|
||||
// get spherical elevation at horizontal distance dst
|
||||
double h = geom->size[0] * sin(acos(dst/geom->size[0]));
|
||||
geom->size[1] = mju_max(geom->size[1], dst2-h);
|
||||
geom->size[1] = max(geom->size[1], dst2-h);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1120,7 +1121,7 @@ void mjCMesh::LoadSTL(mjResource* resource) {
|
||||
resource->name);
|
||||
}
|
||||
// check if vertex coordinates can be cast to an int safely
|
||||
if (fabs(v[k])>pow(2, 30)) {
|
||||
if (fabs(v[k]) > pow(2, 30)) {
|
||||
throw mjCError(this,
|
||||
"vertex coordinates in STL file '%s' exceed maximum bounds",
|
||||
resource->name);
|
||||
@@ -1249,7 +1250,7 @@ void mjCMesh::ComputeVolume(double CoM[3], mjtGeomInertia type,
|
||||
|
||||
// if legacy computation requested, then always positive
|
||||
if (!exactmeshinertia && type==mjINERTIA_VOLUME) {
|
||||
vol = fabs(vol);
|
||||
vol = abs(vol);
|
||||
}
|
||||
|
||||
// add pyramid com
|
||||
@@ -1441,7 +1442,7 @@ void mjCMesh::Process() {
|
||||
|
||||
// if legacy computation requested, then always positive
|
||||
if (!exactmeshinertia && type==mjINERTIA_VOLUME) {
|
||||
vol = fabs(vol);
|
||||
vol = abs(vol);
|
||||
}
|
||||
|
||||
// apply formula, accumulate
|
||||
@@ -1515,8 +1516,8 @@ void mjCMesh::Process() {
|
||||
vert_[3*i+j] = (float) res[j];
|
||||
|
||||
// axis-aligned bounding box
|
||||
aamm_[j+0] = mju_min(aamm_[j+0], res[j]);
|
||||
aamm_[j+3] = mju_max(aamm_[j+3], res[j]);
|
||||
aamm_[j+0] = min(aamm_[j+0], res[j]);
|
||||
aamm_[j+3] = max(aamm_[j+3], res[j]);
|
||||
}
|
||||
}
|
||||
for (int i=0; i < nnormal(); i++) {
|
||||
@@ -2638,8 +2639,8 @@ void mjCFlex::Compile(const mjVFS* vfs) {
|
||||
int* v = elem_.data() + f*(dim+1);
|
||||
for (int e = 0; e < kNumEdges[dim-1]; e++) {
|
||||
auto pair = std::pair(
|
||||
std::min(v[eledge[dim-1][e][0]], v[eledge[dim-1][e][1]]),
|
||||
std::max(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]])
|
||||
);
|
||||
|
||||
// if edge is already present in the vector only store its index
|
||||
|
||||
Reference in New Issue
Block a user