void test_try_lock_two_second_locked() { dummy_mutex m1,m2; m2.lock(); boost::unique_lock<dummy_mutex> l1(m1,boost::defer_lock), l2(m2,boost::defer_lock); int const res=boost::try_lock(l1,l2); BOOST_CHECK(res==1); BOOST_CHECK(!m1.is_locked); BOOST_CHECK(m2.is_locked); BOOST_CHECK(!l1.owns_lock()); BOOST_CHECK(!l2.owns_lock()); }

bool test_host_resolver::TestCopyCtor::operator()() { host_resolver local("127.0.0.1"); host_resolver l2(local); if (l2.get_official_name() != local.get_official_name()) return false; if (l2.count_hosts() != local.count_hosts()) return false; for(int i = 0;i < l2.count_hosts();i++) if (l2.get_host(i) != local.get_host(i)) return false; return true; }

FloatType Route::EstAddNode(size_t pos, GiftID gift_id) const{ if(pos>= this->gift_ids.size()) throw RouteAccessException(*this, pos); //assert(pos < this->gift_ids.size()); auto prev_loc = PrevLoc(pos); auto next_loc = gift_data[gift_ids[pos]].Loc(); auto loc = this->gift_data[gift_id].Loc(); auto node_w = gift_data[gift_id].Weight(); auto total_weight = this->Weight()+sleigh_base_weight; FloatType w0 = total_weight; for (int i = 0; i < pos; ++i) { w0 -= gift_data[gift_ids[i]].Weight(); } Location l1(0,0,0); Location l2(0,0,0); FloatType dist = 0.0; if(pos > 0){ gift_id = gift_ids[0]; l1 = north_pole; l2 = gift_data[gift_id].Loc(); dist += Dist(l1,l2); } for (int i = 1; i < pos; ++i) { gift_id = gift_ids[i-1]; l1 = gift_data[gift_id].Loc(); gift_id = gift_ids[i]; l2 = gift_data[gift_id].Loc(); dist += Dist(l1,l2); } dist += Dist(prev_loc, loc); auto minus_dist = Dist(prev_loc, loc) + Dist(next_loc, loc); auto add_dist = Dist(prev_loc, next_loc); auto dist_diff = abs(minus_dist - add_dist); return dist*node_w + (w0)*dist_diff; }

void test_try_lock_four() { int const num_mutexes=4; for(int i=-1;i<num_mutexes;++i) { dummy_mutex mutexes[num_mutexes]; if(i>=0) { mutexes[i].lock(); } boost::unique_lock<dummy_mutex> l1(mutexes[0],boost::defer_lock), l2(mutexes[1],boost::defer_lock), l3(mutexes[2],boost::defer_lock), l4(mutexes[3],boost::defer_lock); int const res=boost::try_lock(l1,l2,l3,l4); BOOST_CHECK(res==i); for(int j=0;j<num_mutexes;++j) { if((i==j) || (i==-1)) { BOOST_CHECK(mutexes[j].is_locked); } else { BOOST_CHECK(!mutexes[j].is_locked); } } if(i==-1) { BOOST_CHECK(l1.owns_lock()); BOOST_CHECK(l2.owns_lock()); BOOST_CHECK(l3.owns_lock()); BOOST_CHECK(l4.owns_lock()); } else { BOOST_CHECK(!l1.owns_lock()); BOOST_CHECK(!l2.owns_lock()); BOOST_CHECK(!l3.owns_lock()); BOOST_CHECK(!l4.owns_lock()); } } }

void Chapter2Test::Test2_5() { ofstream fout; OpenLogFile(fout,"test2_5.html","Problem 2.5: add two lists with digits and return a new list."); ListNode *l1(nullptr),*l2(nullptr); ListNode *output(nullptr), *expected_1(nullptr), *expected_2(nullptr); stringstream ss; ListNode::GenerateListNode({}, 0, l1); ListNode::GenerateListNode({}, 0, l2); ListNode::GenerateListNode({}, 0, expected_1); ListNode::GenerateListNode({}, 0, expected_2); ListNode::PrintListNode(l1, ss); ss<<" + "; ListNode::PrintListNode(l2, ss); output = sol.prob2_5_1(l1,l2); TestLinkedList(fout, ss.str(), output, expected_1); output = sol.prob2_5_2(l1, l2); TestLinkedList(fout, ss.str(), output, expected_2); ss.str(""); int A0[] = {1,2,3}, B0[] = {1,2,3}, C0[] = {2,4,6}, D0[] = {2,4,6}; ListNode::GenerateListNode(A0, sizeof(A0)/sizeof(A0[0]), l1); ListNode::GenerateListNode(B0, sizeof(B0)/sizeof(B0[0]), l2); ListNode::GenerateListNode(C0, sizeof(C0)/sizeof(C0[0]), expected_1); ListNode::GenerateListNode(D0, sizeof(D0)/sizeof(D0[0]), expected_2); ListNode::PrintListNode(l1, ss); ss<<" + "; ListNode::PrintListNode(l2, ss); output = sol.prob2_5_1(l1,l2); TestLinkedList(fout, ss.str(), output, expected_1); output = sol.prob2_5_2(l1, l2); TestLinkedList(fout, ss.str(), output, expected_2); ss.str(""); int A1[] = {9,9,9}, B1[] = {9,8}, C1[] = {8,8,0,1}, D1[] = {1,0,9,7}; ListNode::GenerateListNode(A1, sizeof(A1)/sizeof(A1[0]), l1); ListNode::GenerateListNode(B1, sizeof(B1)/sizeof(B1[0]), l2); ListNode::GenerateListNode(C1, sizeof(C1)/sizeof(C1[0]), expected_1); ListNode::GenerateListNode(D1, sizeof(D1)/sizeof(D1[0]), expected_2); ListNode::PrintListNode(l1, ss); ss<<" + "; ListNode::PrintListNode(l2, ss); output = sol.prob2_5_1(l1,l2); TestLinkedList(fout, ss.str(), output, expected_1); output = sol.prob2_5_2(l1, l2); TestLinkedList(fout, ss.str(), output, expected_2); CloseLogFile(fout); }

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消息循环 }

