TEST_F(MassSpringConstraintFixedPointTest, ConstraintConstantsTest) { auto implementation = std::make_shared<MassSpringConstraintFixedPoint>(); EXPECT_EQ(SurgSim::Physics::FIXED_3DPOINT, implementation->getConstraintType()); EXPECT_EQ(3u, implementation->getNumDof()); }
/** * Read and store a constraint from the given file. * * Returns 0 if the process finished correctly, otherwise returns 1. */ int readConstraint( char buf[], FILE* fp, double* a, double* b, int* equalityType, int variables ){ char *stringPointer; if( NULL == fgets(buf, MAX_LINE_LENGTH, fp) ) // read in buf return FAILURE; // sets the pointer to the start the of the string to check some stuff stringPointer = &buf[0]; // find the position of the first wrong symbol in that line, if some exists int posWrongSymbol = strspn(stringPointer, "#-0123456789.<=> "); // find the position of a comment char *posComment = strchr(stringPointer, '#'); // difference between comment and code ptrdiff_t diff = posComment-stringPointer; // if a wrong symbol comes before a comment starts stop all calculations if ( diff > posWrongSymbol-1 || (posWrongSymbol < strlen(stringPointer)-1 && diff < 0 ) ){ printf("[ERROR] Found undefined characters at position %d.\n", posWrongSymbol); return FAILURE; } // if there are no whitespaces or something other weired stuff happened, stopp all calculations if ( NULL == (stringPointer = strtok(buf, " ")) ){ printf("[ERROR] Cannot split the given constraint on whitespaces.\n"); return FAILURE; } // otherwise read in all coefficients int i; for ( i = 0; i < variables; i++ ){ // if the followed section is not a number if ( strspn(stringPointer, "-.0123456789") < strlen(stringPointer) ){ printf( "[ERROR] Not a number at position %d\n", (i+1)); return FAILURE; } else sscanf( stringPointer, "%lf", (a+i) ); // null pointer check if ( NULL == (stringPointer = strtok(NULL, " ")) ){ printf( "[ERROR] Reached line end after %d coefficients... expected more information for this constraint.\n", (i+1)); return FAILURE; } } // if equality type doesn't exist, stop calculations if ( NONE == (*equalityType = getConstraintType(stringPointer)) ){ printf("[ERROR] Undefined constraint type. Try '<', '<=', '=', '>=' or '>'.\n"); return FAILURE; } else if ( NULL == (stringPointer = strtok(NULL, " ")) ){ printf("[ERROR] Reached line end... expected a solution value.\n"); return FAILURE; } else sscanf( stringPointer, "%lf", b ); return DONE; }
int GOConstraint::methodsBridge(lua_State* luaVM) { if (isCurrentMethod("getFullID")) { lua_pushstring(luaVM, id.c_str()); return 1; } if (isCurrentMethod("setPivot")) { setPivot(CVector(lua_tonumber(luaVM, 1), lua_tonumber(luaVM, 2), lua_tonumber(luaVM, 3))); return 0; } if (isCurrentMethod("getPivot")) { luaPushVector(luaVM, getPivot().x, getPivot().y, getPivot().z); return 1; } if (isCurrentMethod("getConstraintType")) { lua_pushinteger(luaVM, getConstraintType()); return 1; } if (isCurrentMethod("setSecondObject")) { if (lua_isnil(luaVM, 1)) { setSecondObject(NULL); return 0; } lua_pushstring(luaVM, "cpointer"); lua_gettable(luaVM, -2); PhysicObject* o = (PhysicObject*)lua_tointeger(luaVM, -1); setSecondObject(o); lua_pop(luaVM, -1); return 0; } if (isCurrentMethod("getSecondObject")) { if (getSecondObject() == NULL || getSecondObject()->getObjectID() == "") { lua_pushnil(luaVM); } lua_getglobal(luaVM, getSecondObject()->getObjectID().c_str()); return 1; } if (isCurrentMethod("setSecondPivot")) { setSecondPivot(CVector(lua_tonumber(luaVM, 1), lua_tonumber(luaVM, 2), lua_tonumber(luaVM, 3))); return 0; } if (isCurrentMethod("getSecondPivot")) { luaPushVector(luaVM, getSecondPivot().x, getSecondPivot().y, getSecondPivot().z); return 1; } if (isCurrentMethod("setSecondObjectID")) { string objid = lua_tostring(luaVM, 1); PhysicObject* obj = (PhysicObject*)Game::instance->mapManager->findByID(objid); setSecondObject(obj); return 0; } if (isCurrentMethod("getSecondObjectID")) { if (getSecondObject() == NULL) { lua_pushstring(luaVM, ""); return 0; } lua_pushstring(luaVM, getSecondObject()->getObjectID().c_str()); return 1; } return LuaBridge::methodsBridge(luaVM); }