Clean up mj_id2name and mj_name2id.
PiperOrigin-RevId: 514340647 Change-Id: Idf895b2d7a4a8833725afbe5c71c777081b42d9e
This commit is contained in:
committed by
Copybara-Service
parent
222ee00a66
commit
49dd6b4193
@@ -960,7 +960,7 @@ mj_name2id
|
|||||||
|
|
||||||
.. mujoco-include:: mj_name2id
|
.. mujoco-include:: mj_name2id
|
||||||
|
|
||||||
Get id of object with specified name, return -1 if not found; type is mjtObj.
|
Get id of object with the specified mjtObj type and name, returns -1 if id not found.
|
||||||
|
|
||||||
.. _mj_id2name:
|
.. _mj_id2name:
|
||||||
|
|
||||||
@@ -969,7 +969,7 @@ mj_id2name
|
|||||||
|
|
||||||
.. mujoco-include:: mj_id2name
|
.. mujoco-include:: mj_id2name
|
||||||
|
|
||||||
Get name of object with specified id, return 0 if invalid type or id; type is mjtObj.
|
Get name of object with the specified mjtObj type and id, returns ``NULL`` if name not found.
|
||||||
|
|
||||||
.. _mj_fullM:
|
.. _mj_fullM:
|
||||||
|
|
||||||
|
|||||||
@@ -400,10 +400,10 @@ MJAPI void mj_jacSite(const mjModel* m, const mjData* d, mjtNum* jacp, mjtNum* j
|
|||||||
MJAPI void mj_jacPointAxis(const mjModel* m, mjData* d, mjtNum* jacPoint, mjtNum* jacAxis,
|
MJAPI void mj_jacPointAxis(const mjModel* m, mjData* d, mjtNum* jacPoint, mjtNum* jacAxis,
|
||||||
const mjtNum point[3], const mjtNum axis[3], int body);
|
const mjtNum point[3], const mjtNum axis[3], int body);
|
||||||
|
|
||||||
// Get id of object with specified name, return -1 if not found; type is mjtObj.
|
// Get id of object with the specified mjtObj type and name, returns -1 if id not found.
|
||||||
MJAPI int mj_name2id(const mjModel* m, int type, const char* name);
|
MJAPI int mj_name2id(const mjModel* m, int type, const char* name);
|
||||||
|
|
||||||
// Get name of object with specified id, return 0 if invalid type or id; type is mjtObj.
|
// Get name of object with the specified mjtObj type and id, returns NULL if name not found.
|
||||||
MJAPI const char* mj_id2name(const mjModel* m, int type, int id);
|
MJAPI const char* mj_id2name(const mjModel* m, int type, int id);
|
||||||
|
|
||||||
// Convert sparse inertia matrix M into full (i.e. dense) matrix.
|
// Convert sparse inertia matrix M into full (i.e. dense) matrix.
|
||||||
|
|||||||
@@ -2184,7 +2184,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
doc='Get id of object with specified name, return -1 if not found; type is mjtObj.', # pylint: disable=line-too-long
|
doc='Get id of object with the specified mjtObj type and name, returns -1 if id not found.', # pylint: disable=line-too-long
|
||||||
)),
|
)),
|
||||||
('mj_id2name',
|
('mj_id2name',
|
||||||
FunctionDecl(
|
FunctionDecl(
|
||||||
@@ -2208,7 +2208,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
|||||||
type=ValueType(name='int'),
|
type=ValueType(name='int'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
doc='Get name of object with specified id, return 0 if invalid type or id; type is mjtObj.', # pylint: disable=line-too-long
|
doc='Get name of object with the specified mjtObj type and id, returns NULL if name not found.', # pylint: disable=line-too-long
|
||||||
)),
|
)),
|
||||||
('mj_fullM',
|
('mj_fullM',
|
||||||
FunctionDecl(
|
FunctionDecl(
|
||||||
|
|||||||
+15
-14
@@ -636,8 +636,8 @@ uint64_t mj_hashdjb2(const char* s, uint64_t n) {
|
|||||||
return h % n;
|
return h % n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get id of object with the specified mjtObj type and name,
|
||||||
// get id of object with specified name; -1: not found
|
// returns -1 if id not found
|
||||||
int mj_name2id(const mjModel* m, int type, const char* name) {
|
int mj_name2id(const mjModel* m, int type, const char* name) {
|
||||||
int mapadr;
|
int mapadr;
|
||||||
int* adr = 0;
|
int* adr = 0;
|
||||||
@@ -652,19 +652,23 @@ int mj_name2id(const mjModel* m, int type, const char* name) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
int j = m->names_map[mapadr + i];
|
int j = m->names_map[mapadr + i];
|
||||||
if (j < 0) return -1;
|
if (j<0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!strncmp(name, m->names+adr[j], m->nnames-adr[j])) {
|
if (!strncmp(name, m->names+adr[j], m->nnames-adr[j])) {
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
if (++i == num) i = 0;
|
if ((++i)==num) i = 0;
|
||||||
} while(i != hash);
|
} while (i!=hash);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// get name of object with specified id; 0: invalid type or id, or null name
|
// get name of object with the specified mjtObj type and id,
|
||||||
|
// returns NULL if name not found
|
||||||
const char* mj_id2name(const mjModel* m, int type, int id) {
|
const char* mj_id2name(const mjModel* m, int type, int id) {
|
||||||
int mapadr;
|
int mapadr;
|
||||||
int* adr = 0;
|
int* adr = 0;
|
||||||
@@ -672,15 +676,12 @@ const char* mj_id2name(const mjModel* m, int type, int id) {
|
|||||||
// get number of objects and name addresses
|
// get number of objects and name addresses
|
||||||
int num = _getnumadr(m, type, &adr, &mapadr);
|
int num = _getnumadr(m, type, &adr, &mapadr);
|
||||||
|
|
||||||
if (id>=0 && id<num) {
|
// id is in [0, num) and the found name is not the empty string "\0"
|
||||||
if (m->names[adr[id]]) {
|
if (id>=0 && id<num && m->names[adr[id]]) {
|
||||||
return m->names+adr[id];
|
return m->names+adr[id];
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -81,10 +81,10 @@ MJAPI int mj_jacDifPair(const mjModel* m, const mjData* d, int* chain,
|
|||||||
// get string hash, see http://www.cse.yorku.ca/~oz/hash.html
|
// get string hash, see http://www.cse.yorku.ca/~oz/hash.html
|
||||||
uint64_t mj_hashdjb2(const char* s, uint64_t n);
|
uint64_t mj_hashdjb2(const char* s, uint64_t n);
|
||||||
|
|
||||||
// get id of object with specified name; -1: not found; type is mjtObj
|
// get id of object with the specified mjtObj type and name, returns -1 if id not found
|
||||||
MJAPI int mj_name2id(const mjModel* m, int type, const char* name);
|
MJAPI int mj_name2id(const mjModel* m, int type, const char* name);
|
||||||
|
|
||||||
// get name of object with specified id; 0: invalid type or id; type is mjtObj
|
// get name of object with the specified mjtObj type and id, returns NULL if name not found
|
||||||
MJAPI const char* mj_id2name(const mjModel* m, int type, int id);
|
MJAPI const char* mj_id2name(const mjModel* m, int type, int id);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user