// Exact solution. double exact_solution(double x, double y, double z, double &dx, double &dy, double &dz) { dx = -0.5 * x * l0(y) * l1(y) * l0(z) * l1(z); dy = -0.5 * y * l0(x) * l1(x) * l0(z) * l1(z); dz = -0.5 * z * l0(x) * l1(x) * l0(y) * l1(y); return l0(x) * l1(x) * l0(y) * l1(y) * l0(z) * l1(z); }
void CVMath::setupMatrixM2() { Line r1 = Points::getInstance().getR1(); Line r2 = Points::getInstance().getR2(); Line r3 = Points::getInstance().getR3(); Line r4 = Points::getInstance().getR4(); l0 << r1.x, r1.y, r1.z; m0 << r2.x, r2.y, r2.z; l1 << r3.x, r3.y, r3.z; m1 << r4.x, r4.y, r4.z; MatrixXd LT_M = MatrixXd(2, 3); LT_M << l0(0)*m0(0), l0(0)*m0(1) + l0(1)*m0(0), l0(1)*m0(1), l1(0)*m1(0), l1(0)*m1(1) + l1(1)*m1(0), l1(1)*m1(1); JacobiSVD<MatrixXd> svdA (LT_M, Eigen::ComputeFullV); VectorXd x = svdA.matrixV().col(2); MatrixXd KKT = MatrixXd(2, 2); KKT << x(0), x(1), x(1), x(2); MatrixXd HHT = MatrixXd(3, 3); HHT << x(0), x(1), 0, x(1), x(2), 0, 0, 0, 0; MatrixXd aux = MatrixXd(2, 2); aux = HHT.llt().matrixU(); std::cout << x << std::endl; std::cout << aux << std::endl; Hp = MatrixXd(3, 3); //add 1 ao final para se tornar inversivel Hp << aux(0,0), aux(0,1), 0, 0, aux(1, 1), 0, 0, 0, 1; std::cout << Hp << std::endl; Hp_INV = MatrixXd(3, 3); Hp_INV = Hp.inverse().eval(); std::cout << Hp_INV << std::endl; }
static void ok_start_game(int fd) { struct game * g = find_game_by_fd(fd); if (g) { if (g->status == GAME_STATUS_PLAYING) { int i; for (i = 0; i < g->players_number; i++) { if (g->players_conn[i] == fd) { if (!g->players_started[i]) { if (remote_proto_minor[g->players_conn[i]] >= 1) send_ok(fd, "OK_GAME_START"); g->players_started[i] = 1; l1(OUTPUT_TYPE_DEBUG, "[%d] entering prio mode", g->players_conn[i]); add_prio(g->players_conn[i]); } else { send_line_log(fd, wn_already_ok_started, "OK_GAME_START"); } } } } else { send_line_log(fd, wn_not_started, "OK_GAME_START"); } } else { l0(OUTPUT_TYPE_ERROR, "Internal error"); exit(EXIT_FAILURE); } }
int main(int argc, char *argv[]){ std::vector<int> v0(10); //Vektor mit 10 plaetzen for(std::vector<int>::iterator it = v0.begin(); //iteriert ueber den Vektor it != v0.end(); ++it){ *it = std::rand(); //belegt Plaetze mit Zufallszahlen } //uebergibt die Werte von v0 an Ausgabe std::copy(std::begin(v0), std::end(v0), std::ostream_iterator<int>(std::cout, "\n")); std::list<int> l0(v0.size()); // legt Liste an fuer alle Werte aus v0 std::copy(std::begin(v0), std::end(v0), std::begin(l0)); std::list<int> l1(std::begin(l0), std::end(l0)); //legt neue Liste an mit Werten aus l0 std::reverse(std::begin(l1), std::end(l1)); //dreht die Werte aus l1 um std::copy(std::begin(l1), std::end(l1), std::ostream_iterator<int>(std::cout, "\n")); //gibt l1 umgedreht aus l1.sort(); //sortiert l1 std::copy(l1.begin(), l1.end(), std::ostream_iterator<int>(std::cout, "\n")); //gibt l1 sortiert aus std::generate(std::begin(v0), std::end(v0), std::rand); //bekommt Vektor uebergeben und belegt mit neuen Werten, Zufallszahlen std::copy(v0.rbegin(), v0.rend(), std::ostream_iterator<int>(std::cout, "\n")); return Catch::Session().run(argc, argv); }
Line* Text::FindNext(int m) { Line *l; Line l0("#"); l0.next = first; if(m) l = &l0; else l = find; int f=1; if(l!=NULL) { while(f) { l=l->next; if(l==NULL) break; f=5; if(find_str==NULL) f--; else{if(!strcmp(find_str,l->str)) f--;} if(find_type==-1) f--; else{if(find_type==l->type) f--;} if(find_id==-1) f--; else{if(find_id==l->id) f--;} if(find_id2==-1) f--; else{if(find_id2==l->id2) f--;} if(find_adr==0xFFFF) f--; else{if(find_adr==l->adr) f--;} } } find = l; return l; }
void test_flash_led() { ngac ac("ac1", 0, 5, 1); ngresistor r("r1", 370); ngled led("led1", 5e-3); ngground gnd; ngline l0(ac.p1, gnd.p1); ngline l1(ac.p2, r.p1); ngline l2(r.p2, led.p1); ngline l3(led.p2, ac.p1); schema sch; sch.AddDevices(&ac, &r, &led, &gnd, 0); sch.AddLines(&l0, &l1, &l2, &l3, 0); circuit cir(&sch); cir.Tran("2", "10m"); do { Sleep(200); } while (cir.IsRunning()); getchar(); }
dgFloat32 dgBody::RayCast (const dgLineBox& line, OnRayCastAction filter, OnRayPrecastAction preFilter, void* const userData, dgFloat32 maxT) const { dgAssert (filter); dgVector l0 (line.m_l0); dgVector l1 (line.m_l0 + (line.m_l1 - line.m_l0).Scale4 (dgMin(maxT, dgFloat32 (1.0f)))); if (dgRayBoxClip (l0, l1, m_minAABB, m_maxAABB)) { // if (1) { //l0 = dgVector (-20.3125000f, 3.54991579f, 34.3441200f, 0.0f); //l1 = dgVector (-19.6875000f, 3.54257250f, 35.2211456f, 0.0f); dgContactPoint contactOut; const dgMatrix& globalMatrix = m_collision->GetGlobalMatrix(); dgVector localP0 (globalMatrix.UntransformVector (l0)); dgVector localP1 (globalMatrix.UntransformVector (l1)); dgVector p1p0 (localP1 - localP0); if ((p1p0 % p1p0) > dgFloat32 (1.0e-12f)) { dgFloat32 t = m_collision->RayCast (localP0, localP1, dgFloat32 (1.0f), contactOut, preFilter, this, userData); if (t < dgFloat32 (1.0f)) { dgVector p (globalMatrix.TransformVector(localP0 + (localP1 - localP0).Scale3(t))); dgVector l1l0 (line.m_l1 - line.m_l0); t = ((p - line.m_l0) % l1l0) / (l1l0 % l1l0); if (t < maxT) { dgAssert (t >= dgFloat32 (0.0f)); dgAssert (t <= dgFloat32 (1.0f)); contactOut.m_normal = globalMatrix.RotateVector (contactOut.m_normal); maxT = filter (this, contactOut.m_collision0, p, contactOut.m_normal, contactOut.m_shapeId0, userData, t); } } } } return maxT; }
void reregister_server_if_needed() { time_t current_time; if (last_server_register == -1 || interval_reregister == 0) // feature disabled return; // don't stack zombies, do minimal housework waitpid(-1, NULL, WNOHANG); current_time = get_current_time(); if ((current_time - last_server_register)/60 >= interval_reregister) { l0(OUTPUT_TYPE_INFO, "Reregistering to master server"); last_server_register = current_time; int pid = fork(); if (pid < 0) { l1(OUTPUT_TYPE_ERROR, "Cannot fork: %s", strerror(errno)); return; } if (pid == 0) { // Need to register from a separate process because master server will test us register_server(1); _exit(EXIT_SUCCESS); } } }
int main () { std::vector<int> v0(10); // Erstellt Vektor v0 mit 10 Speicherplaetzen for (std::vector<int>::iterator it = v0.begin(); it != v0.end(); ++it) { // iteriert ueber den Vektor von Beginn (0) bis Ende (9) und erhoeht i um 1 *it = std::rand(); // belegt diese Plaetze mit Zufallszahlen } // oder //for (auto& v : v0) { // v = std::rand(); //} // Uebergibt den Inhalt v0 an Ausgabeiterator, der diese ausgibt std::copy(std::begin(v0), std::end(v0), std::ostream_iterator<int>(std::cout, "\n")); std::list<int> l0(v0.size()); // erstellt Liste l0 mit der Groeße von v0 std::copy(std::begin(v0), std::end(v0), std::begin(l0)); // kopiert den Inhalt von v0 in l0 (Ziel ist Anfang l0) std::list<int> l1(std::begin(l0), std::end(l0)); // erstellt Liste l1 und uebernimmt alle Parameter von l0 std::reverse(std::begin(l1), std::end(l1)); // dreht die Reihenfolge der Listen-Elemente um std::copy(std::begin(l1), std::end(l1), std::ostream_iterator<int>(std::cout, "\n")); // und gibt die Liste l1 aus // sortiert die Liste l1 nach aufsteigender Reihenfolge. Die Reihenfolge gleicher Elemente bleibt bestehen l1.sort(); std::copy( l1.begin(), l1.end(), std::ostream_iterator<int>(std::cout, "\n")); // gibt die sortierte Liste l1 aus std::generate(std::begin(v0), std::end(v0), std::rand); // belegt den Vektor v0 mit Zufallszahlen (generate gibt uebergebenen Elementen neuen Wert letzter Parameter ist dazu genutzte Funktion) std::copy( v0.rbegin(), v0.rend(), std::ostream_iterator<int>(std::cout, "\n")); // Iterator gibt die Elemente von v0 in umgekehrter Reihenfolgen aus return 0; }
int main() { vec v1(1, 1), v2(0, 2); cout << "vec1(1,1) cross vec2(0,2): " << cross(v1, v2) << endl << endl; node p0(0, 0), p1(0, 1), p2(1, 2), p3(2, 1), p4(2, 0), p5(1, 0), p6(1, 1); node s[7]; s[0] = p4, s[1] = p3, s[2] = p2, s[3] = p1, s[4] = p0, s[5] = p5, s[6] = p6; segment l0(p0, p3), l1(p5, p6), l2(p6, p4), l3(p1, p2); test_segment(l0, l1); test_segment(l1, l2); test_segment(l0, l3); segment ll[4]; ll[0] = l0, ll[1] = l1, ll[2] = l2, ll[3] = l3; for(int i = 0; i < 4; ++ i) { ll[i].s_lt.n_idx = i; ll[i].s_rt.n_idx = i; ll[i].s_lt.n_lt = 1; ll[i].s_rt.n_lt = 0; } cout << "sweeping:" << endl; for(int i = 0; i < 4; ++ i) ll[i].s_print(); if(sweeping(ll, 4)) cout << "yes" << endl; else cout << "no" << endl; return(0); }
void pop_front() { retry: unique_lock l(head_->mutex_); node_ptr first = head_->next_; assert(first); unique_lock l0(first->mutex_); bool is_tail = !first->next_; if (is_tail) { l0.unlock(); tail_ptr_mutex_.lock(); l0.lock(); assert(head_->next_ == first); if (first->next_) { // no longer tail, retry tail_ptr_mutex_.unlock(); goto retry; } assert(tail_ == first); } head_->next_ = first->next_; if (is_tail) { tail_ = head_; tail_ptr_mutex_.unlock(); } }
std::pair<bool, T> try_pop_front() { retry: unique_lock l(head_->mutex_); node_ptr first = head_->next_; if (unlikely(!first)) return std::make_pair(false, T()); unique_lock l0(first->mutex_); T t = first->value_; bool is_tail = !first->next_; if (is_tail) { l0.unlock(); tail_ptr_mutex_.lock(); l0.lock(); assert(head_->next_ == first); if (first->next_) { // no longer tail, retry tail_ptr_mutex_.unlock(); goto retry; } assert(tail_ == first); } head_->next_ = first->next_; if (is_tail) { tail_ = head_; tail_ptr_mutex_.unlock(); } return std::make_pair(true, t); }
dgFloat32 dgCollisionScene::RayCast(const dgVector& localP0, const dgVector& localP1, dgContactPoint& contactOut, OnRayPrecastAction preFilter, const dgBody* const body, void* const userData) const { const dgNode *stackPool[DG_SCENE_MAX_STACK_DEPTH]; if (!m_rootNode) { return dgFloat32(1.2f); } dgInt32 stack = 1; stackPool[0] = m_rootNode; dgFloat32 maxParam = dgFloat32(1.2f); //int xxx = 0; dgFastRayTest ray(localP0, localP1); while (stack) { stack--; const dgNode* const me = stackPool[stack]; //xxx ++; if (ray.BoxTest(me->m_minBox, me->m_maxBox)) { if (!me->m_left) { _ASSERTE(!me->m_right); dgContactPoint tmpContactOut; const dgProxy* const proxy = (dgProxy*) me; dgVector l0(proxy->m_matrix.UntransformVector(localP0)); dgVector l1(proxy->m_matrix.UntransformVector(localP1)); dgFloat32 param = proxy->m_shape->RayCast(l0, l1, tmpContactOut, preFilter, body, userData); _ASSERTE(param >= dgFloat32 (0.0f)); if (param < maxParam) { contactOut.m_normal = proxy->m_matrix.RotateVector( tmpContactOut.m_normal); maxParam = param; ray.Reset(maxParam); } } else { _ASSERTE(me->m_left); _ASSERTE(stack < dgInt32 (sizeof (stackPool) / sizeof (dgNode*))); stackPool[stack] = me->m_left; stack++; _ASSERTE(me->m_right); _ASSERTE(stack < dgInt32 (sizeof (stackPool) / sizeof (dgNode*))); stackPool[stack] = me->m_right; stack++; } } } return maxParam; }
int main () { std::vector<int>v0(10); for (std::vector<int>::iterator it = v0.begin(); it != v0.end(); ++ it ) { * it = std::rand(); } // oder // for ( auto & v : v0 ) { // v = std :: rand (); // } std::copy(std::begin(v0), std::end(v0), std::ostream_iterator<int>(std::cout, " einfach \n" )); //kopiert und gibt alle 10 Arrays von int Werten aus std::list<int> l0(v0.size()); //erstellt eine doppelt verkettete Liste der Größe von v0 std::copy(std::begin(v0), std::end(v0), std::begin(l0)); //kopiert die Elemente der Arrays in die Liste std::list<int> l1 (std::begin(l0), std::end(l0)); //erstellt eine zweite doppelt verkettete Liste von der Liste l1 std::reverse(std::begin(l1), std::end(l1)); //vertauscht die Reihenfolge der Arrays std::copy(std::begin(l1), std::end(l1), std::ostream_iterator<int>(std::cout, " umgekehrt \n")); //kopiert und gibt alle Elemente der Liste l1 aus l1.sort(); //sortiert die Array Listen l1 aufsteigend ( < ) std::copy(l1.begin() ,l1.end(), std::ostream_iterator<int>(std::cout, " soriert \n")); //kopiert und gibt alle sortierten Elemente der Liste l1 aus std::generate(std::begin(v0), std::end(v0), std::rand); //gibt jedem Element von v0 einen Zufallswert std::copy(v0.rbegin(), v0.rend(), std::ostream_iterator<int>(std::cout, " reversed random \n")); //kopiert und gibt alle Elemente von v0 reversed aus (rbeginn) return 0; }
Foam::graph Foam::kShellIntegration ( const complexVectorField& Ek, const Kmesh& K ) { // evaluate the radial component of the spectra as an average // over the shells of thickness dk graph kShellMeanEk = kShellMean(Ek, K); const scalarField& x = kShellMeanEk.x(); scalarField& y = *kShellMeanEk.begin()(); // now multiply by 4pi k^2 (the volume of each shell) to get the // spectra E(k). int E(k) dk is now the total energy in a box // of side 2pi y *= sqr(x)*4.0*constant::mathematical::pi; // now scale this to get the energy in a box of side l0 scalar l0(K.sizeOfBox()[0]*(scalar(K.nn()[0])/(scalar(K.nn()[0])-1.0))); scalar factor = pow((l0/(2.0*constant::mathematical::pi)),3.0); y *= factor; // and divide by the number of points in the box, to give the // energy density. y /= scalar(K.size()); return kShellMeanEk; }
void test_restart() { ngac ac("ac1", 0, 5, 1); ngresistor r("r1", 370); ngled led("led1", 5e-3); ngground gnd; ngline l0(ac.p1, gnd.p1); ngline l1(ac.p2, r.p1); ngline l2(r.p2, led.p1); ngline l3(led.p2, ac.p1); schema sch; sch.AddDevices(&ac, &r, &led, &gnd, 0); sch.AddLines(&l0, &l1, &l2, &l3, 0); circuit cir(&sch); cir.Tran("1000"); do { Sleep(200); char ch = getchar(); switch (ch) { case 'r': cir.Restart(); Sleep(200); break; default: break; } } while (cir.IsRunning()); }
/** * window2world * * A very simple function which takes the window parameters from * glut and returns the world coordinate positions on the y=0 * plane * * @param[in] x Glut x coordinate * @param[in] y Glut y coordinate * @return world coordinates */ static vec3 window2world( const int x, const int y ){ /************************************************************/ /* Convert the mouse coordinates into World Coordinates */ /************************************************************/ //retrieve the viewport data GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport ); const mat4 cam = options.camera.getTransform(); //retrieve the modelview (and put it in column major) GLdouble modelview[16]; for ( int i = 0; i < 4; ++i ) for ( int j = 0; j < 4; ++j ) modelview[i*4+j] = cam[j][i]; //retieve the projection matrix (column major too) GLdouble projection[16]; for ( int i = 0; i < 4; ++i ) for ( int j = 0; j < 4; ++j ) projection[i*4+j] = options.projectionMatrix[j][i]; // invert y for better accuracy GLdouble wx = x; GLdouble wy = viewport[3] - y; // to get intersection with near zNear plane setting wz=0 GLdouble wz = 0; //compute the world coordinates first point GLdouble nearX, nearY, nearZ; gluUnProject( wx, wy, wz, modelview, projection, viewport, &nearX, &nearY, &nearZ); // to get intersection with zFar plane setting wz=1 wz = 1; //compute the world coordinates second point GLdouble farX, farY, farZ; gluUnProject( wx, wy, wz, modelview, projection, viewport, &farX, &farY, &farZ); // using line-plane intersection formula find intersection with y=0 (x-z plane) // d is the distance of the intersecting point from l0 in the direction l // I simplified it specifically for the y=0 plane // for general form uncomment the 3 lines below // - Josh vec3 l0(nearX,nearY,nearZ); // a point on the line vec3 l = vec3(farX,farY,farZ) - l0; // vector in dir of line vec3 n(0.0,0.0,1.0); // the norm of the plane vec3 p0(0.0,0.0,0.0); // a point on the plane y=0 GLfloat d = dot(p0-l0,n)/dot(l,n); // GLfloat d = -nearY/(farY-nearY); return l0+l*d; }
void test_switch_by_csw() { ngdc dc("dc1", 5); ngspst spst("spst", ngspst::on); ngresistor r("1", 5); ngled led("led"); ngground gnd; ngline l1(dc.pos, spst.p1); ngline l2(spst.p2, r.p1); ngline l3(r.p2, led.pos); ngline l4(led.neg, dc.neg); ngline l0(dc.neg, gnd.ground); schema sch; sch.AddDevices(&dc, &spst, &r, &gnd, &led, 0); sch.AddLines(&l1, &l2, &l3, &l0, &l4, 0); circuit cir(&sch); #if 0//not work // tran with spst disconnected cir.Tran("10", "1m"); do { Sleep(100); } while (cir.IsRunning()); //cir.Stop(); // tran with spst connected, however it's still disconnected string sw = spst.switchover(); cir.Do(sw); cir.Tran("10", "1m"); do { Sleep(100); } while (cir.IsRunning()); #endif // run with event input to switch spst cir.Tran("1t", "1m", 0); do { Sleep(200); char ch = getchar(); switch (ch) { case 'a': cir.SwitchOver(&spst); Sleep(200); break; case 'q': cir.Halt(); default: break; }; } while (cir.IsRunning()); }
float Printer::bendingCorrectionAt(float x, float y) { RVector3 p0(EEPROM::zProbeX1(),EEPROM::zProbeY1(),EEPROM::bendingCorrectionA()); RVector3 p1(EEPROM::zProbeX2(),EEPROM::zProbeY2(),EEPROM::bendingCorrectionB()); RVector3 p2(EEPROM::zProbeX3(),EEPROM::zProbeY3(),EEPROM::bendingCorrectionC()); RVector3 a = p1-p0,b = p2 - p0; RVector3 n = a.cross(b); RVector3 l0(x,y,0); return ((p0 - l0).scalar(n)) / n.z; }
int find_player_number(struct game *g, int fd) { int i; for (i = 0; i < g->players_number; i++) if (g->players_conn[i] == fd) return i; l0(OUTPUT_TYPE_ERROR, "Internal error"); exit(EXIT_FAILURE); }
TEST(PlayerTest, setAndGetLocationTests) { Player p; Location l0("loc0ID", "l0 is beautiful"); Location l1("loc1ID", "l1 is beautiful"); p.setLocation(&l0); EXPECT_EQ(p.getLocation()->getLocID(), "loc0ID"); p.setLocation(&l1); EXPECT_EQ(p.getLocation()->getLocID(), "loc1ID"); }
int main() { // all possible lock orderings: // 012, 021, 102, 120, 201, 210 auto a = []{ i++; while (i < 6); // wait until all threads have started Lock l0(m[0]), l1(m[1]), l2(m[2]); // is a defer lock std::lock(l0, l1, l2); // 012 std::cout << __LINE__ << std::endl; // all locked -> safe to print }; auto b = []{ i++; while (i < 6); Lock l0(m[0]), l1(m[1]), l2(m[2]); std::lock(l0, l2, l1); // 021 std::cout << __LINE__ << std::endl; }; auto c = []{ i++; while (i < 6); Lock l0(m[0]), l1(m[1]), l2(m[2]); std::lock(l1, l0, l2); // 102 std::cout << __LINE__ << std::endl; }; auto d = []{ i++; while (i < 6); Lock l0(m[0]), l1(m[1]), l2(m[2]); std::lock(l1, l2, l0); // 120 std::cout << __LINE__ << std::endl; }; auto e = []{ i++; while (i < 6); Lock l0(m[0]), l1(m[1]), l2(m[2]); std::lock(l2, l0, l1); // 201 std::cout << __LINE__ << std::endl; }; auto f = []{ i++; while (i < 6); Lock l0(m[0]), l1(m[1]), l2(m[2]); std::lock(l2, l1, l0); // 210 std::cout << __LINE__ << std::endl; }; std::vector<std::thread> threads; threads.reserve(6); threads.emplace_back(a); threads.emplace_back(b); threads.emplace_back(c); threads.emplace_back(d); threads.emplace_back(e); threads.emplace_back(f); for (auto&& t : threads) t.join(); std::cout << "Done" << std::endl; }
TEST(PlayerTest, movePlayerTest) { Player p; Location l0("loc0ID", "l0 is beautiful"); Location l1("loc1ID", "l1 is beautiful"); l0.setPath(Direction::F, &l1, "l1"); p.setLocation(&l0); EXPECT_FALSE(p.movePlayer(Direction::B)); EXPECT_EQ(&l0, p.getLocation()); EXPECT_TRUE(p.movePlayer(Direction::F)); EXPECT_EQ(&l1, p.getLocation()); }
int main () { // Erstellt Vektor v0 mit 10 Plätzen für int-Werte. std::vector<int> v0(10); // Belegt jeden der 10 Plätze mit einer Zufallszahl. for (std::vector<int>::iterator it = v0.begin(); it != v0.end(); ++it) { *it = std::rand(); } // oder //for (auto& v : v0) { // v = std::rand(); //} // Übergibt alle Werte von v0 an einen Iterator, // der diese in der Konsole ausgibt. std::copy( std::begin(v0), std::end(v0), std::ostream_iterator<int>(std::cout, " (von v0)\n")); // Legt neue Liste l0 mit der Größe des Vektors v0 an. std::list<int> l0(v0.size()); // Übergibt alle Werte von v0 an l0 beginnend beim jeweils ersten Platz. std::copy(std::begin(v0), std::end(v0), std::begin(l0)); // Legt neue Liste l1 mit den Werten aus l0 an. std::list<int> l1(std::begin(l0), std::end(l0)); // Dreht die gesamte Liste l1 um. std::reverse(std::begin(l1), std::end(l1)); // Übergibt alle Werte von l1 an einen Iterator, // der diese in der Konsole ausgibt. std::copy( std::begin(l1), std::end(l1), std::ostream_iterator<int>(std::cout, " (von l1, reverse)\n")); // Sortiert die Liste l1 aufsteigend. l1.sort(); // Übergibt alle Werte von l1 an einen Iterator, // der diese in der Konsole ausgibt. std::copy( l1.begin(), l1.end(), std::ostream_iterator<int>(std::cout, " (von l1, sort)\n")); // Belegt den Vektor v0 mit Zufallszahlen über die Methode an dritter Stelle. std::generate(std::begin(v0), std::end(v0), std::rand); // Übergibt alle Werte von v0 in umgekehrter Reihenfolge an einen Iterator, // der diese in der Konsole ausgibt. std::copy( v0.rbegin(), v0.rend(), std::ostream_iterator<int>(std::cout, " (von v0, reverse)\n")); return 0; }
void test_spdt() { //创建所需元器件 ngdc dc("dc1", 5); ngspdt spdt("spdt", ngspdt::status_throw1); ngresistor r1("1", 5); ngresistor r2("2", 5); ngled led1("led1"); ngled led2("led2"); ngground gnd; //创建接线,连接各元器件 ngline l1(dc.pos, spdt.pole); ngline l2(spdt.throw1, r1.p1); ngline l3(spdt.throw2, r2.p1); ngline l4(r1.p2, led1.pos); ngline l5(r2.p2, led2.pos); ngline l6(led1.neg, dc.neg); ngline l7(led2.neg, dc.neg); ngline l0(dc.neg, gnd.ground); //创建电路图,添加元器件、接线到电路图 schema sch; sch.AddDevices(&dc, &spdt, &r1, &r2, &led1, &led2, &gnd, 0); sch.AddLines(&l1, &l2, &l3, &l4, &l5, &l6, &l7, &l0, 0); //创建仿真对象,添加电路图,并开始暂态仿真 circuit cir(&sch); cir.Tran("1t", "1m", 0); do { Sleep(200); char ch = getchar(); switch (ch) { case 'a': cir.SwitchOver(&spdt); Sleep(200); break; case 'q': cir.Halt(); default: break; }; } while (cir.IsRunning()); //主程序线程,类似windows UI消息循环 }
int main () { std::vector<int> v0(10); for (std::vector<int>::iterator it = v0.begin(); it != v0.end(); ++it){ *it =std::rand(); } std::copy (std::begin(v0), std::end(v0),std::ostream_iterator<int>(std::cout, "\n")); std::list<int> l0 (v0.size()); std::copy(std::begin(v0),std::end(v0),std::begin(l0)); std::list<int> l1(std::begin(l0), std::end(l0)); std::reverse(std::begin(l1),std::end(l1)); std::copy(std::begin(l1), std::end(l1), std::ostream_iterator<int>(std::cout,"\n")); l1.sort(); std::copy(l1.begin(),l1.end(),std::ostream_iterator<int>(std::cout, "\n")); std::generate(std::begin(v0), std::end(v0), std::rand); std::copy(v0.rbegin(),v0.rend(),std::ostream_iterator<int>(std::cout,"\n")); return 0; }
void test_circuit_parallel() { //circuit 1 ngac AC("ac1", 0, 5, 1); ngresistor R("r1", 370); ngled LED("LED1", 7e-3); ngground GND; ngline L0(AC.p1, GND.p1); ngline L1(AC.p2, R.p1); ngline L2(R.p2, LED.p1); ngline L3(LED.p2, AC.p1); schema SCH; SCH.AddDevices(&AC, &R, &LED, &GND, 0); SCH.AddLines(&L0, &L1, &L2, &L3, 0); circuit CIR(&SCH); CIR.Tran("20", "1m"); //circuit 2 ngac ac("ac1", 0, 5, 1); ngresistor r("r1", 370); ngled led("led1", 5e-3); ngground gnd; ngline l0(ac.p1, gnd.p1); ngline l1(ac.p2, r.p1); ngline l2(r.p2, led.p1); ngline l3(led.p2, ac.p1); schema sch; sch.AddDevices(&ac, &r, &led, &gnd, 0); sch.AddLines(&l0, &l1, &l2, &l3, 0); circuit cir(&sch); cir.Tran("20", "1m"); do { Sleep(200); } while (CIR.IsRunning() || cir.IsRunning()); }
static void close_game(int fd) { struct game * g = find_game_by_fd(fd); if (g) { if (g->players_conn[0] == fd) { if (g->players_number == 1) { send_line_log(fd, wn_alone_in_the_dark, "CLOSE"); return; } send_ok(fd, "CLOSE"); g->status = GAME_STATUS_CLOSED; calculate_list_games(); } else { send_line_log(fd, wn_not_creator, "CLOSE"); } } else { l0(OUTPUT_TYPE_ERROR, "Internal error"); exit(EXIT_FAILURE); } }
static void setoptions(int fd, char* options) { struct game * g = find_game_by_fd(fd); if (g) { if (g->players_conn[0] == fd) { int i; char* msg; send_ok(fd, "SETOPTIONS"); msg = asprintf_("OPTIONS: %s,PROTOCOLLEVEL:%d", options, min_protocol_level(g)); for (i = 0; i < g->players_number; i++) if (remote_proto_minor[g->players_conn[i]] >= 1) send_line_log_push(g->players_conn[i], msg); free(msg); } else { send_line_log(fd, wn_not_creator, "SETOPTIONS"); } } else { l0(OUTPUT_TYPE_ERROR, "Internal error"); exit(EXIT_FAILURE); } }
boolean BoxObj::Intersects (LineObj& l) { Coord x1 = min(l._p1._x, l._p2._x); Coord x2 = max(l._p1._x, l._p2._x); Coord y1 = min(l._p1._y, l._p2._y); Coord y2 = max(l._p1._y, l._p2._y); BoxObj lbox(x1, y1, x2, y2); boolean intersects = false; if (Intersects(lbox)) { intersects = Contains(l._p1) || Contains(l._p2); if (!intersects) { LineObj l0 (_left, _bottom, _right, _bottom); LineObj l1 (_right, _bottom, _right, _top); LineObj l2 (_right, _top, _left, _top); LineObj l3 (_left, _top, _left, _bottom); intersects = l.Intersects(l0) || l.Intersects(l1) || l.Intersects(l2) || l.Intersects(l3); } } return intersects; }