Replace PointToLocal with operator overload in mjCDef.
PiperOrigin-RevId: 609376948 Change-Id: Id69909d06ab48824a9cbe0d5a305e8f8b72a193d
This commit is contained in:
committed by
Copybara-Service
parent
cf7bd77cd3
commit
0ae9ba37f9
@@ -405,7 +405,6 @@ int mjm_getId(mjElement element) {
|
||||
void mjm_setDefault(mjElement element, mjmDefault* defspec) {
|
||||
mjCBase* baseC = reinterpret_cast<mjCBase*>(element);
|
||||
baseC->def = reinterpret_cast<mjCDef*>(defspec->element);
|
||||
baseC->def->PointToLocal();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -125,13 +125,6 @@ bool mjCComposite::AddDefaultJoint(char* error, int error_sz) {
|
||||
jnt.spec.joint->group = 3;
|
||||
defjoint[(mjtCompKind)i].push_back(jnt);
|
||||
}
|
||||
|
||||
// TODO: push_back might invoke a copy constructor, we undo its effect on pointers here
|
||||
for (int i=0; i<mjNCOMPKINDS; i++) {
|
||||
for (int j=0; j<defjoint[(mjtCompKind)i].size(); j++) {
|
||||
defjoint[(mjtCompKind)i][j].PointToLocal();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -543,7 +543,6 @@ mjCDef* mjCModel::AddDef(string name, int parentid) {
|
||||
if (parentid>=0 && parentid<thisid) {
|
||||
*def = *defaults[parentid];
|
||||
defaults[parentid]->childid.push_back(thisid);
|
||||
def->PointToLocal();
|
||||
}
|
||||
def->parentid = parentid;
|
||||
def->name = name;
|
||||
|
||||
@@ -483,11 +483,20 @@ mjCDef::mjCDef(void) {
|
||||
mjm_defaultEquality(equality.spec);
|
||||
mjm_defaultTendon(tendon.spec);
|
||||
mjm_defaultActuator(actuator.spec);
|
||||
|
||||
// make sure all the pointers are local
|
||||
PointToLocal();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// copy constructor
|
||||
mjCDef::mjCDef(const mjCDef& other) {
|
||||
*this = other;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// compiler
|
||||
void mjCDef::Compile(const mjCModel* model) {
|
||||
// enforce length of all default userdata arrays
|
||||
@@ -501,7 +510,31 @@ void mjCDef::Compile(const mjCModel* model) {
|
||||
|
||||
|
||||
|
||||
// assignment operator (TODO: use overloading)
|
||||
// assignment operator
|
||||
mjCDef& mjCDef::operator=(const mjCDef& other) {
|
||||
if (this != &other) {
|
||||
name = other.name;
|
||||
parentid = other.parentid;
|
||||
childid = other.childid;
|
||||
joint = other.joint;
|
||||
geom = other.geom;
|
||||
site = other.site;
|
||||
camera = other.camera;
|
||||
light = other.light;
|
||||
flex = other.flex;
|
||||
mesh = other.mesh;
|
||||
material = other.material;
|
||||
pair = other.pair;
|
||||
equality = other.equality;
|
||||
tendon = other.tendon;
|
||||
actuator = other.actuator;
|
||||
}
|
||||
PointToLocal();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mjCDef::PointToLocal() {
|
||||
joint.PointToLocal();
|
||||
geom.PointToLocal();
|
||||
|
||||
@@ -1394,9 +1394,11 @@ class mjCDef {
|
||||
friend class mjXWriter;
|
||||
|
||||
public:
|
||||
mjCDef(void); // constructor
|
||||
void Compile(const mjCModel* model); // compiler
|
||||
void PointToLocal();
|
||||
mjCDef(void); // constructor
|
||||
mjCDef(const mjCDef& other); // copy constructor
|
||||
void Compile(const mjCModel* model); // compiler
|
||||
mjCDef& operator=(const mjCDef& other); // copy assignment
|
||||
void PointToLocal(void);
|
||||
|
||||
// identifiers
|
||||
std::string name; // class name
|
||||
|
||||
Reference in New Issue
Block a user