void test_conversion_no_expect(std::string unitString1, std::string unitString2) { ASSERT_NO_THROW(Unit unit1(unitString1.c_str())); ASSERT_NO_THROW(Unit unit2(unitString2.c_str())); Unit unit1(unitString1.c_str()); Unit unit2(unitString2.c_str()); UCFn *cf = (UCFn*) NULL; ASSERT_NO_THROW(cf = unit1.Conversion_to(&unit2)); clean_up_UCFn(&cf); ASSERT_EQ((UCFn*) NULL, cf); }
/*===========================================================================*/ void StochasticUniformGridRenderer::Engine::draw( kvs::ObjectBase* object, kvs::Camera* camera, kvs::Light* light ) { kvs::Texture::Binder unit0( m_volume_texture, 0 ); kvs::Texture::Binder unit1( m_exit_texture, 1 ); kvs::Texture::Binder unit2( m_entry_texture, 2 ); kvs::Texture::Binder unit3( m_transfer_function_texture, 3 ); kvs::Texture::Binder unit4( randomTexture(), 4 ); kvs::ProgramObject::Binder unit( m_ray_casting_shader ); if ( isEnabledShading() ) kvs::OpenGL::Enable( GL_LIGHTING ); else kvs::OpenGL::Disable( GL_LIGHTING ); const float f = camera->back(); const float n = camera->front(); const float to_zw1 = ( f * n ) / ( f - n ); const float to_zw2 = 0.5f * ( ( f + n ) / ( f - n ) ) + 0.5f; const float to_ze1 = 0.5f + 0.5f * ( ( f + n ) / ( f - n ) ); const float to_ze2 = ( f - n ) / ( f * n ); const kvs::Vector3f light_position = kvs::WorldCoordinate( light->position() ).toObjectCoordinate( object ).position(); const kvs::Vector3f camera_position = kvs::WorldCoordinate( camera->position() ).toObjectCoordinate( object ).position(); m_ray_casting_shader.setUniform( "to_zw1", to_zw1 ); m_ray_casting_shader.setUniform( "to_zw2", to_zw2 ); m_ray_casting_shader.setUniform( "to_ze1", to_ze1 ); m_ray_casting_shader.setUniform( "to_ze2", to_ze2 ); m_ray_casting_shader.setUniform( "light_position", light_position ); m_ray_casting_shader.setUniform( "camera_position", camera_position ); const size_t size = randomTextureSize(); const int count = repetitionCount() * ::RandomNumber(); const float offset_x = static_cast<float>( ( count ) % size ); const float offset_y = static_cast<float>( ( count / size ) % size ); const kvs::Vec2 random_offset( offset_x, offset_y ); m_ray_casting_shader.setUniform( "random_offset", random_offset ); this->draw_quad(); }
int main() { Entry test(20, 20, 0); Entry test2(21, 21, 1); Entry test3(23, 45, 1); Entry test4(23, 45, 1); Unit unit1(5, 2, 2, 0); unit1.storeEntry(0, test); unit1.storeEntry(0, test2); unit1.storeEntry(2, test3); unit1.storeEntry(5, test4); unit1.storeEntry(6, test4); cout << unit1 << endl; unit1.clearData(); unit1.storeEntryData(); Unit unit2(3, 2, 2, 0); unit2.storeEntry(0, test); unit2.storeEntry(1, test2); unit2.storeEntryData(); //unit1.storeEntryData(); cout << unit2 << endl; }
double TWEDMSet(MSet *arg1, MSet *arg2, Instant* tMax, Word &map) { bool debugme= true; ArgVectorPointer funargs = qp->Argument(map.addr); int n= arg1->GetNoComponents(),m= arg2->GetNoComponents(); vector< vector<double> > DTW(n, vector<double>(m, 10000)); USetRef unit1(false), unit2(false); Word mapRes; int cost=0; DTW[0][0]= 0; for (int i = 1 ; i< n; ++i) { arg1->Get(i, unit1); USet utmp1(false); unit1.GetUnit(arg1->data, utmp1); (*funargs)[0] = SetWord(&(utmp1.constValue)); for (int j = 1; j< m; ++j) { arg2->Get(j, unit2); USet utmp2(false); unit2.GetUnit(arg2->data, utmp2); (*funargs)[1] = SetWord(&(utmp2.constValue)); if( ((unit1.timeInterval.start > unit2.timeInterval.start) && (unit1.timeInterval.start - unit2.timeInterval.start < *tMax)) || ((unit2.timeInterval.start >= unit1.timeInterval.start) && (unit2.timeInterval.start - unit1.timeInterval.start < *tMax))) { qp->Request(map.addr, mapRes); CcBool* mr= static_cast<CcBool*>(mapRes.addr); cost =(mr->IsDefined() && mr->GetBoolval())? 0: 1; } else cost= 10000; DTW[i][j] = Min(Min( // insertion DTW[i-1][j] + 1 , // deletion DTW[i][j-1] + 1), // match DTW[i-1][j-1] + cost) ; if(debugme) { cerr<<"\n Cost = "<< cost; cerr<<"\n DTW[i-1][j] + 1 = "<< DTW[i-1][j] + 1; cerr<<"\n DTW[i][j-1] + 1 = "<< DTW[i][j-1] + 1; cerr<<"\n DTW[i-1][j-1] + cost = "<< DTW[i-1][j-1] + cost; cerr<<"\n DTW[i][j] = "<< DTW[i][j]; } } } return DTW[n-1][m-1]; }
void test_conversion_no_throw(std::string unitString1, std::string unitString2, double expected_offset, double expected_scale, double tolerance = TOL) { ASSERT_NO_THROW(Unit unit1(unitString1.c_str())); ASSERT_NO_THROW(Unit unit2(unitString2.c_str())); Unit unit1(unitString1.c_str()); Unit unit2(unitString2.c_str()); UCFn *cf = (UCFn*) NULL; ASSERT_NO_THROW(cf = unit1.Conversion_to(&unit2)); EXPECT_NEAR(expected_offset, cf->C[0], tolerance ); EXPECT_NEAR(expected_scale, cf->C[1], tolerance ); clean_up_UCFn(&cf); ASSERT_EQ((UCFn*) NULL, cf); units_requirements(false); }
TEST(AreaUnitTest, Can_Create_Via_Assign) { // Arrange AreaUnit unit1(1, "kg"); AreaUnit unit2(1000, "t"); // Act unit2 = unit1; // Assert EXPECT_EQ(unit1, unit2); }
void test_conversion_throw(std::string unitString1, std::string unitString2) { ASSERT_NO_THROW(Unit unit1(unitString1.c_str())); ASSERT_NO_THROW(Unit unit2(unitString2.c_str())); Unit unit1(unitString1.c_str()); Unit unit2(unitString2.c_str()); UCFn* cf = (UCFn*) NULL; std::cerr << "The purpose of this test is to throw to an exception. Error messages are expected." << std::endl; ASSERT_THROW(cf = unit1.Conversion_to(&unit2), Unit::CONVERSION_ERROR); if(cf!= (UCFn*) NULL) { clean_up_UCFn(&cf); } ASSERT_EQ((UCFn*) NULL, cf); units_requirements(true); }
void SceneHandler::addUnit(Behaviours* behaviour, GameState::Enum state) { if (state != GameState::SCENARIO) { std::shared_ptr<Unit> unit(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), state)); m_unitObjects.push_back(unit); } else { m_leader = new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), state); std::shared_ptr<Unit> unit1(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit1->m_fixRotation = 30; m_team.push_back(unit1); std::shared_ptr<Unit> unit2(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit2->m_fixRotation = 60; m_team.push_back(unit2); std::shared_ptr<Unit> unit3(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit3->m_fixRotation = 90; m_team.push_back(unit3); std::shared_ptr<Unit> unit4(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit4->m_fixRotation = 120; m_team.push_back(unit4); std::shared_ptr<Unit> unit5(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit5->m_fixRotation = 150; m_team.push_back(unit5); std::shared_ptr<Unit> unit6(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit6->m_fixRotation = 180; m_team.push_back(unit6); std::shared_ptr<Unit> unit7(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::TEAM)); unit7->m_fixRotation = 210; m_team.push_back(unit7); std::shared_ptr<Unit> enemie1(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE1)); m_unitObjects.push_back(enemie1); std::shared_ptr<Unit> enemie2(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE2)); m_unitObjects.push_back(enemie2); std::shared_ptr<Unit> enemie3(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE3)); m_unitObjects.push_back(enemie3); std::shared_ptr<Unit> enemie4(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE4)); m_unitObjects.push_back(enemie4); std::shared_ptr<Unit> enemie5(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE5)); m_unitObjects.push_back(enemie5); std::shared_ptr<Unit> enemie6(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE6)); m_unitObjects.push_back(enemie6); std::shared_ptr<Unit> enemie7(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE7)); m_unitObjects.push_back(enemie7); std::shared_ptr<Unit> enemie8(new Unit(behaviour, sf::Sprite(m_unitTexture, sf::IntRect(0, 0, 32, 32)), GameState::ENEMIE8)); m_unitObjects.push_back(enemie8); } }
void QMatrixReconstruction(NoiseCovariance& N, string outfilename){ cout << endl << "Now reconstructing Q from basis vectors..." << endl; //vector< vector< vector<double> > > reconstructed(kParaBins*kPerpBins, vector< vector<double> >(xBins*yBins*fBins, vector<double>(xBins*yBins*fBins,0))); vector< vector<double> > reconstructed(kParaBins*kPerpBins, vector<double>(fBins, 0)); for (int k1 = 0; k1 < fBins; k1++){ cout << " " << floor(100.0 * k1/fBins) << "% done.\r" << std::flush; for (int i1 = 0; i1 < 1; i1++){ for (int j1 = 0; j1 < 1; j1++){ /* for (int i2 = 0; i2 < xBins; i2++){ for (int j2 = 0; j2 < yBins; j2++){ for (int k2 = 0; k2 < fBins; k2++){ */ for (int i2 = 0; i2 < 1; i2++){ for (int j2 = 0; j2 < 1; j2++){ for (int k2 = 0; k2 < 1; k2++){ CVector unit1(s); CVector unit2(s); int here1 = i1*yBins*fBins + j1*fBins + k1; int here2 = i2*yBins*fBins + j2*fBins + k2; unit1.real[here1] = 1.0; unit2.real[here2] = 1.0; CVector P = bandPowerSpectrum(unit1, unit2, N, true); for (int n = 0; n < kParaBins*kPerpBins; n++) reconstructed[n][here1]/*[here2]*/ = 2*P.real[n]; } } } } } } cout << "Done. " << endl; ofstream outfile; //outfile.precision(30); outfile.open(outfilename.c_str(), ios::trunc); for (int n = 0; n < kParaBins*kPerpBins; n++){ for (int i = 0; i < fBins; i++){ //for (int j = 0; j < xBins*yBins*fBins; j++){ outfile << reconstructed[n][i]/*[j]*/ << " "; //} //outfile << endl; } outfile << endl << endl; } outfile.close(); }
void doThings(lua_State* L) { // load the function. load(L, "functions.lua"); // load the Unit Wrapper. loadWrapper(L); ApplyDamageFunction damageFunction("applyDamage"); Unit unit1(12, 30); Unit unit2(7, 40); std::cout << "Health of unit1 and unit2 before unit1 deals damage to unit2 : [Unit1 : " << unit1.health << "] [Unit2 : " << unit2.health << "]" << std::endl; damageFunction.applyDamage(L, unit1, unit2); std::cout << "Health of unit1 and unit2 after unit1 deals damage to unit2 : [Unit1 : " << unit1.health << "] [Unit2 : " << unit2.health << "]" << std::endl; damageFunction.applyDamage(L, unit2, unit1); std::cout << "Health of unit1 and unit2 after unit2 deals damage to unit1 : [Unit1 : " << unit1.health << "] [Unit2 : " << unit2.health << "]" << std::endl; }
void Test::setupScenario(RVO::RVOSimulator* sim) { /* Specify the default parameters for agents that are subsequently added. */ float radius = 2.0f; sim->setAgentDefaults(15.0f, 10, 5.0f, 5.0f, radius, 150.0f); /* * Add agents, specifying their start position, and store their goals on the * opposite side of the environment. */ for (int i = 0; i < 100; ++i) { for (int j = 0; j < 15; ++j) { GameUnitT unit(radius); unit.agentNo = sim->addAgent(RVO::Vector2(55.0f + i * 10.0f, 55.0f + j * 10.0f)); goals.push_back(RVO::Vector2(-1075.0f, -1075.0f)); unit.updatePosition(RVO::Vector2(-1075.0f, -1075.0f)); mUnits.push_back(unit); GameUnitT unit2(radius); unit2.agentNo = sim->addAgent(RVO::Vector2(-55.0f - i * 10.0f, 55.0f + j * 10.0f)); goals.push_back(RVO::Vector2(1075.0f, -1075.0f)); unit2.updatePosition(RVO::Vector2(1075.0f, -1075.0f)); mUnits.push_back(unit2); GameUnitT unit3(radius); unit3.agentNo = sim->addAgent(RVO::Vector2(55.0f + i * 10.0f, -55.0f - j * 10.0f)); goals.push_back(RVO::Vector2(-1075.0f, 1075.0f)); unit3.updatePosition(RVO::Vector2(-1075.0f, 1075.0f)); mUnits.push_back(unit3); GameUnitT unit4(radius); unit4.agentNo = sim->addAgent(RVO::Vector2(-55.0f - i * 10.0f, -55.0f - j * 10.0f)); goals.push_back(RVO::Vector2(1075.0f, 1075.0f)); unit4.updatePosition(RVO::Vector2(1075.0f, 1075.0f)); mUnits.push_back(unit4); } } /* * Add (polygonal) obstacles, specifying their vertices in counterclockwise * order. */ std::vector<RVO::Vector2> obstacle1, obstacle2, obstacle3, obstacle4; obstacle1.push_back(RVO::Vector2(-1010.0f, 1040.0f)); obstacle1.push_back(RVO::Vector2(-1040.0f, 1040.0f)); obstacle1.push_back(RVO::Vector2(-1040.0f, 1010.0f)); obstacle1.push_back(RVO::Vector2(-1010.0f, 1010.0f)); obstacle2.push_back(RVO::Vector2(1010.0f, 1040.0f)); obstacle2.push_back(RVO::Vector2(1010.0f, 1010.0f)); obstacle2.push_back(RVO::Vector2(1040.0f, 1010.0f)); obstacle2.push_back(RVO::Vector2(1040.0f, 1040.0f)); obstacle3.push_back(RVO::Vector2(1010.0f, -1040.0f)); obstacle3.push_back(RVO::Vector2(1040.0f, -1040.0f)); obstacle3.push_back(RVO::Vector2(1040.0f, -1010.0f)); obstacle3.push_back(RVO::Vector2(1010.0f, -1010.0f)); obstacle4.push_back(RVO::Vector2(-1010.0f, -1040.0f)); obstacle4.push_back(RVO::Vector2(-1010.0f, -1010.0f)); obstacle4.push_back(RVO::Vector2(-1040.0f, -1010.0f)); obstacle4.push_back(RVO::Vector2(-1040.0f, -1040.0f)); sim->addObstacle(obstacle1); sim->addObstacle(obstacle2); sim->addObstacle(obstacle3); sim->addObstacle(obstacle4); drawObstacle(obstacle1); drawObstacle(obstacle2); drawObstacle(obstacle3); drawObstacle(obstacle4); /* Process the obstacles so that they are accounted for in the simulation. */ sim->processObstacles(); }
int wedge(FLOAT halves[][2], int m, int next[], int prev[], FLOAT cw_vec[], FLOAT ccw_vec[], int *degen) { int i; FLOAT d_cw, d_ccw; int offensive; *degen = 0; for(i=0;i!=m;i = next[i]) { if(!unit2(halves[i],ccw_vec,EPS)) { /* clock-wise */ cw_vec[0] = ccw_vec[1]; cw_vec[1] = -ccw_vec[0]; /* counter-clockwise */ ccw_vec[0] = -cw_vec[0]; ccw_vec[1] = -cw_vec[1]; break; } } if(i==m) return(UNBOUNDED); i = 0; while(i!=m) { offensive = 0; d_cw = dot2(cw_vec,halves[i]); d_ccw = dot2(ccw_vec,halves[i]); if(d_ccw >= 2*EPS) { if(d_cw <= -2*EPS) { cw_vec[0] = halves[i][1]; cw_vec[1] = -halves[i][0]; (void)unit2(cw_vec,cw_vec,EPS); offensive = 1; } } else if(d_cw >= 2*EPS) { if(d_ccw <= -2*EPS) { ccw_vec[0] = -halves[i][1]; ccw_vec[1] = halves[i][0]; (void)unit2(ccw_vec,ccw_vec,EPS); offensive = 1; } } else if(d_ccw <= -2*EPS && d_cw <= -2*EPS) { return(INFEASIBLE); } else if((d_cw <= -2*EPS) || (d_ccw <= -2*EPS) || (cross2(cw_vec,halves[i]) < 0.0)) { /* degenerate */ if(d_cw <= -2*EPS) { (void)unit2(ccw_vec,cw_vec,EPS); } else if(d_ccw <= -2*EPS) { (void)unit2(cw_vec,ccw_vec,EPS); } *degen = 1; offensive = 1; } /* place this offensive plane in second place */ if(offensive) i = move_to_front(i,next,prev); i = next[i]; if(*degen) break; } if(*degen) { while(i!=m) { d_cw = dot2(cw_vec,halves[i]); d_ccw = dot2(ccw_vec,halves[i]); if(d_cw < -2*EPS) { if(d_ccw < -2*EPS) { return(INFEASIBLE); } else { cw_vec[0] = ccw_vec[0]; cw_vec[1] = ccw_vec[1]; } } else if(d_ccw < -2*EPS) { ccw_vec[0] = cw_vec[0]; ccw_vec[1] = cw_vec[1]; } i = next[i]; } } return(MINIMUM); }
int main (void){ banner(); unit1(); unit2(); bye(); }