void MSDKVpp::SetVPPCompRect(int streamIndex, const VppRect* rect) { if (streamIndex >= MAX_OUTPUT_NUM || !rect || !rect->w || !rect->h) { VPP_TRACE_ERROR("[MSDKVpp]-----invalid dst rect\n"); } Locker<Mutex> l1(m_xMsdkInit); m_vRect[streamIndex] = *rect; if (m_bInit) { Locker<Mutex> l2(m_xMsdkReinit); if (!m_bReinit) m_bReinit = true; } VPP_TRACE_INFO("[MSDKVpp]Attach stream %d vpp rect, %d/%d/%d/%d\n", streamIndex, rect->x, rect->y, rect->w, rect->h); }

// Searchs and activates a window given its title or class name //##ModelId=474D3026011A bool CSendKeys::AppActivate(LPCTSTR WindowTitle, LPCTSTR WindowClass) { HWND w; w = ::FindWindow(WindowClass, WindowTitle); if (w == NULL) { // Must specify at least a criteria if (WindowTitle == NULL && WindowClass == NULL) return false; // << Code to serialize the windowtitle/windowclass in order to send to EnumWindowProc() size_t l1(0), l2(0); if (WindowTitle) l1 = _tcslen(WindowTitle); if (WindowClass) l2 = _tcslen(WindowClass); LPTSTR titleclass = new TCHAR [l1 + l2 + 5]; memset(titleclass, '\0', l1+l2+5); if (WindowTitle) _tcscpy(titleclass, WindowTitle); titleclass[l1] = 0; if (WindowClass) _tcscpy(titleclass+l1+1, WindowClass); // >> enumwindow_t t; t.hwnd = NULL; t.str = titleclass; ::EnumWindows(enumwindowsProc, (LPARAM) & t); w = t.hwnd; delete [] titleclass; } if (w == NULL) return false; return AppActivate(w); }

