Add spaces around comparison operators in engine source files.
PiperOrigin-RevId: 535989348 Change-Id: I883f7e82351299933c49b35a31842b5d8d6aea04
This commit is contained in:
committed by
Copybara-Service
parent
d40c395917
commit
455b1cd2e2
@@ -37,7 +37,7 @@ static mjtByte is_intersect(const mjtNum* p1, const mjtNum* p2,
|
||||
|
||||
// compute determinant, check
|
||||
mjtNum det = (p4[1]-p3[1])*(p2[0]-p1[0]) - (p4[0]-p3[0])*(p2[1]-p1[1]);
|
||||
if (fabs(det)<mjMINVAL) {
|
||||
if (fabs(det) < mjMINVAL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ static mjtByte is_intersect(const mjtNum* p1, const mjtNum* p2,
|
||||
a = ((p4[0]-p3[0])*(p1[1]-p3[1]) - (p4[1]-p3[1])*(p1[0]-p3[0])) / det;
|
||||
b = ((p2[0]-p1[0])*(p1[1]-p3[1]) - (p2[1]-p1[1])*(p1[0]-p3[0])) / det;
|
||||
|
||||
return ((a>=0 && a<=1 && b>=0 && b<=1) ? 1 : 0);
|
||||
return ((a >= 0 && a <= 1 && b >= 0 && b <= 1) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ static mjtNum length_circle(const mjtNum* p0, const mjtNum* p1, int ind, mjtNum
|
||||
|
||||
// flip if necessary
|
||||
cross = p0[1]*p1[0]-p0[0]*p1[1];
|
||||
if ((cross>0 && ind) || (cross<0 && !ind)) {
|
||||
if ((cross > 0 && ind) || (cross < 0 && !ind)) {
|
||||
angle = 2*mjPI - angle;
|
||||
}
|
||||
|
||||
@@ -85,37 +85,37 @@ static mjtNum wrap_circle(mjtNum* pnt, const mjtNum* d, const mjtNum* sd, mjtNum
|
||||
int sgn;
|
||||
|
||||
// either point inside circle or circle too small: no wrap
|
||||
if (sqlen0<sqrad || sqlen1<sqrad || rad<mjMINVAL) {
|
||||
if (sqlen0 < sqrad || sqlen1 < sqrad || rad < mjMINVAL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// points too close: no wrap
|
||||
dd = dif[0]*dif[0] + dif[1]*dif[1];
|
||||
if (dd<mjMINVAL) {
|
||||
if (dd < mjMINVAL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// find nearest point on line segment to origin: a*dif + d0
|
||||
a = -(dif[0]*d[0]+dif[1]*d[1])/dd;
|
||||
if (a<0) {
|
||||
if (a < 0) {
|
||||
a = 0;
|
||||
} else if (a>1) {
|
||||
} else if (a > 1) {
|
||||
a = 1;
|
||||
}
|
||||
tmp[0] = a*dif[0] + d[0];
|
||||
tmp[1] = a*dif[1] + d[1];
|
||||
|
||||
// check for intersection and side
|
||||
if (tmp[0]*tmp[0]+tmp[1]*tmp[1]>sqrad && (!sd || mju_dot(sd, tmp, 2)>=0)) {
|
||||
if (tmp[0]*tmp[0]+tmp[1]*tmp[1] > sqrad && (!sd || mju_dot(sd, tmp, 2) >= 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// construct the two solutions, compute goodness
|
||||
for (int i=0; i<2; i++) {
|
||||
for (int i=0; i < 2; i++) {
|
||||
sqrt0 = mju_sqrt(sqlen0 - sqrad);
|
||||
sqrt1 = mju_sqrt(sqlen1 - sqrad);
|
||||
|
||||
sgn = (i==0 ? 1 : -1);
|
||||
sgn = (i == 0 ? 1 : -1);
|
||||
|
||||
sol[i][0][0] = (d[0]*sqrad + sgn*rad*d[1]*sqrt0)/sqlen0;
|
||||
sol[i][0][1] = (d[1]*sqrad - sgn*rad*d[0]*sqrt0)/sqlen0;
|
||||
@@ -139,7 +139,7 @@ static mjtNum wrap_circle(mjtNum* pnt, const mjtNum* d, const mjtNum* sd, mjtNum
|
||||
}
|
||||
|
||||
// select the better solution
|
||||
int i = (good[0]>good[1] ? 0 : 1);
|
||||
int i = (good[0] > good[1] ? 0 : 1);
|
||||
pnt[0] = sol[i][0][0];
|
||||
pnt[1] = sol[i][0][1];
|
||||
pnt[2] = sol[i][1][0];
|
||||
@@ -173,20 +173,20 @@ static mjtNum wrap_inside(mjtNum* pnt, const mjtNum* d, mjtNum rad) {
|
||||
mjtNum dd = dif[0]*dif[0] + dif[1]*dif[1];
|
||||
|
||||
// either point inside circle or circle too small: no wrap
|
||||
if (len0<=rad || len1<=rad || rad<mjMINVAL || len0<mjMINVAL || len1<mjMINVAL) {
|
||||
if (len0 <= rad || len1 <= rad || rad < mjMINVAL || len0 < mjMINVAL || len1 < mjMINVAL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// segment-circle intersection: no wrap
|
||||
if (dd>mjMINVAL) {
|
||||
if (dd > mjMINVAL) {
|
||||
// find nearest point on line segment to origin: d0 + a*dif
|
||||
mjtNum a = -(dif[0]*d[0]+dif[1]*d[1])/dd;
|
||||
|
||||
// in segment
|
||||
if (a>0 && a<1) {
|
||||
if (a > 0 && a < 1) {
|
||||
mjtNum tmp[2];
|
||||
mju_addScl(tmp, d, dif, a, 2);
|
||||
if (mju_norm(tmp, 2)<=rad) {
|
||||
if (mju_norm(tmp, 2) <= rad) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -204,9 +204,9 @@ static mjtNum wrap_inside(mjtNum* pnt, const mjtNum* d, mjtNum rad) {
|
||||
mjtNum A = rad/len0;
|
||||
mjtNum B = rad/len1;
|
||||
mjtNum cosG = (len0*len0 + len1*len1 - dd) / (2*len0*len1);
|
||||
if (cosG<-1+mjMINVAL) {
|
||||
if (cosG < -1+mjMINVAL) {
|
||||
return -1;
|
||||
} else if (cosG>1-mjMINVAL) {
|
||||
} else if (cosG > 1-mjMINVAL) {
|
||||
return 0;
|
||||
}
|
||||
mjtNum G = mju_acos(cosG);
|
||||
@@ -216,20 +216,20 @@ static mjtNum wrap_inside(mjtNum* pnt, const mjtNum* d, mjtNum rad) {
|
||||
mjtNum f = mju_asin(A*z) + mju_asin(B*z) - 2*mju_asin(z) + G;
|
||||
|
||||
// make sure init is not on the other side
|
||||
if (f>0) {
|
||||
if (f > 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Newton method
|
||||
int iter;
|
||||
for (iter=0; iter<maxiter && mju_abs(f)>tolerance; iter++) {
|
||||
for (iter=0; iter < maxiter && mju_abs(f) > tolerance; iter++) {
|
||||
// derivative
|
||||
mjtNum df = A/mju_max(mjMINVAL, mju_sqrt(1-z*z*A*A)) +
|
||||
B/mju_max(mjMINVAL, mju_sqrt(1-z*z*B*B)) -
|
||||
2/mju_max(mjMINVAL, mju_sqrt(1-z*z));
|
||||
|
||||
// check sign; SHOULD NOT OCCUR
|
||||
if (df>-mjMINVAL) {
|
||||
if (df > -mjMINVAL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ static mjtNum wrap_inside(mjtNum* pnt, const mjtNum* d, mjtNum rad) {
|
||||
mjtNum z1 = z - f/df;
|
||||
|
||||
// make sure we are moving to the left; SHOULD NOT OCCUR
|
||||
if (z1>z) {
|
||||
if (z1 > z) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -246,13 +246,13 @@ static mjtNum wrap_inside(mjtNum* pnt, const mjtNum* d, mjtNum rad) {
|
||||
f = mju_asin(A*z) + mju_asin(B*z) - 2*mju_asin(z) + G;
|
||||
|
||||
// exit if positive; SHOULD NOT OCCUR
|
||||
if (f>tolerance) {
|
||||
if (f > tolerance) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// check convergence
|
||||
if (iter>=maxiter) {
|
||||
if (iter >= maxiter) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ mjtNum mju_wrap(mjtNum* wpnt, const mjtNum* x0, const mjtNum* x1,
|
||||
mjtNum L0, L1;
|
||||
|
||||
// check object type; SHOULD NOT OCCUR
|
||||
if (type!=mjWRAP_SPHERE && type!=mjWRAP_CYLINDER) {
|
||||
if (type != mjWRAP_SPHERE && type != mjWRAP_CYLINDER) {
|
||||
mju_error("mju_wrap: unknown wrapping object type %d", type);
|
||||
}
|
||||
|
||||
@@ -297,12 +297,12 @@ mjtNum mju_wrap(mjtNum* wpnt, const mjtNum* x0, const mjtNum* x1,
|
||||
mju_mulMatTVec(p[1], xmat, tmp, 3, 3);
|
||||
|
||||
// too close to origin: return
|
||||
if (mju_norm3(p[0])<mjMINVAL || mju_norm3(p[1])<mjMINVAL) {
|
||||
if (mju_norm3(p[0]) < mjMINVAL || mju_norm3(p[1]) < mjMINVAL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// construct 2D frame for circle wrap
|
||||
if (type==mjWRAP_SPHERE) {
|
||||
if (type == mjWRAP_SPHERE) {
|
||||
// 1st axis = p0
|
||||
mju_copy3(axis[0], p[0]);
|
||||
mju_normalize3(axis[0]);
|
||||
@@ -312,15 +312,15 @@ mjtNum mju_wrap(mjtNum* wpnt, const mjtNum* x0, const mjtNum* x1,
|
||||
mjtNum nrm = mju_normalize3(normal);
|
||||
|
||||
// if (p0, p1) parallel: different normal
|
||||
if (nrm<mjMINVAL) {
|
||||
if (nrm < mjMINVAL) {
|
||||
// find max component of axis0
|
||||
int i = 0;
|
||||
if (mju_abs(axis[0][1])>mju_abs(axis[0][0]) &&
|
||||
mju_abs(axis[0][1])>mju_abs(axis[0][2])) {
|
||||
if (mju_abs(axis[0][1]) > mju_abs(axis[0][0]) &&
|
||||
mju_abs(axis[0][1]) > mju_abs(axis[0][2])) {
|
||||
i = 1;
|
||||
}
|
||||
if (mju_abs(axis[0][2])>mju_abs(axis[0][0]) &&
|
||||
mju_abs(axis[0][2])>mju_abs(axis[0][1])) {
|
||||
if (mju_abs(axis[0][2]) > mju_abs(axis[0][0]) &&
|
||||
mju_abs(axis[0][2]) > mju_abs(axis[0][1])) {
|
||||
i = 2;
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ mjtNum mju_wrap(mjtNum* wpnt, const mjtNum* x0, const mjtNum* x1,
|
||||
}
|
||||
|
||||
// apply inside wrap
|
||||
if (side && sd[0]==0 && sd[1]==0) {
|
||||
if (side && sd[0] == 0 && sd[1] == 0) {
|
||||
wlen = wrap_inside(pnt, d, size[0]);
|
||||
}
|
||||
|
||||
@@ -384,12 +384,12 @@ mjtNum mju_wrap(mjtNum* wpnt, const mjtNum* x0, const mjtNum* x1,
|
||||
}
|
||||
|
||||
// no wrap
|
||||
if (wlen<0) {
|
||||
if (wlen < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// reconstruct 3D points in local frame: res
|
||||
for (int i=0; i<2; i++) {
|
||||
for (int i=0; i < 2; i++) {
|
||||
// res = axis0*d0 + axis1*d1
|
||||
mju_scl3(res+3*i, axis[0], pnt[2*i]);
|
||||
mju_scl3(tmp, axis[1], pnt[2*i+1]);
|
||||
@@ -397,7 +397,7 @@ mjtNum mju_wrap(mjtNum* wpnt, const mjtNum* x0, const mjtNum* x1,
|
||||
}
|
||||
|
||||
// cylinder: correct along z
|
||||
if (type==mjWRAP_CYLINDER) {
|
||||
if (type == mjWRAP_CYLINDER) {
|
||||
// set vertical coordinates
|
||||
L0 = mju_sqrt((p[0][0]-res[0])*(p[0][0]-res[0]) + (p[0][1]-res[1])*(p[0][1]-res[1]));
|
||||
L1 = mju_sqrt((p[1][0]-res[3])*(p[1][0]-res[3]) + (p[1][1]-res[4])*(p[1][1]-res[4]));
|
||||
@@ -466,7 +466,7 @@ mjtNum mju_muscleGain(mjtNum len, mjtNum vel, const mjtNum lengthrange[2],
|
||||
mjtNum fvmax = prm[8];
|
||||
|
||||
// scale force if negative
|
||||
if (force<0) {
|
||||
if (force < 0) {
|
||||
force = scale / mjMAX(mjMINVAL, acc0);
|
||||
}
|
||||
|
||||
@@ -484,16 +484,16 @@ mjtNum mju_muscleGain(mjtNum len, mjtNum vel, const mjtNum lengthrange[2],
|
||||
|
||||
// length curve
|
||||
mjtNum FL = 0;
|
||||
if (L>=lmin && L<=a) {
|
||||
if (L >= lmin && L <= a) {
|
||||
x = (L-lmin) / mjMAX(mjMINVAL, a-lmin);
|
||||
FL = 0.5*x*x;
|
||||
} else if (L<=1) {
|
||||
} else if (L <= 1) {
|
||||
x = (1-L) / mjMAX(mjMINVAL, 1-a);
|
||||
FL = 1 - 0.5*x*x;
|
||||
} else if (L<=b) {
|
||||
} else if (L <= b) {
|
||||
x = (L-1) / mjMAX(mjMINVAL, b-1);
|
||||
FL = 1 - 0.5*x*x;
|
||||
} else if (L<=lmax) {
|
||||
} else if (L <= lmax) {
|
||||
x = (lmax-L) / mjMAX(mjMINVAL, lmax-b);
|
||||
FL = 0.5*x*x;
|
||||
}
|
||||
@@ -501,11 +501,11 @@ mjtNum mju_muscleGain(mjtNum len, mjtNum vel, const mjtNum lengthrange[2],
|
||||
// velocity curve
|
||||
mjtNum FV;
|
||||
mjtNum y = fvmax-1;
|
||||
if (V<=-1) {
|
||||
if (V <= -1) {
|
||||
FV = 0;
|
||||
} else if (V<=0) {
|
||||
} else if (V <= 0) {
|
||||
FV = (V+1)*(V+1);
|
||||
} else if (V<=y) {
|
||||
} else if (V <= y) {
|
||||
FV = fvmax - (y-V)*(y-V) / mjMAX(mjMINVAL, y);
|
||||
} else {
|
||||
FV = fvmax;
|
||||
@@ -528,7 +528,7 @@ mjtNum mju_muscleBias(mjtNum len, const mjtNum lengthrange[2],
|
||||
mjtNum fpmax = prm[7];
|
||||
|
||||
// scale force if negative
|
||||
if (force<0) {
|
||||
if (force < 0) {
|
||||
force = scale / mjMAX(mjMINVAL, acc0);
|
||||
}
|
||||
|
||||
@@ -540,9 +540,9 @@ mjtNum mju_muscleBias(mjtNum len, const mjtNum lengthrange[2],
|
||||
|
||||
// half-quadratic to (L0+lmax)/2, linear beyond
|
||||
mjtNum b = 0.5*(1+lmax);
|
||||
if (L<=1) {
|
||||
if (L <= 1) {
|
||||
return 0;
|
||||
} else if (L<=b) {
|
||||
} else if (L <= b) {
|
||||
mjtNum x = (L-1) / mjMAX(mjMINVAL, b-1);
|
||||
return -force*fpmax*0.5*x*x;
|
||||
} else {
|
||||
@@ -606,7 +606,7 @@ void mju_encodePyramid(mjtNum* pyramid, const mjtNum* force, const mjtNum* mu, i
|
||||
// arbitary redundancy resolution:
|
||||
// pyramid0_i + pyramid1_i = force_normal/(dim-1) = a
|
||||
// pyramid0_i - pyramid1_i = force_tangent_i/mu_i = b
|
||||
for (int i=0; i<dim-1; i++) {
|
||||
for (int i=0; i < dim-1; i++) {
|
||||
b = mju_min(a, force[i+1]/mu[i]);
|
||||
pyramid[2*i] = 0.5*(a+b);
|
||||
pyramid[2*i+1] = 0.5*(a-b);
|
||||
@@ -618,19 +618,19 @@ void mju_encodePyramid(mjtNum* pyramid, const mjtNum* force, const mjtNum* mu, i
|
||||
// convert pyramid representation to contact force
|
||||
void mju_decodePyramid(mjtNum* force, const mjtNum* pyramid, const mjtNum* mu, int dim) {
|
||||
// special handling of frictionless contacts
|
||||
if (dim==1) {
|
||||
if (dim == 1) {
|
||||
force[0] = pyramid[0];
|
||||
return;
|
||||
}
|
||||
|
||||
// force_normal = sum(pyramid0_i + pyramid1_i)
|
||||
force[0] = 0;
|
||||
for (int i=0; i<2*(dim-1); i++) {
|
||||
for (int i=0; i < 2*(dim-1); i++) {
|
||||
force[0] += pyramid[i];
|
||||
}
|
||||
|
||||
// force_tangent_i = (pyramid0_i - pyramid1_i) * mu_i
|
||||
for (int i=0; i<dim-1; i++) {
|
||||
for (int i=0; i < dim-1; i++) {
|
||||
force[i+1] = (pyramid[2*i] - pyramid[2*i+1]) * mu[i];
|
||||
}
|
||||
}
|
||||
@@ -646,7 +646,7 @@ mjtNum mju_springDamper(mjtNum pos0, mjtNum vel0, mjtNum k, mjtNum b, mjtNum t)
|
||||
|
||||
// overdamping
|
||||
// pos(t) = c1*exp(r1*t) + c2*exp(r2*t); r12 = (-b +- sqrt(det))/2
|
||||
if (det>mjMINVAL) {
|
||||
if (det > mjMINVAL) {
|
||||
// compute w = sqrt(det)/2
|
||||
w = mju_sqrt(det)/2;
|
||||
|
||||
@@ -664,7 +664,7 @@ mjtNum mju_springDamper(mjtNum pos0, mjtNum vel0, mjtNum k, mjtNum b, mjtNum t)
|
||||
|
||||
// critical damping
|
||||
// pos(t) = exp(-b*t/2) * (c1 + c2*t)
|
||||
else if (det<=mjMINVAL && det>=-mjMINVAL) {
|
||||
else if (det <= mjMINVAL && det >= -mjMINVAL) {
|
||||
// compute coefficients
|
||||
c1 = pos0;
|
||||
c2 = vel0 + b*c1/2;
|
||||
@@ -692,8 +692,8 @@ mjtNum mju_springDamper(mjtNum pos0, mjtNum vel0, mjtNum k, mjtNum b, mjtNum t)
|
||||
|
||||
// print matrix to screen
|
||||
void mju_printMat(const mjtNum* mat, int nr, int nc) {
|
||||
for (int r=0; r<nr; r++) {
|
||||
for (int c=0; c<nc; c++) {
|
||||
for (int r=0; r < nr; r++) {
|
||||
for (int c=0; c < nc; c++) {
|
||||
printf("%.8f ", mat[r*nc+c]);
|
||||
}
|
||||
printf("\n");
|
||||
@@ -707,8 +707,8 @@ void mju_printMat(const mjtNum* mat, int nr, int nc) {
|
||||
void mju_printMatSparse(const mjtNum* mat, int nr,
|
||||
const int* rownnz, const int* rowadr,
|
||||
const int* colind) {
|
||||
for (int r=0; r<nr; r++) {
|
||||
for (int adr=rowadr[r]; adr<rowadr[r]+rownnz[r]; adr++) {
|
||||
for (int r=0; r < nr; r++) {
|
||||
for (int adr=rowadr[r]; adr < rowadr[r]+rownnz[r]; adr++) {
|
||||
printf("(%d %d): %9.6f ", r, colind[adr], mat[adr]);
|
||||
}
|
||||
printf("\n");
|
||||
@@ -742,9 +742,9 @@ mjtNum mju_max(mjtNum a, mjtNum b) {
|
||||
|
||||
// clip x to the range [min, max]
|
||||
mjtNum mju_clip(mjtNum x, mjtNum min, mjtNum max) {
|
||||
if (x<min) {
|
||||
if (x < min) {
|
||||
return min;
|
||||
} else if (x>max) {
|
||||
} else if (x > max) {
|
||||
return max;
|
||||
} else {
|
||||
return x;
|
||||
@@ -755,9 +755,9 @@ mjtNum mju_clip(mjtNum x, mjtNum min, mjtNum max) {
|
||||
|
||||
// sign function
|
||||
mjtNum mju_sign(mjtNum x) {
|
||||
if (x<0) {
|
||||
if (x < 0) {
|
||||
return -1;
|
||||
} else if (x>0) {
|
||||
} else if (x > 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -972,13 +972,13 @@ const char* mju_writeNumBytes(size_t nbytes) {
|
||||
int i;
|
||||
static mjTHREADLOCAL char message[20];
|
||||
static const char suffix[] = " KMGTPE";
|
||||
for (i=0; i<6; i++) {
|
||||
for (i=0; i < 6; i++) {
|
||||
const size_t bits = (size_t)(1) << (10*(6-i));
|
||||
if (nbytes >= bits && !(nbytes & (bits - 1))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i<6) {
|
||||
if (i < 6) {
|
||||
mjSNPRINTF(message, "%zu%c", nbytes >> (10*(6-i)), suffix[6-i]);
|
||||
} else {
|
||||
mjSNPRINTF(message, "%zu", nbytes >> (10*(6-i)));
|
||||
@@ -1042,15 +1042,15 @@ const char* mju_warningText(int warning, size_t info) {
|
||||
|
||||
// return 1 if nan or abs(x)>mjMAXVAL, 0 otherwise
|
||||
int mju_isBad(mjtNum x) {
|
||||
return (x!=x || x>mjMAXVAL || x<-mjMAXVAL);
|
||||
return (x != x || x > mjMAXVAL || x < -mjMAXVAL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// return 1 if all elements are 0
|
||||
int mju_isZero(mjtNum* vec, int n) {
|
||||
for (int i=0; i<n; i++) {
|
||||
if (vec[i]!=0) {
|
||||
for (int i=0; i < n; i++) {
|
||||
if (vec[i] != 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1069,7 +1069,7 @@ mjtNum mju_standardNormal(mjtNum* num2) {
|
||||
x1 = scale * (mjtNum)rand() - 1.0;
|
||||
x2 = scale * (mjtNum)rand() - 1.0;
|
||||
w = x1 * x1 + x2 * x2;
|
||||
} while (w>=1.0 || w==0);
|
||||
} while (w >= 1.0 || w == 0);
|
||||
|
||||
w = mju_sqrt((-2.0 * mju_log(w)) / w);
|
||||
if (num2) {
|
||||
@@ -1083,7 +1083,7 @@ mjtNum mju_standardNormal(mjtNum* num2) {
|
||||
|
||||
// convert from float to mjtNum
|
||||
void mju_f2n(mjtNum* res, const float* vec, int n) {
|
||||
for (int i=0; i<n; i++) {
|
||||
for (int i=0; i < n; i++) {
|
||||
res[i] = (mjtNum) vec[i];
|
||||
}
|
||||
}
|
||||
@@ -1092,7 +1092,7 @@ void mju_f2n(mjtNum* res, const float* vec, int n) {
|
||||
|
||||
// convert from mjtNum to float
|
||||
void mju_n2f(float* res, const mjtNum* vec, int n) {
|
||||
for (int i=0; i<n; i++) {
|
||||
for (int i=0; i < n; i++) {
|
||||
res[i] = (float) vec[i];
|
||||
}
|
||||
}
|
||||
@@ -1100,7 +1100,7 @@ void mju_n2f(float* res, const mjtNum* vec, int n) {
|
||||
|
||||
// convert from double to mjtNum
|
||||
void mju_d2n(mjtNum* res, const double* vec, int n) {
|
||||
for (int i=0; i<n; i++) {
|
||||
for (int i=0; i < n; i++) {
|
||||
res[i] = (mjtNum) vec[i];
|
||||
}
|
||||
}
|
||||
@@ -1109,7 +1109,7 @@ void mju_d2n(mjtNum* res, const double* vec, int n) {
|
||||
|
||||
// convert from mjtNum to double
|
||||
void mju_n2d(double* res, const mjtNum* vec, int n) {
|
||||
for (int i=0; i<n; i++) {
|
||||
for (int i=0; i < n; i++) {
|
||||
res[i] = (double) vec[i];
|
||||
}
|
||||
}
|
||||
@@ -1118,10 +1118,10 @@ void mju_n2d(double* res, const mjtNum* vec, int n) {
|
||||
|
||||
// insertion sort, increasing order
|
||||
void mju_insertionSort(mjtNum* list, int n) {
|
||||
for (int i=1; i<n; i++) {
|
||||
for (int i=1; i < n; i++) {
|
||||
mjtNum x = list[i];
|
||||
int j = i-1;
|
||||
while (j>=0 && list[j]>x) {
|
||||
while (j >= 0 && list[j] > x) {
|
||||
list[j+1] = list[j];
|
||||
j--;
|
||||
}
|
||||
@@ -1133,10 +1133,10 @@ void mju_insertionSort(mjtNum* list, int n) {
|
||||
|
||||
// integer insertion sort, increasing order
|
||||
void mju_insertionSortInt(int* list, int n) {
|
||||
for (int i=1; i<n; i++) {
|
||||
for (int i=1; i < n; i++) {
|
||||
int x = list[i];
|
||||
int j = i-1;
|
||||
while (j>=0 && list[j]>x) {
|
||||
while (j >= 0 && list[j] > x) {
|
||||
list[j+1] = list[j];
|
||||
j--;
|
||||
}
|
||||
@@ -1152,7 +1152,7 @@ mjtNum mju_Halton(int index, int base) {
|
||||
mjtNum b = (mjtNum)base;
|
||||
mjtNum f = 1/b, hn = 0;
|
||||
|
||||
while (n0>0) {
|
||||
while (n0 > 0) {
|
||||
int n1 = n0/base;
|
||||
int r = n0 - n1*base;
|
||||
hn += f*r;
|
||||
@@ -1167,7 +1167,7 @@ mjtNum mju_Halton(int index, int base) {
|
||||
|
||||
// Call strncpy, then set dst[n-1] = 0.
|
||||
char* mju_strncpy(char *dst, const char *src, int n) {
|
||||
if (dst && src && n>0) {
|
||||
if (dst && src && n > 0) {
|
||||
strncpy(dst, src, n);
|
||||
dst[n-1] = 0;
|
||||
}
|
||||
@@ -1180,10 +1180,10 @@ char* mju_strncpy(char *dst, const char *src, int n) {
|
||||
// sigmoid function over 0<=x<=1 using quintic polynomial
|
||||
mjtNum mju_sigmoid(mjtNum x) {
|
||||
// fast return
|
||||
if (x<=0) {
|
||||
if (x <= 0) {
|
||||
return 0;
|
||||
}
|
||||
if (x>=1) {
|
||||
if (x >= 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user