void AABoxOpsTest::testIsEqual() { gmtl::AABoxf box( gmtl::Point3f( -1,-2,-3 ), gmtl::Point3f( 4,5,6 ) ), bok( gmtl::Point3f( -1,-2,-3 ), gmtl::Point3f( 4,5,6 ) ), mok( gmtl::Point3f( -1,-2,-3 ), gmtl::Point3f( 4,5,7 ) ); CPPUNIT_ASSERT( gmtl::isEqual( bok, box, 0.0001f ) ); CPPUNIT_ASSERT( bok == box ); CPPUNIT_ASSERT( bok != mok ); CPPUNIT_ASSERT( !gmtl::isEqual( bok, mok, 0.0001f ) ); CPPUNIT_ASSERT( gmtl::isEqual( bok, mok, 1.0001f ) ); }
void manacher(const string &w, vector<vector<bool>> &fdp, vector<vector<bool>> &bdp) { int len = w.length(); string tmp(2*len+2, ' '); vector<int> dp(2*len+2, 0); tmp[0] = 1; tmp[1] = 0; dp[0] = 1; dp[1] = 1; for (int i=0; i<len; ++i) { tmp[2+i*2] = w[i]; tmp[2+i*2+1] = 0; } int ctr = 1; for (int i=2, end=2+len*2; i<end; ++i) { if (tmp[ctr-(i-ctr)] == tmp[i]) { ++dp[ctr]; } else { int octr = ctr++; for (; ctr<i; ++ctr) { dp[ctr] = min(dp[octr-(ctr-octr)], i-ctr); if (ctr+dp[ctr]==i && tmp[i]==tmp[ctr-(i-ctr)]) { break; } } ++dp[ctr]; } } int octr = ctr; for (int end=2+len*2; ctr<end; ++ctr) { dp[ctr] = min(dp[octr-(ctr-octr)], end-1-ctr); } vector<bool> fok(len, false), bok(len, false); for (int i=2, end=len*2; i<=end; ++i) { if (i+dp[i]-1>=end) { bok[(i-(end-i)-2)>>1] = true; } if (i-dp[i]+1<=2) { fok[(i+(i-2)-2)>>1] = true; }