void player_part_game_(int fd, char* reason) { struct game * g = find_game_by_fd(fd); if (g) { char * save_nick; int j; int i = find_player_number(g, fd); // remove parting player from game save_nick = g->players_nick[i]; for (j = i; j < g->players_number - 1; j++) { g->players_conn[j] = g->players_conn[j + 1]; g->players_nick[j] = g->players_nick[j + 1]; g->players_started[j] = g->players_started[j + 1]; } g->players_number--; // completely remove game if empty if (g->players_number == 0) { int was_running = g->status == GAME_STATUS_PLAYING; games = g_list_remove(games, g); free(g); calculate_list_games(); if (was_running) l2(OUTPUT_TYPE_INFO, "running games decrements to: %d (%d players)", games_running, players_in_game); } else { if (g->status == GAME_STATUS_PLAYING) { // inform other players, playing state char leave_player_prio_msg[] = "?l\n"; leave_player_prio_msg[0] = fd; process_msg_prio_(fd, leave_player_prio_msg, strlen(leave_player_prio_msg), g); } else { char parted_msg[1000]; // inform other players, non-playing state snprintf(parted_msg, sizeof(parted_msg), reason ? reason : ok_player_parted, save_nick); for (j = 0; j < g->players_number; j++) send_line_log_push(g->players_conn[j], parted_msg); } calculate_list_games(); } free(save_nick); open_players = g_list_append(open_players, GINT_TO_POINTER(fd)); } }

int main() { typedef fusion::vector<> vector0; typedef fusion::vector<element1_type &> vector1; typedef fusion::vector<element1_type &, element2_type> vector2; typedef fusion::vector<element1_type &, element2_type, element3_type> vector3; vector0 v0; vector1 v1(element1); #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) // Note: C++11 will pickup the rvalue overload for the d argument // since we do not have all permutations (expensive!) for all const& // and && arguments. We either have all && or all const& arguments only. // For that matter, use std::ref to disambiguate the call. vector2 v2(std::ref(element1), element2); vector3 v3(std::ref(element1), element2, std::ref(element3)); #else vector2 v2(element1, element2); vector3 v3(element1, element2, element3); #endif test_sequence(v0); test_sequence(v1); test_sequence(v2); test_sequence(v3); typedef fusion::list<> list0; typedef fusion::list<element1_type &> list1; typedef fusion::list<element1_type &, element2_type> list2; typedef fusion::list<element1_type &, element2_type, element3_type> list3; list0 l0; list1 l1(element1); list2 l2(element1, element2); list3 l3(element1, element2, element3); test_sequence(l0); test_sequence(l1); test_sequence(l2); test_sequence(l3); return boost::report_errors(); }

void testCase1(){ stdL<int> l1(10, 0); tsL<int> l2(10, 0); assert(TinySTL::Test::container_equal(l1, l2)); int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; stdL<int> l3(std::begin(arr), std::end(arr)); tsL<int> l4(std::begin(arr), std::end(arr)); assert(TinySTL::Test::container_equal(l3, l4)); auto l5(l1); auto l6(l2); assert(TinySTL::Test::container_equal(l5, l6)); auto l7 = l1; auto l8 = l2; assert(TinySTL::Test::container_equal(l7, l8)); }

TEST(RegionDescriptor, Boxfilter) { cv::Mat_<int> input(3,7); std::iota(input.begin(), input.end(), 1); region_interval l1(0, 0,3); region_interval l2(1, 0,2); region_interval l3(2, 1,2); std::vector<region_interval> reg {l1,l2,l3}; std::vector<std::pair<int, int>> result; std::vector<std::pair<int, int>> expected {{0,0}, {1,1}, {4,26}, {6,39}, {6,45}, {6,51}, {6,57}, {6,63}, {5,61}, {2,21}, {0,0}}; result.resize(expected.size()); region_descriptors::segment_boxfilter(result, input, reg, -3, 7); ASSERT_TRUE(std::equal(result.begin(), result.end(), expected.begin())); }

void StringAnimationManager::clone(const StringAnimationManager& other,SequenceTime offset, const RangeD* range) { // The range=[0,0] case is obviously a bug in the spec of paramCopy() from the parameter suite: // it prevents copying the value of frame 0. bool copyRange = range != NULL /*&& (range->min != 0 || range->max != 0)*/; QMutexLocker l(&_imp->keyframesMutex); _imp->keyframes.clear(); QMutexLocker l2(&other._imp->keyframesMutex); for (Keyframes::const_iterator it = other._imp->keyframes.begin(); it!=other._imp->keyframes.end(); ++it) { if (copyRange && (it->time < range->min || it->time > range->max)) { continue; } StringKeyFrame k; k.time = it->time + offset; k.value = it->value; _imp->keyframes.insert(k); } }

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()); }

TEST(TestSharedSection, GetSharedLockWhileTryingExclusiveLock) { std::atomic<long> mutex(0L); CEvent event; CSharedSection sec; CSharedLock l1(sec); // get a shared lock locker<CExclusiveLock> l2(sec,&mutex); thread waitThread1(l2); // try to get an exclusive lock EXPECT_TRUE(waitForThread(mutex,1,10000)); SleepMillis(10); // still need to give it a chance to move ahead EXPECT_TRUE(!l2.haslock); // this thread is waiting ... EXPECT_TRUE(!l2.obtainedlock); // this thread is waiting ... // now try and get a SharedLock locker<CSharedLock> l3(sec,&mutex,&event); thread waitThread3(l3); // try to get a shared lock EXPECT_TRUE(waitForThread(mutex,2,10000)); SleepMillis(10); EXPECT_TRUE(l3.haslock); event.Set(); EXPECT_TRUE(waitThread3.timed_join(MILLIS(10000))); // l3 should have released. EXPECT_TRUE(!l3.haslock); // but the exclusive lock should still not have happened EXPECT_TRUE(!l2.haslock); // this thread is waiting ... EXPECT_TRUE(!l2.obtainedlock); // this thread is waiting ... // let it go l1.Leave(); // the last shared lock leaves. EXPECT_TRUE(waitThread1.timed_join(MILLIS(10000))); EXPECT_TRUE(l2.obtainedlock); // the exclusive lock was captured EXPECT_TRUE(!l2.haslock); // ... but it doesn't have it anymore }

// Copy data in global variables // Input: // MU - PxM two-dimensional array of Gaussians means // PS - PxM two-dimensional array of Gaussian probabilities // SI - PxM two-dimensional array of Gaussian standard deviations // ES - PxPxM three-dimensional array of Markov transition probabilities // P - number of variables // num_states - number of states in WHMT model // // Output: // MUO - PxM two-dimensional array of Gaussians means // PSO - PxM two-dimensional array of Gaussian probabilities // SIO - PxM two-dimensional array of Gaussian standard deviations // ESO - PxPxM three-dimensional array of Markov transition probabilities // void copy_para_1D(double **MU, double **MUO, double **SI, double **SIO, double **PS, double **PSO, double ***ES, double ***ESO, int P, long num_states) { int i,j,jj,level; level = l2(P); for(i=0; i<level; i++) // index starts from zero for(j=0; j<num_states; j++) { MUO[i][j] = MU[i][j]; SIO[i][j] = SI[i][j]; PSO[i][j] = PS[i][j]; for(jj=0; jj<num_states; jj++) ESO[i][j][jj] = ES[i][j][jj]; } }

// Initilize parameters for 1D WHMT model // Input: // w1 - 1-dimensional vector with data // P - number of elements // num_states - number of HMT states // // Output: // MU - PxM two-dimensional array of Gaussians means // PS - PxM two-dimensional array of Gaussian probabilities // SI - PxM two-dimensional array of Gaussian standard deviations // ES - PxPxM three-dimensional array of Markov transition probabilities // void initialize_1D(double *w1, double **MU, double **PS, double **SI, double ***ES, int P, long num_states) // NEW! let data w be internal (not external) variable for 1D { int i,j,k,level; int J,si,ei; double tsis, temp; level = l2(P); for(k=0; k<level; k++) // loop on levels. Start index at zero { J=power2(k); // don't remove 1 !!! /* HH subband */ si=J+1; // Set start and end indices ei=2*J; tsis = 0.0; LOOPsi // start index at zero { temp=w1[i]; tsis+=temp*temp; // compute E[X^2] } #ifdef DEBUG_PRINTS printf("USED x[%ld:%ld] ; Sum of squares: tsis=%lf, ", si - 1, ei - 1, tsis); fflush(stdout); printf("J=%ld, num - elements = %ld, Normalized Sum of squares = %lf\n", J, ei - si + 1, tsis / double(J)); fflush(stdout); #endif tsis/=J; // Normalize for(i=0; i<num_states; i++) // loop on Gaussians. 2nd Gaussian is good. What about first?? { MU[k][i] = 0.0; // set all means at zero PS[k][i] = 1.0 / double(num_states); // 0.5; // uniform set probabilities SI[k][i] = tsis*(1+i*3) /* 2*(i+1)*/ / double(num_states); // // (1/2) \sum_i x_i^2 (mean is zero) . Why not sqrt? why divide by two??? why i*3? for(j=0; j<num_states; j++) // loop on Gaussians for transition matrix ES[k][i][j] = 1.0/double(num_states); // set uniform transition matrix } } // loop on levels }

TEST(TestSharedSection, TwoCase) { CSharedSection sec; CEvent event; std::atomic<long> mutex(0L); locker<CSharedLock> l1(sec,&mutex,&event); { CSharedLock lock(sec); thread waitThread1(l1); EXPECT_TRUE(waitForWaiters(event,1,10000)); EXPECT_TRUE(l1.haslock); event.Set(); EXPECT_TRUE(waitThread1.timed_join(MILLIS(10000))); } locker<CSharedLock> l2(sec,&mutex,&event); { CExclusiveLock lock(sec); // get exclusive lock thread waitThread2(l2); // thread should block EXPECT_TRUE(waitForThread(mutex,1,10000)); SleepMillis(10); EXPECT_TRUE(!l2.haslock); lock.Leave(); EXPECT_TRUE(waitForWaiters(event,1,10000)); SleepMillis(10); EXPECT_TRUE(l2.haslock); event.Set(); EXPECT_TRUE(waitThread2.timed_join(MILLIS(10000))); } }

// EM function with Wiener transform ? // Input: // NOT USED: whmt - WHMT_struct with all parameters // w1 - 1-dimensional vector with data // NOT USED: ws1 - 1-dimensional vector with st.d. data (for Poisson model. This is ignored for the Gaussian case) // PP - PxM two-dimensional array of Gaussians probabilities // nv - estimated noise variance (??) // P - number of variables // slev - number of levels for denoising (for 1024 a good value is 4 or 5). Denoise only slev coarse levels (?) ( maximal level? why the hell is this 5? ) // // Output: // w1 - we change the values // void emwiener_1D(double *w1, double **PP, double **SI, double nv, int P, int slev, long num_states) { //printf("inside emw something special\n"); int i,j,k,J,si,ei,level; // ,slev; double y,sps; // slev = 5; // maximal level? why the hell is this 5? level = l2(P); // number of levels for(k=slev-1; k<level; k++) // modified: -1 index { J=power2(k); // don't remove one!!! si=J+1; ei=2*J; //printf("emwiener Level=%ld, run i from %ld to %ld\n", k, si, ei); for(i=si-1; i<ei; i++) // modify: -1 index { y=0; for(j=0; j<num_states; j++) { sps = MAX(SI[k][j]-nv, 0.0); #ifdef DEBUG_PRINTS printf("emwiener Set: SI[%ld][%ld]=%lf, nv=%lf, sps=%lf\n", k, j, SI[k][j], nv, sps); fflush(stdout); #endif y += PP[i][j]*sps/(sps+nv); #ifdef DEBUG_PRINTS printf("emwiener Set2: PP[%ld][%ld]=%lf, nv=%lf, sps=%lf\n", i, j, PP[i][j], nv, sps); fflush(stdout); printf("emwiener PRODUCT: PP[i][j]=%lf, sps=%lf, prod=%lf\n", PP[i][j], sps, PP[i][j]*sps); fflush(stdout); printf("emwiener Set3: y = %lf <- PP[i][j]*sps=%lf, (sps+nv)=%lf, prod = %lf\n", y, PP[i][j] * sps, sps + nv, PP[i][j] * sps / (sps + nv)); fflush(stdout); #endif } #ifdef DEBUG_PRINTS printf("emwiener Set4: new W1[%ld]=%lf <- W1[%ld]=%lf * y=%lf\n", i, w1[i]*y, i, w1[i], y); fflush(stdout); #endif w1[i] *= y; // change only in this level } } }

void QuickBucket::GenerateCases() { xyLoc o(100,100); for (int x = o.x-3; x <= o.x+3; x++) { for (int y = o.y-3; y <= o.y+3; y++) { xyLoc l(x,y); int baseCase = GetBaseCase(l,o); for (direction d = 0; d < 8; d++) { xyLoc l2(x+X[d], y+Y[d]); cases[baseCase] = GetCase(l,l2,o); baseCase ++; } } } }

int main(int argc, const char * argv[]) { Leaf1 l1(7,8,9); //cout<<l1.getpriv()<<endl; //cout<<l1.publ<<endl; cout<<l1.get11priv()<<endl; Derived1 d1(7,8,9); cout<<d1.get1priv()<<endl; Leaf2 l2(1, 2, 3); Leaf3 l3(4, 5, 6); l2.print(); l3.print(); cout<<endl; cout<<l3.publ<<endl; // insert code here... std::cout << "Hello, World!\n"; return 0; }

void TestList( const Allocator& a ) { typedef std::list< typename Allocator::value_type, Allocator > List; List l1( Policy< Allocator >::template GetDefault< List >( a ) ); List l2( Policy< Allocator >::template GetCopied< List >( a ) ); TestList( a, l1 ); TestList( a, l2 ); l1.swap( l2 ); TestList( a, l1 ); TestList( a, l2 ); l1.splice( l1.end(), l2 ); TestList( a, l1 ); TestList( a, l2 ); }

void io_test() { quan::time::min t1(1.5); quan::time::s t2(22.2); quan::length::ft l1(.222); { std::ofstream out("data.txt"); out << t1 << '\n' << t2 << '\n' << l1 ; } std::ifstream in("data.txt"); quan::time::min t3; quan::time::s t4; quan::length::ft l2(1); in >> t3 >> t4 >> l2; QUAN_CHECK(!in.bad()); QUAN_CHECK(t1 == t3); QUAN_CHECK(t2 ==t4); QUAN_CHECK(l1 == l2); }

bool intersection1b(Segment s1, Segment s2){ //check for intersection of to segments // get start end end points of segments Point p1 = s1.source(); Point p2 = s1.target(); Point p3 = s2.source(); Point p4 = s2.target(); // create line objects from the points Line l1(p1, p2); Line l2(p3, p4); // compute orientation of each point relative to the other line Oriented_side side1 = l1.oriented_side(p3); Oriented_side side2 = l1.oriented_side(p4); Oriented_side side3 = l2.oriented_side(p1); Oriented_side side4 = l2.oriented_side(p2); // std::cout << "side " << side1 << std::endl; // std::cout << "side " << side2 << std::endl; // std::cout << "side " << side3 << std::endl; // std::cout << "side " << side4 << std::endl; // if any point is on the respective other line if (side1 == CGAL::ON_ORIENTED_BOUNDARY || side2 == CGAL::ON_ORIENTED_BOUNDARY || side3 == CGAL::ON_ORIENTED_BOUNDARY || side4 == CGAL::ON_ORIENTED_BOUNDARY) { // then we check all possible cases of points on segment if (s1.has_on(p3)) { return 1; } if (s1.has_on(p4)) { return 1; } if (s2.has_on(p1)) { return 1; } if (s2.has_on(p2)) { return 1; } } // otherwise perform the check for non-colinear segments return side1 != side2 && side3 != side4; }

// Compute some kind of error. Output is global variables double conerr_1D(double **MU, double **MUO, double **SI, double **SIO, double **PS, double **PSO, double ***ES, double ***ESO, int P, long num_states) { int i,j,jj,J,level; double errval; //double t1,t2,t3,t4;//Unused Variable double pserr,muerr,sierr,eserr; pserr = 0.0; // error in p muerr = 0.0; // error in mu sierr = 0.0; // error in st.d. eserr = 0.0; // error in transition probs level = l2(P); // what is P? J = level; // why times 3? for(i=0; i<level; i++) // wavelets level // start index at zero!!! // for(j=1;j<=3;j++) // what's here? why 3? for(j=0; j<num_states; j++) // loop on Gaussians instead { pserr += (PS[i][j]-PSO[i][j])*(PS[i][j]-PSO[i][j]); // Compute sum of squares error muerr += (MU[i][j]-MUO[i][j])*(MU[i][j]-MUO[i][j]); // why no mu error? Added mu error sierr += (SI[i][j]-SIO[i][j])*(SI[i][j]-SIO[i][j]); for(jj=0; jj<num_states; jj++) eserr += (ES[i][j][jj]-ESO[i][j][jj])*(ES[i][j][jj]-ESO[i][j][jj]); } //printf(" ---> Delta(P)=%lf, Delta(es)=%lf, Delta(mu)=%lf, Delta(SD)=%lf\n",pserr, eserr, muerr, sierr); // print all errors pserr/=J; // normalize all errors by J - what is J? muerr/=J; sierr/=J; eserr/=J; errval = MAX(MAX(pserr, sierr), MAX(muerr, eserr)); // take maximum error return(errval); }

bool FSSftp::Equal( FS* fs ) { if ( !fs || fs->Type() != FS::SFTP ) { return false; } if ( fs == this ) { return true; } FSSftp* f = ( FSSftp* )fs; MutexLock l1( &infoMutex ); MutexLock l2( &( f->infoMutex ) ); if ( _infoParam.isSet != f->_infoParam.isSet ) { return false; } return !CmpStr<const unicode_t>( _infoParam.server.Data(), f->_infoParam.server.Data() ) && !CmpStr<const unicode_t>( _infoParam.user.Data(), f->_infoParam.user.Data() ) && _infoParam.port == f->_infoParam.port && _infoParam.charset == f->_infoParam.charset; }

void listTest(){ cct::List<int> list{1,2,3}; list.begin(); list.end(); list.cbegin(); list.cend(); list.crbegin(); list.crend(); list.rbegin(); list.rend(); list.size(); auto l1=list.toConst(); l1.clone(); cct::List<double> l2(std::piecewise_construct, l1.rbegin(),l1.rend()); l2.length(); }

TEST(LinearInterp, LinearInterpFunctions) { LinearInterp<float> l1; EXPECT_NEAR(l1.interpolate(1), 0, 0.0001); LinearInterp<float> l2(3.1); EXPECT_NEAR(l2.interpolate(1), 3.1, 0.0001); LinearInterp<float> l3; l3.addPoint(2, 1); EXPECT_NEAR(l3.interpolate(1), 1, 0.0001); EXPECT_NEAR(l3.interpolate(2), 1, 0.0001); EXPECT_NEAR(l3.interpolate(3), 1, 0.0001); LinearInterp <float> l4; l4.addPoint(2, 1); l4.addPoint(3, 2); l4.setBoundaryMode(LinearInterp<float>::CONSTANTSLOPE); EXPECT_NEAR(l4.interpolate(1), 0, 0.0001); EXPECT_NEAR(l4.interpolate(0), -1, 0.0001); EXPECT_NEAR(l4.interpolate(2.5), 1.5, 0.0001); EXPECT_NEAR(l4.interpolate(2.75), 1.75, 0.0001); EXPECT_NEAR(l4.interpolate(3), 2, 0.0001); EXPECT_NEAR(l4.interpolate(3.5), 2.5, 0.0001); }

int PositionVector::appendWithCrossingPoint(const PositionVector& v) { if (back().distanceTo(v[0]) < 2) { // !!! heuristic copy(v.begin() + 1, v.end(), back_inserter(*this)); return 1; } // Line l1((*this)[static_cast<int>(size()) - 2], back()); l1.extrapolateBy(100); Line l2(v[0], v[1]); l2.extrapolateBy(100); if (l1.intersects(l2) && l1.intersectsAtLength2D(l2) < l1.length2D() - 100) { // !!! heuristic Position p = l1.intersectsAt(l2); (*this)[static_cast<int>(size()) - 1] = p; copy(v.begin() + 1, v.end(), back_inserter(*this)); return 2; } else { copy(v.begin(), v.end(), back_inserter(*this)); return 3; } }

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; }