void SimpleListTest::testCreate() { // SimpleList() SimpleList v1; TEST_ASSERT_EQUALS("{}", c_str(v1)); // SimpleList(size_type, value_type) SimpleList v2(2, (void*)"a"); TEST_ASSERT_EQUALS("{a, a}", c_str(v2)); const char* values[] = { "1st", "2nd" }; // SimpleList(const_pointer, const_pointer) SimpleList v3((void**)values, (void**)values + 2); TEST_ASSERT_EQUALS("{1st, 2nd}", c_str(v3)); // SimpleList(const_iterator, const_iterator) SimpleList v4(m_list.begin(), ++(++m_list.begin())); TEST_ASSERT_EQUALS("{1st, 2nd}", c_str(v4)); // SimpleList(const SimpleList&) SimpleList v5(m_list); TEST_ASSERT_EQUALS("{1st, 2nd, 3rd, 4th, 5th}", c_str(v5)); }
/** * @brief Sets up an encoding object with a sample graph */ void TestClusterwiseCrossoverEngine::setUp(void) { g= new Graph(); Vertex v0(0); Vertex v1(1); Vertex v2(2); Vertex v3(3); Vertex v4(4); Vertex v5(5); g->addVertex(v0); g->addVertex(v1); g->addVertex(v2); g->addVertex(v3); g->addVertex(v4); g->addVertex(v5); rng = new std::mt19937(); testObj = new ClusterwiseCrossoverEngine(rng); }
void DebugRenderer::AddBoundingBox(const BoundingBox& box, const Matrix3x4& transform, const Color& color, bool depthTest, bool solid) { const Vector3& min = box.min_; const Vector3& max = box.max_; Vector3 v0(transform * min); Vector3 v1(transform * Vector3(max.x_, min.y_, min.z_)); Vector3 v2(transform * Vector3(max.x_, max.y_, min.z_)); Vector3 v3(transform * Vector3(min.x_, max.y_, min.z_)); Vector3 v4(transform * Vector3(min.x_, min.y_, max.z_)); Vector3 v5(transform * Vector3(max.x_, min.y_, max.z_)); Vector3 v6(transform * Vector3(min.x_, max.y_, max.z_)); Vector3 v7(transform * max); unsigned uintColor = color.ToUInt(); if (!solid) { AddLine(v0, v1, uintColor, depthTest); AddLine(v1, v2, uintColor, depthTest); AddLine(v2, v3, uintColor, depthTest); AddLine(v3, v0, uintColor, depthTest); AddLine(v4, v5, uintColor, depthTest); AddLine(v5, v7, uintColor, depthTest); AddLine(v7, v6, uintColor, depthTest); AddLine(v6, v4, uintColor, depthTest); AddLine(v0, v4, uintColor, depthTest); AddLine(v1, v5, uintColor, depthTest); AddLine(v2, v7, uintColor, depthTest); AddLine(v3, v6, uintColor, depthTest); } else { AddPolygon(v0, v1, v2, v3, uintColor, depthTest); AddPolygon(v4, v5, v7, v6, uintColor, depthTest); AddPolygon(v0, v4, v6, v3, uintColor, depthTest); AddPolygon(v1, v5, v7, v2, uintColor, depthTest); AddPolygon(v3, v2, v7, v6, uintColor, depthTest); AddPolygon(v0, v1, v5, v4, uintColor, depthTest); } }
void tst_QQuaternion::subtract() { QFETCH(float, x1); QFETCH(float, y1); QFETCH(float, z1); QFETCH(float, w1); QFETCH(float, x2); QFETCH(float, y2); QFETCH(float, z2); QFETCH(float, w2); QFETCH(float, x3); QFETCH(float, y3); QFETCH(float, z3); QFETCH(float, w3); QQuaternion v1(w1, x1, y1, z1); QQuaternion v2(w2, x2, y2, z2); QQuaternion v3(w3, x3, y3, z3); QVERIFY((v3 - v1) == v2); QVERIFY((v3 - v2) == v1); QQuaternion v4(v3); v4 -= v1; QVERIFY(v4 == v2); QCOMPARE(v4.x(), v3.x() - v1.x()); QCOMPARE(v4.y(), v3.y() - v1.y()); QCOMPARE(v4.z(), v3.z() - v1.z()); QCOMPARE(v4.scalar(), v3.scalar() - v1.scalar()); QQuaternion v5(v3); v5 -= v2; QVERIFY(v5 == v1); QCOMPARE(v5.x(), v3.x() - v2.x()); QCOMPARE(v5.y(), v3.y() - v2.y()); QCOMPARE(v5.z(), v3.z() - v2.z()); QCOMPARE(v5.scalar(), v3.scalar() - v2.scalar()); }
void DebugRenderer::AddBoundingBox(const BoundingBox& box, const Color& color, bool depthTest, bool solid) { const Vector3& min = box.min_; const Vector3& max = box.max_; Vector3 v1(max.x_, min.y_, min.z_); Vector3 v2(max.x_, max.y_, min.z_); Vector3 v3(min.x_, max.y_, min.z_); Vector3 v4(min.x_, min.y_, max.z_); Vector3 v5(max.x_, min.y_, max.z_); Vector3 v6(min.x_, max.y_, max.z_); unsigned uintColor = color.ToUInt(); if (!solid) { AddLine(min, v1, uintColor, depthTest); AddLine(v1, v2, uintColor, depthTest); AddLine(v2, v3, uintColor, depthTest); AddLine(v3, min, uintColor, depthTest); AddLine(v4, v5, uintColor, depthTest); AddLine(v5, max, uintColor, depthTest); AddLine(max, v6, uintColor, depthTest); AddLine(v6, v4, uintColor, depthTest); AddLine(min, v4, uintColor, depthTest); AddLine(v1, v5, uintColor, depthTest); AddLine(v2, max, uintColor, depthTest); AddLine(v3, v6, uintColor, depthTest); } else { AddPolygon(min, v1, v2, v3, uintColor, depthTest); AddPolygon(v4, v5, max, v6, uintColor, depthTest); AddPolygon(min, v4, v6, v3, uintColor, depthTest); AddPolygon(v1, v5, max, v2, uintColor, depthTest); AddPolygon(v3, v2, max, v6, uintColor, depthTest); AddPolygon(min, v1, v5, v4, uintColor, depthTest); } }
TEST(SharedValueTest, ctorBool) { bool b = true; EXPECT_NO_THROW(Value v(b)); EXPECT_NO_THROW(Value v(false)); Value v(false); EXPECT_EQ(v.type(), typeid(bool)); EXPECT_EQ(v.as<bool>(), false); Value v2(true); EXPECT_EQ(v2.type(), typeid(bool)); EXPECT_EQ(v2.as<bool>(), true); Value v3(b); EXPECT_EQ(v3.type(), typeid(bool)); EXPECT_EQ(v3.as<bool>(), true); b = false; Value v4(b); EXPECT_EQ(v4.type(), typeid(bool)); EXPECT_EQ(v4.as<bool>(), false); float f = 11.44; Value v5(!(f - 111)); EXPECT_EQ(v5.type(), typeid(bool)); EXPECT_EQ(v5.as<bool>(), false); Value v6(!!0.1f); EXPECT_EQ(v6.type(), typeid(bool)); EXPECT_EQ(v6.as<bool>(), true); EXPECT_NO_THROW(Value v7(v6)); Value v7(v6); EXPECT_EQ(v7.type(), typeid(bool)); EXPECT_EQ(v7.as<bool>(), true); }
void TestTupleList() { test_db_config::DbConfig config; bool bRet = config.Init(); assert( bRet == true ); occiwrapper::ConnectionInfo info( config.GetStrIp(), 1521, config.GetUserName(), config.GetPassword(), config.GetSid() ); occiwrapper::SessionFactory sf; occiwrapper::Session s = sf.Create( info ); string strErrMsg; struct tm objTm; objTm.tm_year = 2014 - 1900; objTm.tm_mon = 11; objTm.tm_mday = 30; objTm.tm_hour = 10; objTm.tm_min = 43; objTm.tm_sec = 0; s << strCreateTable, now, bRet, strErrMsg; // test 1 elements s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int > t1[ 2 ]; t1[ 0 ] = make_tuple( 1 ); t1[ 1 ] = make_tuple( 2 ); list< tuple< int > > v1( t1, t1 + 2 ); s << "insert into tbl_test_tuple_elements( t1 ) values ( :1 )", batched_use( v1 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int > > v1Out; s << "select t1 from tbl_test_tuple_elements", into( v1Out ), now, bRet, strErrMsg; assert( bRet ); assert( v1Out.size() == 2 ); // test 2 elements s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float > t2[ 2 ]; t2[ 0 ] = make_tuple( 1, 1.1 ); t2[ 1 ] = make_tuple( 2, 2.1 ); list< tuple< int, float > > v2( t2, t2 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2 ) values ( :1, :2 )", batched_use( v2 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float > > v2Out; s << "select t1, t2 from tbl_test_tuple_elements", into( v2Out ), now, bRet, strErrMsg; assert( bRet ); assert( v2Out.size() == 2 ); // test 3 elements s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string > t3[ 2 ]; t3[ 0 ] = make_tuple( 1, 1.1, "str1" ); t3[ 1 ] = make_tuple( 2, 2.1, "str2" ); list< tuple< int, float, string > > v3( t3, t3 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3 ) values ( :1, :2, :3 )", batched_use( v3 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string > > v3Out; s << "select t1, t2, t3 from tbl_test_tuple_elements", into( v3Out ), now, bRet, strErrMsg; assert( bRet ); assert( v3Out.size() == 2 ); // test 4 elements s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm > t4[ 2 ]; t4[ 0 ] = make_tuple( 1, 1.1, "str1", objTm ); t4[ 1 ] = make_tuple( 2, 2.1, "str2", objTm ); list< tuple< int, float, string, struct tm > > v4( t4, t4 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4 ) values ( :1, :2, :3, :4 )", batched_use( v4 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm > > v4Out; s << "select t1, t2, t3, t4 from tbl_test_tuple_elements", into( v4Out ), now, bRet, strErrMsg; assert( bRet ); assert( v4Out.size() == 2 ); // test 5 elements s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm, struct tm > t5[ 2 ]; t5[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm ); t5[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm ); list< tuple< int, float, string, struct tm, struct tm > > v5( t5, t5 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5 ) values ( :1, :2, :3, :4, :5 )", batched_use( v5 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm, struct tm > > v5Out; s << "select t1, t2, t3, t4, t5 from tbl_test_tuple_elements", into( v5Out ), now, bRet, strErrMsg; assert( bRet ); assert( v5Out.size() == 2 ); // test 6 elements s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm, struct tm, double > t6[ 2 ]; t6[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2 ); t6[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2 ); list< tuple< int, float, string, struct tm, struct tm, double > > v6( t6, t6 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6 ) values ( :1, :2, :3, :4, :5, :6 )", batched_use( v6 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm, struct tm, double > > v6Out; s << "select t1, t2, t3, t4, t5, t6 from tbl_test_tuple_elements", into( v6Out ), now, bRet, strErrMsg; assert( bRet ); assert( v6Out.size() == 2 ); // test 7 element s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm, struct tm, double, double > t7[ 2 ]; t7[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2, 3.1 ); t7[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2, 3.2 ); list< tuple< int, float, string, struct tm, struct tm, double, double > > v7( t7, t7 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7 ) values ( :1, :2, :3, :4, :5, :6, :7 )", batched_use( v7 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm, struct tm, double, double > > v7Out; s << "select t1, t2, t3, t4, t5, t6, t7 from tbl_test_tuple_elements", into( v7Out ), now, bRet, strErrMsg; assert( bRet ); assert( v7Out.size() == 2 ); // test 8 element s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm, struct tm, double, double, string > t8[ 2 ]; t8[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2, 3.1, "str8_1" ); t8[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2, 3.2, "str8_2" ); list< tuple< int, float, string, struct tm, struct tm, double, double, string > > v8( t8, t8 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7, t8 ) values ( :1, :2, :3, :4, :5, :6, :7, :8 )", batched_use( v8 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm, struct tm, double, double, string > > v8Out; s << "select t1, t2, t3, t4, t5, t6, t7, t8 from tbl_test_tuple_elements", into( v8Out ), now, bRet, strErrMsg; assert( bRet ); assert( v8Out.size() == 2 ); // test 9 element s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm, struct tm, double, double, string, string > t9[ 2 ]; t9[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2, 3.1, "str8_1", "str9_1" ); t9[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2, 3.2, "str8_2", "str9_2" ); list< tuple< int, float, string, struct tm, struct tm, double, double, string, string > > v9( t9, t9 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7, t8, t9 ) values ( :1, :2, :3, :4, :5, :6, :7, :8, :9 )", batched_use( v9 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm, struct tm, double, double, string, string > > v9Out; s << "select t1, t2, t3, t4, t5, t6, t7, t8, t9 from tbl_test_tuple_elements", into( v9Out ), now, bRet, strErrMsg; assert( bRet ); assert( v9Out.size() == 2 ); // test 10 element s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); tuple< int, float, string, struct tm, struct tm, double, double, string, string, string > t10[ 2 ]; t10[ 0 ] = make_tuple( 1, 1.1, "str1", objTm, objTm, 1.2, 3.1, "str8_1", "str9_1", "str10_1" ); t10[ 1 ] = make_tuple( 2, 2.1, "str2", objTm, objTm, 2.2, 3.2, "str8_2", "str9_2", "str10_2" ); list< tuple< int, float, string, struct tm, struct tm, double, double, string, string, string > > v10( t10, t10 + 2 ); s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 ) values ( :1, :2, :3, :4, :5, :6, :7, :8, :9, :10 )", batched_use( v10 ), now, bRet, strErrMsg; assert( bRet ); list< tuple< int, float, string, struct tm, struct tm, double, double, string, string, string > > v10Out; s << "select t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 from tbl_test_tuple_elements", into( v10Out ), now, bRet, strErrMsg; assert( bRet ); assert( v10Out.size() == 2 ); s << "drop table tbl_test_tuple_elements", now, bRet, strErrMsg; assert( bRet ); }
bool fusion_vector_test(const char* archive_type, const char* io_type) { boost::fusion::vector<int, double> v1(33, 3.14), v2; typename archive_traits::oarchive oa; archive_traits::ocreate(oa, archive_type, io_type); oa & v1; typename archive_traits::iarchive ia; archive_traits::icreate(ia, oa, archive_type, io_type); ia & v2; if ( v1 != v2 ) { std::cout << "FUSION_VECTOR deserialization error! [1]" << std::endl; return false; } std::set<std::string> set; set.insert("2"); set.insert("3"); set.insert("4"); boost::fusion::vector< std::string, std::set<std::string> > v3("1", set), v4; typename archive_traits::oarchive oa2; archive_traits::ocreate(oa2, archive_type, io_type); oa2 & v3; typename archive_traits::iarchive ia2; archive_traits::icreate(ia2, oa2, archive_type, io_type); ia2 & v4; if ( v3 != v4 ) { std::cout << "FUSION_VECTOR deserialization error! [2]" << std::endl; return false; } boost::fusion::vector<int, int> vv; typename archive_traits::oarchive oa3; archive_traits::ocreate(oa3, archive_type, io_type); oa3 & boost::fusion::make_vector(33,44); typename archive_traits::iarchive ia3; archive_traits::icreate(ia3, oa3, archive_type, io_type); ia3 & vv; if ( vv != boost::fusion::make_vector(33,44) ) { std::cout << "FUSION_VECTOR deserialization error! [3]" << std::endl; return false; } static const char str[] = "str"; boost::fusion::vector<boost::uint64_t, std::string> v5(33, str), v6; typename archive_traits::oarchive oa4; archive_traits::ocreate(oa4, archive_type, io_type); oa4 & v5; const size_t expected_size = 4+ // archive information sizeof(std::uint8_t)+ // fusion::vector size marker sizeof(std::uint64_t)+ // first type sizeof(std::uint32_t)+ // string size marker strlen(str); // string length if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { const size_t current_size = oa4.size(); if ( current_size != expected_size ) { std::cout << "FUSION_VECTOR deserialization error! [4]" << std::endl; return false; } } typename archive_traits::iarchive ia4; archive_traits::icreate(ia4, oa4, archive_type, io_type); ia4 & v6; if ( v5 != v6 ) { std::cout << "FUSION_VECTOR deserialization error! [5]" << std::endl; return false; } typename archive_traits::oarchive oa5; archive_traits::ocreate(oa5, archive_type, io_type); oa5 & boost::fusion::make_vector<boost::uint64_t, std::string>(33, "str"); if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { const size_t current_size2 = oa5.size(); if ( current_size2 != expected_size ) { std::cout << "FUSION_VECTOR deserialization error! [6]" << std::endl; return false; } } typename archive_traits::iarchive ia5; archive_traits::icreate(ia5, oa5, archive_type, io_type); ia5 & v6; if ( v5 != v6 ) { std::cout << "FUSION_VECTOR deserialization error! [7]" << std::endl; return false; } return true; }
bool CubeMesh::Update(const D3DXVECTOR2& currentMousePos, const D3DXMATRIX& matWorld, const D3DXMATRIX& matView, const D3DXMATRIX& matProj) { GraphicsDevice* pGDevice = GraphicsDevice::getInstance(); IDirect3DDevice9* pDevice = pGDevice->m_pD3DDevice; //将屏幕坐标进行变换,变换到相对于mCubeViewport的原点的坐标 int x = int(currentMousePos.x - pGDevice->mCubeViewport.X); int y = int(currentMousePos.y - pGDevice->mCubeViewport.Y); //获取World中的射线 Ray ray = CalcPickingRay(x, y, pGDevice->mCubeViewport, matView, matProj ); //检测射线和所有三角形的相交情况 HRESULT hr = S_FALSE; UINT lSize = nPrimitive * 3 * sizeof(PCTVertex); PCTVertex* vertex = 0; V(pVB->Lock(0, 0, (void**)&vertex, 0)); FaceType lTargetFaceType = FaceType::None; //最近的Cube面 float lMinDistance = FLT_MAX; //最近的距离 for(unsigned int i = 0; i < nPrimitive * 3; i+=6) //步进6是为了遍历一个矩形的两个三角形 { FaceType lFaceType = FaceType(i/6); #ifdef DEBUG_CUBE switch(lFaceType) { case Forward: DebugPrintf("前"); break; case Backward: DebugPrintf("后"); break; case Upward: DebugPrintf("上"); break; case Downward: DebugPrintf("下"); break; case Left: DebugPrintf("左"); break; case Right: DebugPrintf("右"); break; default: break; } #endif PCTVertex& pt0 = vertex[IndexBuf.at(i)]; PCTVertex& pt1 = vertex[IndexBuf.at(i+1)]; PCTVertex& pt2 = vertex[IndexBuf.at(i+2)]; D3DXVECTOR3 v0(pt0.Pos); D3DXVECTOR3 v1(pt1.Pos); D3DXVECTOR3 v2(pt2.Pos); PCTVertex& pt3 = vertex[IndexBuf.at(i+3)]; PCTVertex& pt4 = vertex[IndexBuf.at(i+4)]; PCTVertex& pt5 = vertex[IndexBuf.at(i+5)]; D3DXVECTOR3 v3(pt3.Pos); D3DXVECTOR3 v4(pt4.Pos); D3DXVECTOR3 v5(pt5.Pos); //若与该三角形相交则加深其所在Cube面颜色 TODO:遍历完后取最近的Face float t =0.0f,u=0.0f,v=0.0f; if (Ray::Intersect(ray.Origin, ray.Direction, v0, v1, v2, &t, &u, &v) || Ray::Intersect(ray.Origin, ray.Direction, v3, v4, v5, &t, &u, &v)) { #ifdef DEBUG_CUBE DebugPrintf("√\n"); #endif if (t < lMinDistance) { lMinDistance = t; lTargetFaceType = lFaceType; } p = ray.Origin + t*ray.Direction; pt0.Color = D3DCOLOR_ARGB(0xff,0xcc,0xcc,0xcc); pt1.Color = D3DCOLOR_ARGB(0xff,0xcc,0xcc,0xcc); pt2.Color = D3DCOLOR_ARGB(0xff,0xcc,0xcc,0xcc); pt3.Color = D3DCOLOR_ARGB(0xff,0xcc,0xcc,0xcc); pt4.Color = D3DCOLOR_ARGB(0xff,0xcc,0xcc,0xcc); pt5.Color = D3DCOLOR_ARGB(0xff,0xcc,0xcc,0xcc); } else { #ifdef DEBUG_CUBE DebugPrintf("\n"); #endif pt0.Color = 0xFFFFFFFF; pt1.Color = 0xFFFFFFFF; pt2.Color = 0xFFFFFFFF; pt3.Color = 0xFFFFFFFF; pt4.Color = 0xFFFFFFFF; pt5.Color = 0xFFFFFFFF; } } V(pVB->Unlock()); return true; }
int main (int argc, char** argv) { UnitTest t (72); Variant v0 (true); Variant v1 (42); Variant v2 (3.14); Variant v3 ("foo"); Variant v4 (1234567890, Variant::type_date); Variant v5 (1200, Variant::type_duration); Variant v00 = v0 == v0; t.is (v00.type (), Variant::type_boolean, "true == true --> boolean"); t.is (v00.get_bool (), true, "true == true --> true"); Variant v01 = v0 == v1; t.is (v01.type (), Variant::type_boolean, "true == 42 --> boolean"); t.is (v01.get_bool (), false, "true == 42 --> false"); Variant v02 = v0 == v2; t.is (v02.type (), Variant::type_boolean, "true == 3.14 --> boolean"); t.is (v02.get_bool (), false, "true == 3.14 --> false"); Variant v03 = v0 == v3; t.is (v03.type (), Variant::type_boolean, "true == 'foo' --> boolean"); t.is (v03.get_bool (), false, "true == 'foo' --> false"); Variant v04 = v0 == v4; t.is (v04.type (), Variant::type_boolean, "true == 1234567890 --> boolean"); t.is (v04.get_bool (), false, "true == 1234567890 --> false"); Variant v05 = v0 == v5; t.is (v05.type (), Variant::type_boolean, "true == 1200 --> boolean"); t.is (v05.get_bool (), false, "true == 1200 --> false"); Variant v10 = v1 == v0; t.is (v10.type (), Variant::type_boolean, "42 == true --> boolean"); t.is (v10.get_bool (), false, "42 == true --> false"); Variant v11 = v1 == v1; t.is (v11.type (), Variant::type_boolean, "42 == 42 --> boolean"); t.is (v11.get_bool (), true, "42 == 42 --> true"); Variant v12 = v1 == v2; t.is (v12.type (), Variant::type_boolean, "42 == 3.14 --> boolean"); t.is (v12.get_bool (), false, "42 == 3.14 --> false"); Variant v13 = v1 == v3; t.is (v13.type (), Variant::type_boolean, "42 == 'foo' --> boolean"); t.is (v13.get_bool (), false, "42 == 'foo' --> false"); Variant v14 = v1 == v4; t.is (v04.type (), Variant::type_boolean, "42 == 1234567890 --> boolean"); t.is (v04.get_bool (), false, "42 == 1234567890 --> false"); Variant v15 = v1 == v5; t.is (v15.type (), Variant::type_boolean, "42 == 1200 --> boolean"); t.is (v15.get_bool (), false, "42 == 1200 --> false"); Variant v20 = v2 == v0; t.is (v20.type (), Variant::type_boolean, "3.14 == true --> boolean"); t.is (v20.get_bool (), false, "3.14 == true --> false"); Variant v21 = v2 == v1; t.is (v21.type (), Variant::type_boolean, "3.14 == 42 --> boolean"); t.is (v21.get_bool (), false, "3.14 == 42 --> false"); Variant v22 = v2 == v2; t.is (v22.type (), Variant::type_boolean, "3.14 == 3.14 --> boolean"); t.is (v22.get_bool (), true, "3.14 == 3.14 --> true"); Variant v23 = v2 == v3; t.is (v23.type (), Variant::type_boolean, "3.14 == 'foo' --> boolean"); t.is (v23.get_bool (), false, "3.14 == 'foo' --> false"); Variant v24 = v2 == v4; t.is (v24.type (), Variant::type_boolean, "3.14 == 1234567890 --> boolean"); t.is (v24.get_bool (), false, "3.14 == 1234567890 --> false"); Variant v25 = v2 == v5; t.is (v25.type (), Variant::type_boolean, "3.14 == 1200 --> boolean"); t.is (v25.get_bool (), false, "3.14 == 1200 --> false"); Variant v30 = v3 == v0; t.is (v30.type (), Variant::type_boolean, "'foo' == true --> boolean"); t.is (v30.get_bool (), false, "'foo' == true --> false"); Variant v31 = v3 == v1; t.is (v31.type (), Variant::type_boolean, "'foo' == 42 --> boolean"); t.is (v31.get_bool (), false, "'foo' == 42 --> false"); Variant v32 = v3 == v2; t.is (v32.type (), Variant::type_boolean, "'foo' == 3.14 --> boolean"); t.is (v32.get_bool (), false, "'foo' == 3.14 --> false"); Variant v33 = v3 == v3; t.is (v33.type (), Variant::type_boolean, "'foo' == 'foo' --> boolean"); t.is (v33.get_bool (), true, "'foo' == 'foo' --> true"); Variant v34 = v3 == v4; t.is (v34.type (), Variant::type_boolean, "'foo' == 1234567890 --> boolean"); t.is (v34.get_bool (), false, "'foo' == 1234567890 --> false"); Variant v35 = v3 == v5; t.is (v35.type (), Variant::type_boolean, "'foo' == 1200 --> boolean"); t.is (v35.get_bool (), false, "'foo' == 1200 --> false"); Variant v40 = v4 == v0; t.is (v40.type (), Variant::type_boolean, "1234567890 == true --> boolean"); t.is (v40.get_bool (), false, "1234567890 == true --> false"); Variant v41 = v4 == v1; t.is (v41.type (), Variant::type_boolean, "1234567890 == 42 --> boolean"); t.is (v41.get_bool (), false, "1234567890 == 42 --> false"); Variant v42 = v4 == v2; t.is (v42.type (), Variant::type_boolean, "1234567890 == 3.14 --> boolean"); t.is (v42.get_bool (), false, "1234567890 == 3.14 --> false"); Variant v43 = v4 == v3; t.is (v43.type (), Variant::type_boolean, "1234567890 == 'foo' --> boolean"); t.is (v43.get_bool (), false, "1234567890 == 'foo' --> false"); Variant v44 = v4 == v4; t.is (v44.type (), Variant::type_boolean, "1234567890 == 1234567890 --> boolean"); t.is (v44.get_bool (), true, "1234567890 == 1234567890 --> true"); Variant v45 = v4 == v5; t.is (v45.type (), Variant::type_boolean, "1234567890 == 1200 --> boolean"); t.is (v45.get_bool (), false, "1234567890 == 1200 --> false"); Variant v50 = v5 == v0; t.is (v50.type (), Variant::type_boolean, "1200 == true --> boolean"); t.is (v50.get_bool (), false, "1200 == true --> false"); Variant v51 = v5 == v1; t.is (v51.type (), Variant::type_boolean, "1200 == 42 --> boolean"); t.is (v51.get_bool (), false, "1200 == 42 --> false"); Variant v52 = v5 == v2; t.is (v52.type (), Variant::type_boolean, "1200 == 3.14 --> boolean"); t.is (v52.get_bool (), false, "1200 == 3.14 --> false"); Variant v53 = v5 == v3; t.is (v53.type (), Variant::type_boolean, "1200 == 'foo' --> boolean"); t.is (v53.get_bool (), false, "1200 == 'foo' --> false"); Variant v54 = v5 == v4; t.is (v04.type (), Variant::type_boolean, "1200 == 1234567890 --> boolean"); t.is (v04.get_bool (), false, "1200 == 1234567890 --> false"); Variant v55 = v5 == v5; t.is (v55.type (), Variant::type_boolean, "1200 == 1200 --> boolean"); t.is (v55.get_bool (), true, "1200 == 1200 --> true"); return 0; }
// Computes the root bit bound of the expression. // In effect, computeBound() returns the current value of low. extLong ExprRep::computeBound() { extLong measureBd = measure(); // extLong cauchyBd = length(); extLong ourBd = (d_e() - EXTLONG_ONE) * high() + lc(); // BFMSS[2,5] bound. extLong bfmsskBd; if (v2p().isInfty() || v2m().isInfty()) bfmsskBd = CORE_INFTY; else bfmsskBd = l25() + u25() * (d_e() - EXTLONG_ONE) - v2() - ceilLg5(v5()); // since we might compute \infty - \infty for this bound if (bfmsskBd.isNaN()) bfmsskBd = CORE_INFTY; extLong bd = core_min(measureBd, // core_min(cauchyBd, core_min(bfmsskBd, ourBd)); #ifdef CORE_SHOW_BOUNDS std::cout << "Bounds (" << measureBd << "," << bfmsskBd << ", " << ourBd << "), "; std::cout << "MIN = " << bd << std::endl; std::cout << "d_e= " << d_e() << std::endl; #endif #ifdef CORE_DEBUG_BOUND // Some statistics about which one is/are the winner[s]. computeBoundCallsCounter++; int number_of_winners = 0; std::cerr << " New contest " << std::endl; if (bd == bfmsskBd) { BFMSS_counter++; number_of_winners++; std::cerr << " BFMSS is the winner " << std::endl; } if (bd == measureBd) { Measure_counter++; number_of_winners++; std::cerr << " measureBd is the winner " << std::endl; } /* if (bd == cauchyBd) { Cauchy_counter++; number_of_winners++; std::cerr << " cauchyBd is the winner " << std::endl; } */ if (bd == ourBd) { LiYap_counter++; number_of_winners++; std::cerr << " ourBd is the winner " << std::endl; } assert(number_of_winners >= 1); if (number_of_winners == 1) { if (bd == bfmsskBd) { BFMSS_only_counter++; std::cerr << " BFMSSBd is the only winner " << std::endl; } else if (bd == measureBd) { Measure_only_counter++; std::cerr << " measureBd is the only winner " << std::endl; } /* else if (bd == cauchyBd) { Cauchy_only_counter++; std::cerr << " cauchyBd is the only winner " << std::endl; } */ else if (bd == ourBd) { LiYap_only_counter++; std::cerr << " ourBd is the only winner " << std::endl; } } #endif return bd; }//computeBound()
void ValueTest::onEnter() { UnitTestDemo::onEnter(); Value v1; CCASSERT(v1.getType() == Value::Type::NONE, ""); CCASSERT(v1.isNull(), ""); Value v2(100); CCASSERT(v2.getType() == Value::Type::INTEGER, ""); CCASSERT(!v2.isNull(), ""); Value v3(101.4f); CCASSERT(v3.getType() == Value::Type::FLOAT, ""); CCASSERT(!v3.isNull(), ""); Value v4(106.1); CCASSERT(v4.getType() == Value::Type::DOUBLE, ""); CCASSERT(!v4.isNull(), ""); unsigned char byte = 50; Value v5(byte); CCASSERT(v5.getType() == Value::Type::BYTE, ""); CCASSERT(!v5.isNull(), ""); Value v6(true); CCASSERT(v6.getType() == Value::Type::BOOLEAN, ""); CCASSERT(!v6.isNull(), ""); Value v7("string"); CCASSERT(v7.getType() == Value::Type::STRING, ""); CCASSERT(!v7.isNull(), ""); Value v8(std::string("string2")); CCASSERT(v8.getType() == Value::Type::STRING, ""); CCASSERT(!v8.isNull(), ""); auto createValueVector = [&]() { ValueVector ret; ret.push_back(v1); ret.push_back(v2); ret.push_back(v3); return ret; }; Value v9(createValueVector()); CCASSERT(v9.getType() == Value::Type::VECTOR, ""); CCASSERT(!v9.isNull(), ""); auto createValueMap = [&]() { ValueMap ret; ret["aaa"] = v1; ret["bbb"] = v2; ret["ccc"] = v3; return ret; }; Value v10(createValueMap()); CCASSERT(v10.getType() == Value::Type::MAP, ""); CCASSERT(!v10.isNull(), ""); auto createValueMapIntKey = [&]() { ValueMapIntKey ret; ret[111] = v1; ret[222] = v2; ret[333] = v3; return ret; }; Value v11(createValueMapIntKey()); CCASSERT(v11.getType() == Value::Type::INT_KEY_MAP, ""); CCASSERT(!v11.isNull(), ""); }
void Cube::initialize() { // Buffer Vertex Data for a Color cube GLfloat hW = 1 / 2.0f; GLfloat hH = 1 / 2.0f; GLfloat hD = 1 / 2.0f; vector<pntVertexData> v; // Vertex Positions glm::vec4 v0(-hW, -hH, hD, 1.0f); glm::vec4 v1(-hW, -hH, -hD, 1.0f); glm::vec4 v2(hW, -hH, -hD, 1.0f); glm::vec4 v3(hW, -hH, hD, 1.0f); glm::vec4 v4(-hW, hH, hD, 1.0f); glm::vec4 v5(-hW, hH, -hD, 1.0f); glm::vec4 v6(hW, hH, -hD, 1.0f); glm::vec4 v7(hW, hH, hD, 1.0f); // Create interleaved position and normal data glm::vec3 n = glm::vec3(-1, 0, 0); v.push_back(pntVertexData(v0, n, glm::vec2(0.0f, 0.0f))); v.push_back(pntVertexData(v4, n, glm::vec2(0.0f, 1.0f))); v.push_back(pntVertexData(v1, n, glm::vec2(1.0f, 0.0f))); v.push_back(pntVertexData(v1, n, glm::vec2(1.0f, 0.0f))); v.push_back(pntVertexData(v4, n, glm::vec2(0.0f, 1.0f))); v.push_back(pntVertexData(v5, n, glm::vec2(1.0f, 1.0f))); n = glm::vec3(1, 0, 0); v.push_back(pntVertexData(v3, n, glm::vec2(0.0f, 0.0f))); v.push_back(pntVertexData(v2, n, glm::vec2(1.0f, 0.0f))); v.push_back(pntVertexData(v6, n, glm::vec2(1.0f, 1.0f))); v.push_back(pntVertexData(v3, n, glm::vec2(0.0f, 0.0f))); v.push_back(pntVertexData(v6, n, glm::vec2(1.0f, 1.0f))); v.push_back(pntVertexData(v7, n, glm::vec2(0.0f, 1.0f))); n = glm::vec3(0, 0, 1); v.push_back(pntVertexData(v0, n, glm::vec2(0.0f, 1.0f))); v.push_back(pntVertexData(v3, n, glm::vec2(1.0f, 1.0f))); v.push_back(pntVertexData(v7, n, glm::vec2(1.0f, 0.0f))); v.push_back(pntVertexData(v0, n, glm::vec2(0.0f, 1.0f))); v.push_back(pntVertexData(v7, n, glm::vec2(1.0f, 0.0f))); v.push_back(pntVertexData(v4, n, glm::vec2(0.0f, 0.0f))); n = glm::vec3(0, 0, -1); v.push_back(pntVertexData(v1, n, glm::vec2(1.0f, 0.0f))); v.push_back(pntVertexData(v5, n, glm::vec2(1.0f, 1.0f))); v.push_back(pntVertexData(v2, n, glm::vec2(0.0f, 0.0f))); v.push_back(pntVertexData(v2, n, glm::vec2(0.0f, 0.0f))); v.push_back(pntVertexData(v5, n, glm::vec2(1.0f, 1.0f))); v.push_back(pntVertexData(v6, n, glm::vec2(0.0f, 1.0f))); n = glm::vec3(0, 1, 0); v.push_back(pntVertexData(v4, n, glm::vec2(0.0f, 0.0f))); v.push_back(pntVertexData(v7, n, glm::vec2(2.0f, 0.0f))); v.push_back(pntVertexData(v6, n, glm::vec2(2.0f, 2.0f))); v.push_back(pntVertexData(v4, n, glm::vec2(0.0f, 0.0f))); v.push_back(pntVertexData(v6, n, glm::vec2(2.0f, 2.0f))); v.push_back(pntVertexData(v5, n, glm::vec2(0.0f, 2.0f))); n = glm::vec3(0, -1, 0); v.push_back(pntVertexData(v0, n, glm::vec2(0.0f, 1.0f))); v.push_back(pntVertexData(v2, n, glm::vec2(2.0f, 0.0f))); v.push_back(pntVertexData(v3, n, glm::vec2(2.0f, 1.0f))); v.push_back(pntVertexData(v0, n, glm::vec2(0.0f, 1.0f))); v.push_back(pntVertexData(v1, n, glm::vec2(0.0f, 0.0f))); v.push_back(pntVertexData(v2, n, glm::vec2(2.0f, 0.0f))); glUseProgram(shaderProgram); material = Material(glGetUniformLocation(shaderProgram, "object.ambientMat"), glGetUniformLocation(shaderProgram, "object.diffuseMat"), glGetUniformLocation(shaderProgram, "object.specularMat"), glGetUniformLocation(shaderProgram, "object.specularExp"), glGetUniformLocation(shaderProgram, "object.emmissiveMat"), glGetUniformLocation(shaderProgram, "object.textureMode")); // Generate vertex array object and bind it for the first time glGenVertexArrays(1, &vertexArrayObject); glBindVertexArray(vertexArrayObject); GLuint VBO; glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, v.size() * sizeof(pntVertexData), &v[0], GL_STATIC_DRAW); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(pntVertexData), 0); glEnableVertexAttribArray(0); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(pntVertexData), (const GLvoid*)sizeof(glm::vec4)); glEnableVertexAttribArray(1); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(pntVertexData), (const GLvoid*)(sizeof(glm::vec3)+sizeof(glm::vec4))); glEnableVertexAttribArray(2); numberOfIndices = v.size(); v.clear(); // Set the modeling transformation glm::mat4 modelingTransformation = glm::translate(glm::vec3(0.0, 0.0f, 0.0f)) * glm::rotate(M_PI / 4.0f, glm::vec3(0.0f, 1.0f, 0.0f)); GLuint modelLocation = glGetUniformLocation(shaderProgram, "modelMatrix"); assert(modelLocation != 0xFFFFFFFF); glUniformMatrix4fv(modelLocation, 1, GL_FALSE, glm::value_ptr(modelingTransformation)); }
void CHttpTestCase4::DoRunL() { // Literals used in the function _LIT8(KWapTestUrl, "http://WapTestIP/perl/dumpform.pl"); // Replace the host name in the URL HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile); CleanupStack::PushL(newUrl8); TPtr8 newUrlPtr8 = newUrl8->Des(); TUriParser8 testURI; testURI.Parse(newUrlPtr8); //open a Session RHTTPSession mySession; mySession.OpenL(); CleanupClosePushL(mySession); iEngine->Utils().LogIt(_L("Session Created(TC4)")); iEngine->Utils().LogIt(_L("Session parameters: Default")); //Get the mySession'string pool handle; iMyStrP = mySession.StringPool(); //get strings this testcase needs RStringF textPlain = iMyStrP.StringF(HTTP::ETextPlain, RHTTPSession::GetTable()); RStringF textHtml = iMyStrP.StringF(HTTP::ETextHtml, RHTTPSession::GetTable()); RStringF mimeType = iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded, RHTTPSession::GetTable()); //Open a Transaction in mySession RHTTPTransaction myTransaction; myTransaction = mySession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable())); CleanupClosePushL(myTransaction); iEngine->Utils().LogIt(_L("Transaction Created in mySession")); //Get a handle of the request in myTransaction RHTTPRequest myRequest = myTransaction.Request(); RHTTPHeaders myHeaders = myRequest.GetHeaderCollection(); //provide some headers THTTPHdrVal v2(textPlain); THTTPHdrVal v3(textHtml); THTTPHdrVal v4(6); THTTPHdrVal v5(mimeType); myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept,RHTTPSession::GetTable()),v2); myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept,RHTTPSession::GetTable()),v3); myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength,RHTTPSession::GetTable()),v4); myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType,RHTTPSession::GetTable()), v5); TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8); iEngine->Utils().LogIt(_L("Method:Post")); iEngine->Utils().LogIt(_L("Accept:test/plain,text/html")); iEngine->Utils().LogIt(_L("Content-Type: application/x-www-form-urlencoded")); iEngine->Utils().LogIt(_L("Content-Length: 6")); myRequest.SetBody(*this); myTransaction.SubmitL(); CActiveScheduler::Start(); //close Transaction and session myTransaction.Close(); iEngine->Utils().LogIt(_L("Transaction terminated\n")); mySession.Close(); iEngine->Utils().LogIt(_L("Session terminated")); if (iTestFail==1) { User::Leave(-1); } CleanupStack::Pop(2); // mySession, myTansaction CleanupStack::PopAndDestroy(newUrl8); }
int main (int, char**) { UnitTest t (76); Variant v0 (true); Variant v1 (42); Variant v2 (3.14); Variant v3 ("foo"); Variant v4 (1234567890, Variant::type_date); Variant v5 (1200, Variant::type_duration); // Truth table. Variant vFalse (false); Variant vTrue (true); t.is (vFalse && vFalse, false, "false && false --> false"); t.is (vFalse && vTrue, false, "false && true --> false"); t.is (vTrue && vFalse, false, "true && false --> false"); t.is (vTrue && vTrue, true, "true && true --> true"); Variant v00 = v0 && v0; t.is (v00.type (), Variant::type_boolean, "true && true --> boolean"); t.is (v00.get_bool (), true, "true && true --> true"); Variant v01 = v0 && v1; t.is (v01.type (), Variant::type_boolean, "true && 42 --> boolean"); t.is (v01.get_bool (), true, "true && 42 --> true"); Variant v02 = v0 && v2; t.is (v02.type (), Variant::type_boolean, "true && 3.14 --> boolean"); t.is (v02.get_bool (), true, "true && 3.14 --> true"); Variant v03 = v0 && v3; t.is (v03.type (), Variant::type_boolean, "true && 'foo' --> boolean"); t.is (v03.get_bool (), true, "true && 'foo' --> true"); Variant v04 = v0 && v4; t.is (v04.type (), Variant::type_boolean, "true && 1234567890 --> boolean"); t.is (v04.get_bool (), true, "true && 1234567890 --> true"); Variant v05 = v0 && v5; t.is (v05.type (), Variant::type_boolean, "true && 1200 --> boolean"); t.is (v05.get_bool (), true, "true && 1200 --> true"); Variant v10 = v1 && v0; t.is (v10.type (), Variant::type_boolean, "42 && true --> boolean"); t.is (v10.get_bool (), true, "42 && true --> true"); Variant v11 = v1 && v1; t.is (v11.type (), Variant::type_boolean, "42 && 42 --> boolean"); t.is (v11.get_bool (), true, "42 && 42 --> true"); Variant v12 = v1 && v2; t.is (v12.type (), Variant::type_boolean, "42 && 3.14 --> boolean"); t.is (v12.get_bool (), true, "42 && 3.14 --> true"); Variant v13 = v1 && v3; t.is (v13.type (), Variant::type_boolean, "42 && 'foo' --> boolean"); t.is (v13.get_bool (), true, "42 && 'foo' --> true"); Variant v14 = v1 && v4; t.is (v04.type (), Variant::type_boolean, "42 && 1234567890 --> boolean"); t.is (v04.get_bool (), true, "42 && 1234567890 --> true"); Variant v15 = v1 && v5; t.is (v15.type (), Variant::type_boolean, "42 && 1200 --> boolean"); t.is (v15.get_bool (), true, "42 && 1200 --> true"); Variant v20 = v2 && v0; t.is (v20.type (), Variant::type_boolean, "3.14 && true --> boolean"); t.is (v20.get_bool (), true, "3.14 && true --> true"); Variant v21 = v2 && v1; t.is (v21.type (), Variant::type_boolean, "3.14 && 42 --> boolean"); t.is (v21.get_bool (), true, "3.14 && 42 --> true"); Variant v22 = v2 && v2; t.is (v22.type (), Variant::type_boolean, "3.14 && 3.14 --> boolean"); t.is (v22.get_bool (), true, "3.14 && 3.14 --> true"); Variant v23 = v2 && v3; t.is (v23.type (), Variant::type_boolean, "3.14 && 'foo' --> boolean"); t.is (v23.get_bool (), true, "3.14 && 'foo' --> true"); Variant v24 = v2 && v4; t.is (v24.type (), Variant::type_boolean, "3.14 && 1234567890 --> boolean"); t.is (v24.get_bool (), true, "3.14 && 1234567890 --> true"); Variant v25 = v2 && v5; t.is (v25.type (), Variant::type_boolean, "3.14 && 1200 --> boolean"); t.is (v25.get_bool (), true, "3.14 && 1200 --> true"); Variant v30 = v3 && v0; t.is (v30.type (), Variant::type_boolean, "'foo' && true --> boolean"); t.is (v30.get_bool (), true, "'foo' && true --> true"); Variant v31 = v3 && v1; t.is (v31.type (), Variant::type_boolean, "'foo' && 42 --> boolean"); t.is (v31.get_bool (), true, "'foo' && 42 --> true"); Variant v32 = v3 && v2; t.is (v32.type (), Variant::type_boolean, "'foo' && 3.14 --> boolean"); t.is (v32.get_bool (), true, "'foo' && 3.14 --> true"); Variant v33 = v3 && v3; t.is (v33.type (), Variant::type_boolean, "'foo' && 'foo' --> boolean"); t.is (v33.get_bool (), true, "'foo' && 'foo' --> true"); Variant v34 = v3 && v4; t.is (v34.type (), Variant::type_boolean, "'foo' && 1234567890 --> boolean"); t.is (v34.get_bool (), true, "'foo' && 1234567890 --> true"); Variant v35 = v3 && v5; t.is (v35.type (), Variant::type_boolean, "'foo' && 1200 --> boolean"); t.is (v35.get_bool (), true, "'foo' && 1200 --> true"); Variant v40 = v4 && v0; t.is (v40.type (), Variant::type_boolean, "1234567890 && true --> boolean"); t.is (v40.get_bool (), true, "1234567890 && true --> true"); Variant v41 = v4 && v1; t.is (v41.type (), Variant::type_boolean, "1234567890 && 42 --> boolean"); t.is (v41.get_bool (), true, "1234567890 && 42 --> true"); Variant v42 = v4 && v2; t.is (v42.type (), Variant::type_boolean, "1234567890 && 3.14 --> boolean"); t.is (v42.get_bool (), true, "1234567890 && 3.14 --> true"); Variant v43 = v4 && v3; t.is (v43.type (), Variant::type_boolean, "1234567890 && 'foo' --> boolean"); t.is (v43.get_bool (), true, "1234567890 && 'foo' --> true"); Variant v44 = v4 && v4; t.is (v44.type (), Variant::type_boolean, "1234567890 && 1234567890 --> boolean"); t.is (v44.get_bool (), true, "1234567890 && 1234567890 --> true"); Variant v45 = v4 && v5; t.is (v45.type (), Variant::type_boolean, "1234567890 && 1200 --> boolean"); t.is (v45.get_bool (), true, "1234567890 && 1200 --> true"); Variant v50 = v5 && v0; t.is (v50.type (), Variant::type_boolean, "1200 && true --> boolean"); t.is (v50.get_bool (), true, "1200 && true --> true"); Variant v51 = v5 && v1; t.is (v51.type (), Variant::type_boolean, "1200 && 42 --> boolean"); t.is (v51.get_bool (), true, "1200 && 42 --> true"); Variant v52 = v5 && v2; t.is (v52.type (), Variant::type_boolean, "1200 && 3.14 --> boolean"); t.is (v52.get_bool (), true, "1200 && 3.14 --> true"); Variant v53 = v5 && v3; t.is (v53.type (), Variant::type_boolean, "1200 && 'foo' --> boolean"); t.is (v53.get_bool (), true, "1200 && 'foo' --> true"); Variant v54 = v5 && v4; t.is (v04.type (), Variant::type_boolean, "1200 && 1234567890 --> boolean"); t.is (v04.get_bool (), true, "1200 && 1234567890 --> true"); Variant v55 = v5 && v5; t.is (v55.type (), Variant::type_boolean, "1200 && 1200 --> boolean"); t.is (v55.get_bool (), true, "1200 && 1200 --> true"); return 0; }
void QhullLinkedList_test:: t_QhullLinkedList_iterator() { RboxPoints rcube("c"); Qhull q(rcube,"QR0"); // rotated unit cube QhullVertexList vs(q.endVertex(), q.endVertex()); QhullVertexListIterator i= vs; QCOMPARE(vs.count(), 0); QVERIFY(!i.hasNext()); QVERIFY(!i.hasPrevious()); i.toBack(); QVERIFY(!i.hasNext()); QVERIFY(!i.hasPrevious()); QhullVertexList vs2 = q.vertexList(); QhullVertexListIterator i2(vs2); QCOMPARE(vs2.count(), 8); i= vs2; QVERIFY(i2.hasNext()); QVERIFY(!i2.hasPrevious()); QVERIFY(i.hasNext()); QVERIFY(!i.hasPrevious()); i2.toBack(); i.toFront(); QVERIFY(!i2.hasNext()); QVERIFY(i2.hasPrevious()); QVERIFY(i.hasNext()); QVERIFY(!i.hasPrevious()); // i at front, i2 at end/back, 4 neighbors QhullVertexList vs3 = q.vertexList(); // same as vs2 QhullVertex v3(vs3.first()); QhullVertex v4= vs3.first(); QCOMPARE(v3, v4); QVERIFY(v3==v4); QhullVertex v5(v4.next()); QVERIFY(v4!=v5); QhullVertex v6(v5.next()); QhullVertex v7(v6.next()); QhullVertex v8(vs3.last()); QCOMPARE(i2.peekPrevious(), v8); i2.previous(); i2.previous(); i2.previous(); i2.previous(); QCOMPARE(i2.previous(), v7); QCOMPARE(i2.previous(), v6); QCOMPARE(i2.previous(), v5); QCOMPARE(i2.previous(), v4); QVERIFY(!i2.hasPrevious()); QCOMPARE(i.peekNext(), v4); // i.peekNext()= 1.0; // compiler error QCOMPARE(i.next(), v4); QCOMPARE(i.peekNext(), v5); QCOMPARE(i.next(), v5); QCOMPARE(i.next(), v6); QCOMPARE(i.next(), v7); i.next(); i.next(); i.next(); QCOMPARE(i.next(), v8); QVERIFY(!i.hasNext()); i.toFront(); QCOMPARE(i.next(), v4); }//t_QhullLinkedList_iterator
main() { Matrix a(2,2); a(0,0) = 2.0; a(0,1) = 1.0; a(1,0) = 1.0; a(1,1) = 2.0; Matrix b(1,1); b(0,0) = 10; Matrix c(3,3); c(0,0) = 9.0; c(0,1) = 2.0; c(0,2) = 2.0; c(2,0) = 2.0; c(2,1) = 2.0; c(2,2) = 9.0; c(1,0) = 2.0; c(1,1) = 9.0; c(1,2) = 2.0; ID d(1); d(0) = 1; ID e(1); e(0) = 2; ID f(2); f(0) = 1; f(1) = 0; ID g(2); g(0) = -1; g(1) = 2; ID h(3); h(0) = 2; h(1) = 1; h(2) = 3; ID m(3); m(0) = 5; m(1) = 4; m(2) = 3; Graph theGraph(6); Vertex v0(0,0); theGraph.addVertex(&v0); Vertex v1(1,1); theGraph.addVertex(&v1); Vertex v2(2,2); theGraph.addVertex(&v2); Vertex v3(3,3); theGraph.addVertex(&v3); Vertex v4(4,4); theGraph.addVertex(&v4); Vertex v5(5,5); theGraph.addVertex(&v5); theGraph.addEdge(0,1); theGraph.addEdge(2,1); theGraph.addEdge(1,3); theGraph.addEdge(5,4); theGraph.addEdge(4,3); Vector x(3); x(0) = 2; x(1) = 3; x(2) = 4.5; SuperLU *theSolver1 = new SuperLU; SparseGenColLinSOE *theSOE1 = new SparseGenColLinSOE(*theSolver1); opserr << "Test One with SuperLU\n"; theSOE1->setSize(theGraph); theSOE1->addA(a,f); theSOE1->addA(a,g); theSOE1->addA(c,h); theSOE1->addA(c,m,2.0); theSOE1->addB(x,h); theSOE1->addB(x,m,-1); theSOE1->solve(); opserr << "B: " << theSOE1->getB(); opserr << "X: " << theSOE1->getX(); delete theSOE1; KSPType method = KSPCG; // KSPCG KSPGMRES PCType preconditioner = PCJACOBI; // PCJACOBI PCILU PCBJACOBI PetscSparseSeqSolver *theSolver2 = new PetscSparseSeqSolver(method, preconditioner); SparseGenRowLinSOE *theSOE2 = new SparseGenRowLinSOE(*theSolver2); opserr << "Test Two with Petsc\n"; theSOE2->setSize(theGraph); theSOE2->addA(a,f); theSOE2->addA(a,g); theSOE2->addA(c,h); theSOE2->addA(c,m,2.0); theSOE2->addB(x,h); theSOE2->addB(x,m,-1); theSOE2->solve(); opserr << "B: " << theSOE2->getB(); opserr << "X: " << theSOE2->getX(); // solve again theSOE2->solve(); opserr << " results on a second solve with same B\n"; opserr << "B: " << theSOE2->getB(); opserr << "X: " << theSOE2->getX(); delete theSOE2; PetscSparseSeqSolver *theSolver3 = new PetscSparseSeqSolver(method, preconditioner); SparseGenRowLinSOE *theSOE3 = new SparseGenRowLinSOE(*theSolver3); opserr << "Test Three with Petsc\n"; theSOE3->setSize(theGraph); theSOE3->addA(a,f); theSOE3->addA(a,g); theSOE3->addA(c,h); theSOE3->addA(c,m,2.0); theSOE3->addB(x,h); theSOE3->addB(x,m,-1); theSOE2->solve(); opserr << "B: " << theSOE2->getB(); opserr << "X: " << theSOE2->getX(); // perturb A a bit theSOE3->addA(c,m,0.001); theSOE3->solve(); opserr << " results on a second solve with A perturbed\n"; opserr << "B: " << theSOE2->getB(); opserr << "X: " << theSOE2->getX(); // perturb B a bit theSOE3->addB(x,m,0.001); theSOE3->solve(); opserr << " results on a second solve with B perturbed\n"; opserr << "B: " << theSOE2->getB(); opserr << "X: " << theSOE2->getX(); delete theSOE3; exit(0); }
int main() { std::vector<int> vec; std::deque<int> deq; std::array<int, 3> arr{ -10, 0, 10 }, ar2{ -5, 1, 5 }; std::list<int> lis; std::forward_list<int> f_lis; //array { std::cout << "array: "; for (auto i : arr) std::cout << i << " "; std::cout << std::endl; //.at() std::cout << ".at(0) " << arr.at(0) << std::endl; //.empty() if (arr.empty()) std::cout << ".empty" << std::endl; else std::cout << ".not empty" << std::endl; //.back() std::cout << ".back() " << arr.back() << std::endl; //.begin() auto ptr = arr.begin(); //*ptr += 100; std::cout << ".begin() " << *ptr << std::endl; //.cbegin() auto const_ptr = arr.cbegin(); //const_iterator //*pt -= 100; std::cout << ".cbegin() " << *const_ptr << std::endl; //.cend() const_ptr = arr.cend() - 1; std::cout << ".cend()-1 " << *const_ptr << std::endl; //.crbegin() auto const_rev_it = arr.crbegin(); std::cout << ".crbegin() " << *const_rev_it << std::endl; for (auto it = arr.crbegin(); it != arr.crend(); it++) std::cout << *it << " "; std::cout << std::endl; //.crend() auto cri_ptr = arr.crend() - 1; std::cout << ".crend() " << *cri_ptr << std::endl; //.data() std::cout << ".data() " << *(arr.data()) << std::endl; //.end() ptr = arr.end() - 1; std::cout << ".end()-1 " << *ptr << std::endl; //.fill arr.fill(99); std::cout << ".fill() "; for (auto i : arr) std::cout << i << " "; std::cout << std::endl; //.front() std::cout << ".front() " << arr.front() << std::endl; //.max_size() std::cout << ".max_size() " << arr.max_size() << std::endl; //operator[] arr[0] = -10; arr[1] = 0; arr[2] = 10; std::cout << "opaerator[] "; for (auto i : arr) std::cout << i << " "; std::cout << std::endl; auto c = -2; for (auto &i : arr) { i = c; c += 2; } for (auto i : arr) std::cout << i << " "; std::cout << std::endl; //.rbegin() std::cout << ".rbegin() "; auto r_ptr = arr.rbegin(); std::cout << *r_ptr << std::endl; //.rend() std::cout << ".rend() "; r_ptr = arr.rend() - 1; std::cout << *r_ptr << std::endl; //.size() std::cout << ".size() " << arr.size() << std::endl; //.swap() arr.swap(ar2); std::cout << ".swap() "; for (auto i : arr) std::cout << i << " "; std::cout << std::endl; //get<>() auto x = std::get<0>(arr); std::cout << x << std::endl; } //vector { std::cout << std::endl; typedef std::vector<int> vect; vect v1({ -2, 0, 2 }); vect v2(3); v2.at(0) = -3; v2.at(1) = 1; v2.at(2) = 3; std::cout << "vector: "; for (auto i : v1) std::cout << i << " "; std::cout << std::endl; //.assign() std::cout << ".assign(5, 10) "; v1.assign(5, 10); for (auto i : v1) std::cout << i << " "; std::cout << std::endl << std::endl; std::cout << ".assign(v2.begin()+1, v2.end()-1) "; v1.assign(v2.begin(), v2.end()); for (auto i : v1) std::cout << i << " "; std::cout << std::endl; //.back() std::cout << ".back() " << v1.back() << std::endl; //.clear() std::cout << ".clear() " << std::endl; v1.clear(); for (auto i : v1) std::cout << i; std::cout << std::endl; //assign() v1.assign(v2.begin(), v2.end()); //.capacity() std::cout << ".capacity() " << v1.capacity() << std::endl; //.crbegin() auto vcrbeg = v1.crbegin(); std::cout << ".crbegin() " << *vcrbeg << std::endl; //.data() std::cout << ".data() " << *(v1.data()) << std::endl; //.emplace std::cout << ".emplace(1, 33) "; v1.emplace(v1.begin() + 1, 33); for (auto i : v1) std::cout << i << " "; std::cout << std::endl; //.emplace() v1.emplace_back(44); for (auto i : v1) std::cout << i << " "; std::cout << std::endl; vect v3({ 3,4,5,6,7 }); vect v4({ 3,4,5,6,7 }); std::cout << "v3.size() " << v3.size() << std::endl; std::cout << "v4.size() " << v4.size() << std::endl; std::cout << "v3.capacity() " << v3.capacity() << std::endl; std::cout << "v4.capacity() " << v4.capacity() << std::endl; v3.emplace_back(5); v4.push_back(5); std::cout << "v3.emplace_back() " << v3.capacity() << std::endl; std::cout << "v4.push_back() " << v4.capacity() << std::endl; //.insert() v1.insert(v1.begin() + 1, 99); std::cout << ".insert(v1.begin()+1, 99) "; for (auto i : v1) std::cout << i << " "; std::cout << std::endl; v1.insert(v1.begin() + 1, v3.begin(), v3.end()-1); std::cout << ".insert(v1.begin() + 1, v3.begin(), v3.end()-1) "; for (auto i : v1) std::cout << i << " "; std::cout << std::endl; //.pop_back() std::cout << ".pop_back() " << std::endl; int i = v1.size()-1; while (v1.size() > 0) { for (int j = 0; j <= i ; j++) std::cout << v1[j] << " "; std::cout << std::endl; v1.pop_back(); i--; } std::cout << std::endl; //.shrink_to_fit() vect v5(100); std::cout << v5.capacity() << std::endl; v5.resize(10); std::cout << v5.capacity() << std::endl; v5.reserve(200); std::cout << v5.capacity() << std::endl; v5.shrink_to_fit(); std::cout << v5.capacity() << std::endl; std::vector<char> vchar(50), vchar2(52); char ch[] = "Lukasz Nawrot"; strncpy_s(vchar.data(), 16, ch, 16); std::cout << vchar.data() << std::endl; } return 0; }
void HUD::setup(){ //Colors for HUDSpinners below ofColor c5(12,60,104); ofColor stepGraphColor(39,39,34); spinner5.setup(15 /*count*/, 0 /*avgRotSpd*/, 3 /*rotVariation*/, c5 /*color*/, 40 /*resolution*/, (22.0/1280.0)*ofGetWidth() /*minRad*/, (85.0/1280.0) * ofGetWidth() /*maxRad*/, (7.0/1280)*ofGetWidth() /*minWidth*/, (30.0/1280.0)*ofGetWidth() /*maxWidth*/, false); HUDimg.loadImage("HUD_AGUS_3.png"); //Lower Right Inner for (int i = 0; i < 3; i++){ HUDUnit tempy; tempy.setup(.5 /*rotSpeed*/, c5 /*color*/, 40 /*numSeg*/, .333 *i /*startSweep*/, .1 /*sweep (0-1)*/, (90.0/1680)*ofGetWidth() /*innerRad*/, (93.0/1680)*ofGetWidth()/*outerRad*/, true /*hasTail*/); unit1_1.push_back(tempy); } //Lower RIght Outer for (int i = 0; i < 4; i++){ HUDUnit tempy; tempy.setup(-.7 /*rotSpeed*/, c5 /*color*/, 40 /*numSeg*/, 0.25*i + .125 /*startSweep*/, .1 /*sweep (0-1)*/, (105.0/1680)*ofGetWidth() /*innerRad*/, (109.0/1680)*ofGetWidth()/*outerRad*/, true/*hasTail*/); unit1_2.push_back(tempy); } //Left inner for (int i = 0; i < 4; i++){ HUDUnit tempy; tempy.setup(.5 /*rotSpeed*/, c5 /*color*/, 40 /*numSeg*/, 0.25*i + ofRandom(-.03,.03) /*startSweep*/, ofRandom(.06, .08) /*sweep (0-1)*/, (51.0/1680)*ofGetWidth() /*innerRad*/, (54.0/1680)*ofGetWidth()/*outerRad*/, true/*hasTail*/); unit2_1.push_back(tempy); } //Left Outer for (int i = 0; i < 4; i++){ HUDUnit tempy; tempy.setup(-.5 /*rotSpeed*/, c5 /*color*/, 40 /*numSeg*/, 0.25*i + ofRandom(-.03,.03) /*startSweep*/, ofRandom(.07, .1) /*sweep (0-1)*/, (65.0/1680)*ofGetWidth() /*innerRad*/, (69.0/1680)*ofGetWidth()/*outerRad*/, true/*hasTail*/); unit2_2.push_back(tempy); } //Setup of Signal Quality Graph on Left of Screen stepGraph1.setup(100/*maxBlocks*/, (38.0/1280.0)*ofGetWidth()/*graphWidth*/, (388.0/768.0)*ofGetHeight()/*graphHeight*/, (2.5/1280.0)*ofGetWidth()/*distBetBlocks*/, stepGraphColor/*color*/, (0.019)*ofGetWindowWidth()/*xLoc*/, (0.768) *ofGetWindowHeight() /*yLoc*/); //Setup of ticker beneath central graph on right rangeMarker1Img.loadImage("RangeMarker_North.png"); rangeMarker1Color.set(100, 102, 90); ofVec3f v1((.9123)*ofGetWindowWidth(), (.6125)*ofGetWindowHeight(), 0); ofVec3f v2((.9773)*ofGetWindowWidth(), (.6125)*ofGetWindowHeight(), 0); rangeMarker1.setup(v1/*VEC3,rangeBound1*/, v2/*VEC3,rangeBound2*/, 10/*numIncrements*/, rangeMarker1Img/*img*/, (10.0/1680)*ofGetWidth()/*imgW*/, (12.0/1660)*ofGetWidth()/*imgH*/, rangeMarker1Color/*color*/, .005/*chanceToUpdate(0-1)*/); // Setup of ticker to the left of graph on top rangeMarker2Img.loadImage("RangeMarker_East.png"); rangeMarker2Color.set(100, 102, 90); ofVec3f v3((1040.0/1280.0)*ofGetWindowWidth(), (11.5/768.0)*ofGetWindowHeight(), 0); ofVec3f v4((1040.0/1280.0)*ofGetWindowWidth(), (76.0/768.0)*ofGetWindowHeight(), 0); rangeMarker2.setup(v3/*VEC3,rangeBound1*/, v4/*VEC3,rangeBound2*/, 10/*numIncrements*/, rangeMarker2Img/*img*/, (12.0/1680)*ofGetWidth()/*imgW*/, (8.0/1660)*ofGetWidth()/*imgH*/, rangeMarker2Color/*color*/, .005/*chanceToUpdate(0-1)*/); // Setup array of tickers in graph on right markerGraphImg.loadImage("RangeMarker_RectVert.png"); markerGraphColor.set(100, 102, 90); for(int i = 0; i < 15; i++){ HUDRangeMarker temp; ofVec3f v5((1168.5/1280.0)*ofGetWindowWidth()+((7.8/1680.0)*ofGetWidth())*(float)i, (300.0/768.0)*ofGetWindowHeight(), 0); ofVec3f v6((1168.5/1280.0)*ofGetWindowWidth()+((7.8/1680.0)*ofGetWidth())*(float)i, (322.0/768.0)*ofGetWindowHeight(), 0); temp.setup(v5/*VEC3,rangeBound1*/, v6/*VEC3,rangeBound2*/, 6/*numIncrements*/, markerGraphImg/*img*/, (3.0/1680)*ofGetWidth()/*imgW*/, (7.0/1680)*ofGetWidth()/*imgH*/, markerGraphColor/*color*/, 0.001*i /*chanceToUpdate(0-1)*/); markerGraph.push_back(temp); } singleBlink = false; doubleBlink = false; }
void QuatGenMetricTest::testGenTimingMakeRot() { double bokd = 1; float bokf = 1; gmtl::Quat<double> q1; const long iters(25000); for (long iter = 0; iter < iters; ++iter) { q1 = gmtl::make<gmtl::Quat<double> >( gmtl::makeNormal( gmtl::AxisAngled( bokd, bokd, bokd, bokd ) ) ); bokd += q1[2]; } gmtl::Quat<float> q2; bokf = 1.0f; for (long iter = 0; iter < iters; ++iter) { q2 = gmtl::make<gmtl::Quat<float> >( gmtl::makeNormal( gmtl::AxisAnglef( bokf, bokf, bokf, bokf ) ) ); bokf -= q2[3]; } gmtl::Quat<double> q3; bokd = 1.0f; for (long iter = 0; iter < iters; ++iter) { q3 = gmtl::make<gmtl::Quat<double> >( gmtl::makeNormal( gmtl::AxisAngled( bokd, gmtl::Vec<double, 3>( bokd, bokd, bokd ) ) ) ); bokd *= q3[1] + 1.234; } gmtl::Quat<float> q4; bokf = 1.0f; for (long iter = 0; iter < iters; ++iter) { q4 = gmtl::make<gmtl::Quat<float> >( gmtl::makeNormal( gmtl::AxisAnglef( bokf, gmtl::Vec<float, 3>( bokf, bokf, bokf ) ) ) ); bokf += q4[1] + 1.234f; } gmtl::Quat<double> q5; gmtl::Vec<double, 3> v4(1,2,3), v5(1,2,3); for (long iter = 0; iter < iters; ++iter) { q5 = gmtl::makeRot<gmtl::Quat<double> >( gmtl::makeNormal(v4), gmtl::makeNormal(v5) ); v4[2] += q5[1] + 1.234; v5[0] -= q5[2] + 1.234; } gmtl::Quat<float> q6; gmtl::Vec<float, 3> v6(1,2,3), v7(1,2,3); for (long iter = 0; iter < iters; ++iter) { q6 = gmtl::makeRot<gmtl::Quat<float> >( gmtl::makeNormal(v6), gmtl::makeNormal(v7) ); v6[2] += q6[1] + 1.234f; v7[0] -= q6[2] + 1.234f; } gmtl::AxisAnglef axisAngle; for (long iter = 0; iter < iters; ++iter) { gmtl::set( axisAngle, q6 ); q6[0] = axisAngle[0] + axisAngle[1] - axisAngle[2] - axisAngle[3]; axisAngle[0] += q6[1] + 1.234f; axisAngle[1] -= q6[2] * -0.22f + 1.234f; axisAngle[2] += q6[1] + 0.1f; axisAngle[3] -= q6[2] - 0.99f; } // force intelligent compilers to do all the iterations (ie. to not optimize them out), // by using the variables computed... CPPUNIT_ASSERT( bokf != 0.998f ); CPPUNIT_ASSERT( bokd != 0.0998 ); CPPUNIT_ASSERT( q1[0] != 10000.0f ); CPPUNIT_ASSERT( q2[1] != 10000.0f ); CPPUNIT_ASSERT( q3[2] != 10000.0f ); CPPUNIT_ASSERT( q4[3] != 10000.0f ); CPPUNIT_ASSERT( q5[0] != 10000.0f ); CPPUNIT_ASSERT( q6[1] != 10000.0f ); }
void VectorTest::test_constructor(void) { message += "test_constructor\n"; std::string file_name = "../data/vector.dat"; // Default Vector<bool> v1; assert_true(v1.size() == 0, LOG); // Size Vector<bool> v2(1); assert_true(v2.size() == 1, LOG); // Size initialization Vector<bool> v3(1, false); assert_true(v3.size() == 1, LOG); assert_true(v3[0] == false, LOG); // File Vector<int> v4(3, 0); v4.save(file_name); Vector<int> w4(file_name); assert_true(w4.size() == 3, LOG); assert_true(w4 == 0, LOG); // Sequential Vector<int> v6(10, 5, 50); assert_true(v6.size() == 9, LOG); assert_true(v6[0] == 10, LOG); assert_true(v6[8] == 50, LOG); Vector<double> v7(3.0, 0.2, 3.8); assert_true(v7.size() == 5, LOG); assert_true(v7[0] == 3.0, LOG); assert_true(v7[4] == 3.8, LOG); Vector<int> v8(9, -1, 1); assert_true(v8.size() == 9, LOG); assert_true(v8[0] == 9, LOG); assert_true(v8[8] == 1, LOG); // Copy Vector<std::string> v5(1, "hello"); Vector<std::string> w5(v5); assert_true(w5.size() == 1, LOG); assert_true(w5[0] == "hello", LOG); }
void QuatGenMetricTest::testGenTimingSetRot() { double bokd = 1; float bokf = 1; gmtl::Quat<double> q1; const long iters(25000); for (long iter = 0; iter < iters; ++iter) { gmtl::set( q1, gmtl::makeNormal( gmtl::AxisAngled( bokd, bokd, bokd, bokd ) ) ); bokd += q1[2]; } gmtl::Quat<float> q2; bokf = 1.0f; for (long iter = 0; iter < iters; ++iter) { gmtl::set( q2, gmtl::makeNormal( gmtl::AxisAnglef( bokf, bokf, bokf, bokf ) ) ); bokf -= q2[3]; } gmtl::Quat<double> q3; bokd = 1.0f; for (long iter = 0; iter < iters; ++iter) { gmtl::set( q3, gmtl::makeNormal( gmtl::AxisAngled( bokd, gmtl::Vec<double, 3>( bokd, bokd, bokd ) ) ) ); bokd *= q3[1] + 1.2; } gmtl::Quat<float> q4; bokf = 1.0f; for (long iter = 0; iter < iters; ++iter) { gmtl::set( q4, gmtl::makeNormal( gmtl::AxisAnglef( bokf, gmtl::Vec<float, 3>( bokf, bokf, bokf ) ) ) ); bokf += q4[1] + 1.2f; } gmtl::Quat<double> q5; gmtl::Vec<double, 3> v4(1,2,3), v5(1,2,3); for (long iter = 0; iter < iters; ++iter) { gmtl::setRot( q5, gmtl::makeNormal( v4 ), gmtl::makeNormal( v5 ) ); v4[2] += q5[1] + 1.2; v5[0] -= q5[2] + 1.2; } gmtl::Quat<float> q6; gmtl::Vec<float, 3> v6(1,2,3), v7(1,2,3); for (long iter = 0; iter < iters; ++iter) { gmtl::setRot( q6, gmtl::makeNormal( v6 ), gmtl::makeNormal( v7 ) ); v6[2] += q6[1] + 1.2f; v7[0] -= q6[2] + 1.2f; } // force intelligent compilers to do all the iterations (ie. to not optimize them out), // by using the variables computed... CPPUNIT_ASSERT( bokf != 0.998f ); CPPUNIT_ASSERT( bokd != 0.0998 ); CPPUNIT_ASSERT( q1[0] != 10000.0f ); CPPUNIT_ASSERT( q2[1] != 10000.0f ); CPPUNIT_ASSERT( q3[2] != 10000.0f ); CPPUNIT_ASSERT( q4[3] != 10000.0f ); CPPUNIT_ASSERT( q5[0] != 10000.0f ); CPPUNIT_ASSERT( q6[1] != 10000.0f ); }
bool boost_fusion_vector_test(std::ostream &log, const char *archive_type, const char *test_name) { boost::fusion::vector<int, double> v1(33, 3.14), v2; typename archive_traits::oarchive oa; archive_traits::ocreate(oa, archive_type); oa & YAS_OBJECT_NVP("obj", ("vector", v1)); typename archive_traits::iarchive ia; archive_traits::icreate(ia, oa, archive_type); ia & YAS_OBJECT_NVP("obj", ("vector", v2)); if ( v1 != v2 ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } std::set<std::string> set; set.insert("2"); set.insert("3"); set.insert("4"); boost::fusion::vector< std::string, std::set<std::string> > v3("1", std::move(set)), v4; typename archive_traits::oarchive oa2; archive_traits::ocreate(oa2, archive_type); oa2 & YAS_OBJECT_NVP("obj", ("vector", v3)); typename archive_traits::iarchive ia2; archive_traits::icreate(ia2, oa2, archive_type); ia2 & YAS_OBJECT_NVP("obj", ("vector", v4)); if ( v3 != v4 ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } boost::fusion::vector<int, int> vv; typename archive_traits::oarchive oa3; archive_traits::ocreate(oa3, archive_type); oa3 & YAS_OBJECT_NVP("obj", ("vector", boost::fusion::make_vector(33,44))); typename archive_traits::iarchive ia3; archive_traits::icreate(ia3, oa3, archive_type); ia3 & YAS_OBJECT_NVP("obj", ("vector", vv)); if ( vv != boost::fusion::make_vector(33,44) ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } static const char str[] = "str"; boost::fusion::vector<boost::uint64_t, std::string> v5(33, str), v6, v7; typename archive_traits::oarchive oa4; archive_traits::ocreate(oa4, archive_type); oa4 & YAS_OBJECT_NVP("obj", ("vector", v5)); static const std::size_t binary_expected_size = archive_traits::oarchive_type::header_size() // archive header +sizeof(std::uint8_t) // fusion::vector size marker +sizeof(std::uint64_t) // first type +sizeof(std::uint64_t) // string size marker +std::strlen(str) // string ; static const std::size_t binary_compacted_expected_size = archive_traits::oarchive_type::header_size() // archive header +sizeof(std::uint8_t) // fusion::vector size marker +1/*len of next field*/ +1/*string length*/+std::strlen(str) // string ; static const std::size_t text_expected_size = archive_traits::oarchive_type::header_size() +1/*len of next field*/+1/*size marker*/ +1/*len of next field*/+2/*value*/ +1/*len of next field*/+1/*string len*/+3/*string*/ ; if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { if ( archive_traits::oarchive_type::compacted() ) { const size_t current_size = oa4.size(); if (current_size != binary_compacted_expected_size) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } else { const size_t current_size = oa4.size(); if (current_size != binary_expected_size) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } } if ( yas::is_text_archive<typename archive_traits::oarchive_type>::value ) { const size_t current_size = oa4.size(); if ( current_size != text_expected_size ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } typename archive_traits::iarchive ia4; archive_traits::icreate(ia4, oa4, archive_type); ia4 & YAS_OBJECT_NVP("obj", ("vector", v6)); if ( v5 != v6 ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } typename archive_traits::oarchive oa5; archive_traits::ocreate(oa5, archive_type); auto v = boost::fusion::make_vector<boost::uint64_t, std::string>(33, "str"); oa5 & YAS_OBJECT_NVP("obj", ("vector", std::move(v))); if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { if ( archive_traits::oarchive_type::compacted() ) { const size_t current_size2 = oa5.size(); if (current_size2 != binary_compacted_expected_size) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } else { const size_t current_size2 = oa5.size(); if (current_size2 != binary_expected_size) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } } if ( yas::is_text_archive<typename archive_traits::oarchive_type>::value ) { const size_t current_size = oa5.size(); if ( current_size != text_expected_size ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } typename archive_traits::iarchive ia5; archive_traits::icreate(ia5, oa5, archive_type); ia5 & YAS_OBJECT_NVP("obj", ("vector", v7)); if ( v5 != v7 ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } boost::fusion::vector<> vv0, vv1; typename archive_traits::oarchive oa6; archive_traits::ocreate(oa6, archive_type); oa6 & YAS_OBJECT_NVP("obj", ("vector", vv0)); if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { if ( oa6.size() != (archive_traits::oarchive_type::header_size()+1) ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } if ( yas::is_text_archive<typename archive_traits::oarchive_type>::value ) { if ( oa6.size() != (archive_traits::oarchive_type::header_size()+1/*len of next field*/+1/*size marker*/) ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } typename archive_traits::iarchive ia6; archive_traits::icreate(ia6, oa6, archive_type); ia6 & YAS_OBJECT_NVP("obj", ("vector", vv1)); boost::fusion::vector0<> ve0, ve1; typename archive_traits::oarchive oa7; archive_traits::ocreate(oa7, archive_type); oa7 & YAS_OBJECT_NVP("obj", ("vector", ve0)); if ( yas::is_binary_archive<typename archive_traits::oarchive_type>::value ) { if ( oa7.size() != (archive_traits::oarchive_type::header_size()+1) ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } if ( yas::is_text_archive<typename archive_traits::oarchive_type>::value ) { if ( oa7.size() != (archive_traits::oarchive_type::header_size()+1/*len of next field*/+1/*size marker*/) ) { YAS_TEST_REPORT(log, archive_type, test_name); return false; } } typename archive_traits::iarchive ia7; archive_traits::icreate(ia7, oa7, archive_type); ia7 & YAS_OBJECT_NVP("obj", ("vector", ve1)); return true; }
//Define vertices and triangles void CTitanic::init(float aScale) { this->clearMesh(); TVector3 v0(-4,2,2); this->iVertices.push_back(v0*aScale); TVector3 v1(-3,1,0); this->iVertices.push_back(v1*aScale); TVector3 v2(-3,-1,0); this->iVertices.push_back(v2*aScale); TVector3 v3(-4,-2,2); this->iVertices.push_back(v3*aScale); TVector3 v4(3,2,2); this->iVertices.push_back(v4*aScale); TVector3 v5(3,1,0); this->iVertices.push_back(v5*aScale); TVector3 v6(3,-1,0); this->iVertices.push_back(v6*aScale); TVector3 v7(3,-2,2); this->iVertices.push_back(v7*aScale); TVector3 v8(5,0,2); this->iVertices.push_back(v8*aScale); /* TTriangle t0(0,2,1); this->iTriangles.push_back(t0); TTriangle t1(0,3,2); this->iTriangles.push_back(t1); TTriangle t2(0,1,4); this->iTriangles.push_back(t2); TTriangle t3(1,5,4); this->iTriangles.push_back(t3); TTriangle t4(1,6,5); this->iTriangles.push_back(t4); TTriangle t5(1,2,6); this->iTriangles.push_back(t5); TTriangle t6(2,3,6); this->iTriangles.push_back(t6); TTriangle t7(3,7,6); this->iTriangles.push_back(t7); TTriangle t8(4,5,8); this->iTriangles.push_back(t8); TTriangle t9(5,6,8); this->iTriangles.push_back(t9); TTriangle t10(6,7,8); this->iTriangles.push_back(t10); TTriangle t11(0,4,3); this->iTriangles.push_back(t11); TTriangle t12(3,4,7); this->iTriangles.push_back(t12); TTriangle t13(4,8,7); this->iTriangles.push_back(t13); */ TTriangle t0(0,1,2); this->iTriangles.push_back(t0); TTriangle t1(0,2,3); this->iTriangles.push_back(t1); TTriangle t2(0,4,1); this->iTriangles.push_back(t2); TTriangle t3(1,4,5); this->iTriangles.push_back(t3); TTriangle t4(1,5,6); this->iTriangles.push_back(t4); TTriangle t5(1,6,2); this->iTriangles.push_back(t5); TTriangle t6(2,6,3); this->iTriangles.push_back(t6); TTriangle t7(3,6,7); this->iTriangles.push_back(t7); TTriangle t8(4,8,5); this->iTriangles.push_back(t8); TTriangle t9(5,8,6); this->iTriangles.push_back(t9); TTriangle t10(6,8,7); this->iTriangles.push_back(t10); TTriangle t11(0,3,4); this->iTriangles.push_back(t11); TTriangle t12(3,7,4); this->iTriangles.push_back(t12); TTriangle t13(4,7,8); this->iTriangles.push_back(t13); }
void tst_Q3ValueVector::acc_01() { // vectors Q3ValueVector<int> v1; QVERIFY( v1.empty() ); QVERIFY( v1.size() == 0 ); QVERIFY( v1.capacity() >= v1.size() ); Q3ValueVector<int> v2( v1 ); QVERIFY( v2.empty() ); QVERIFY( v2.size() == 0 ); QVERIFY( v2.capacity() >= v1.size() ); Q3ValueVector<int> v5( 5 ); QVERIFY( !v5.empty() ); QVERIFY( v5.size() == 5 ); QVERIFY( v5.capacity() >= 5 ); //operator= Q3ValueVector<int> v4 = v2; QVERIFY( v4.empty() ); QVERIFY( v4.size() == 0 ); QVERIFY( (int)v4.capacity() >= 0 ); // adding elements v4.push_back( 1 ); v4.push_back( 2 ); v4.push_back( 3 ); QVERIFY( !v4.empty() ); QVERIFY( v2.empty() ); // should have detached QVERIFY( v4.size() == 3 ); QVERIFY( v4.capacity() >= v4.size() ); v4.insert( v4.end(), 4 ); v4.insert( v4.begin(), 0 ); QVERIFY( !v4.empty() ); QVERIFY( v4.size() == 5 ); QVERIFY( v4.capacity() >= v4.size() ); QVERIFY( v4[0] == 0); QVERIFY( v4[1] == 1); QVERIFY( v4[2] == 2); QVERIFY( v4[3] == 3); QVERIFY( v4[4] == 4); // swap Q3ValueVector<int> tmp = v2; v2 = v4; v4 = tmp; // v4.swap( v2 ); QVERIFY( v4.empty() ); QVERIFY( !v2.empty() ); QVERIFY( v2.size() == 5 ); QVERIFY( v2.capacity() >= v2.size() ); QVERIFY( v2[0] == 0); QVERIFY( v2[1] == 1); QVERIFY( v2[2] == 2); QVERIFY( v2[3] == 3); QVERIFY( v2[4] == 4); // v2 Should contain 5 elements: 0,1,2,3,4 QVERIFY(v4.size() == 0); //Should contain no elements // element access Q3ValueVector<int> v3( 5 ); v3[0] = 0; v3[1] = 1; v3[2] = 2; v3[3] = 3; v3[4] = 4; QVERIFY( v3[0] == 0 ); QVERIFY( v3[1] == 1 ); QVERIFY( v3[2] == 2 ); QVERIFY( v3[3] == 3 ); QVERIFY( v3[4] == 4 ); bool ok = FALSE; (void) v3.at( 1000, &ok ); QVERIFY( !ok ); int& j = v3.at( 2, &ok ); QVERIFY( ok ); QVERIFY( j == 2 ); // iterators Q3ValueVector<int>::iterator it = v3.begin(); int k = 0; for ( ; k < 5; ++k, ++it ) QVERIFY( *it == k ); QVERIFY( it == v3.end() ); --it; for ( k = 4; k >= 0; --k, --it ) QVERIFY( *it == k ); QVERIFY( v3.front() == 0 ); QVERIFY( v3.back() == 4 ); // capacity stuff v3.resize( 5 ); // Should contain 5 elements: 0,1,2,3,4 QVERIFY( v3.size() == 5 ); QVERIFY( v3[0] == 0 ); QVERIFY( v3[1] == 1 ); QVERIFY( v3[2] == 2 ); QVERIFY( v3[3] == 3 ); QVERIFY( v3[4] == 4 ); v3.resize( 6 ); // Should now contain 6 elements: 0,1,2,3,4,0 QVERIFY( v3[0] == 0 ); QVERIFY( v3[1] == 1 ); QVERIFY( v3[2] == 2 ); QVERIFY( v3[3] == 3 ); QVERIFY( v3[4] == 4 ); QVERIFY( v3[5] == 0 ); v3.reserve( 1000 ); QVERIFY( v3.size() == 6 ); QVERIFY( v3[0] == 0 ); QVERIFY( v3[1] == 1 ); QVERIFY( v3[2] == 2 ); QVERIFY( v3[3] == 3 ); QVERIFY( v3[4] == 4 ); QVERIFY( v3.capacity() >= 1000 ); v3.back() = 5; // Should contain 5 elements: 0,1,2,3,4 QVERIFY( v3.back() == 5 ); QVERIFY( v3[0] == 0 ); QVERIFY( v3[1] == 1 ); QVERIFY( v3[2] == 2 ); QVERIFY( v3[3] == 3 ); QVERIFY( v3[4] == 4 ); v3.resize( 5 ); // Should contain 5 elements: 0,1,2,3,4 QVERIFY( v3.size() == 5 ); QVERIFY( v3[0] == 0 ); QVERIFY( v3[1] == 1 ); QVERIFY( v3[2] == 2 ); QVERIFY( v3[3] == 3 ); QVERIFY( v3[4] == 4 ); QVERIFY( v3.capacity() >= 1000 ); it = v3.end(); v3.erase( --it ); // Should contain 4 elements: 0,1,2,3 QVERIFY( v3.size() == 4 ); QVERIFY( v3[0] == 0 ); QVERIFY( v3[1] == 1 ); QVERIFY( v3[2] == 2 ); QVERIFY( v3[3] == 3 ); QVERIFY( v3.capacity() >= 1000 ); it = v3.begin(); Q3ValueVector<int>::iterator it2 = v3.end(); v3.erase( ++it, --it2 ); // Should contain 2 elements: 0,3 QVERIFY( v3.size() == 2 ); QVERIFY( v3[0] == 0 ); QVERIFY( v3[1] == 3 ); QVERIFY( v3.capacity() >= 1000 ); it = v3.begin(); v3.insert( ++it, 9 ); // Should contain 3 elements: 0,9,3 QVERIFY( v3.size() == 3 ); QVERIFY( v3[0] == 0 ); QVERIFY( v3[1] == 9 ); QVERIFY( v3[2] == 3 ); QVERIFY( v3.capacity() >= 1000 ); it = v3.begin(); v3.insert( ++it, 4, 4 ); // Should contain 7 elements: 0,4,4,4,4,9,3 QVERIFY( v3.size() == 7 ); QVERIFY( v3[0] == 0 ); QVERIFY( v3[1] == 4 ); QVERIFY( v3[2] == 4 ); QVERIFY( v3[3] == 4 ); QVERIFY( v3[4] == 4 ); QVERIFY( v3[5] == 9 ); QVERIFY( v3[6] == 3 ); QVERIFY( v3.capacity() >= 1000 ); it = v3.begin(); v3.insert( ++it, 2000, 2 ); // Should contain 2007 elements: 0,2,2,...2,4,4,4,4,9,3 QVERIFY( v3.size() == 2007 ); it = qFind( v3.begin(), v3.end(), 3 ); it2 = v3.end(); QVERIFY( it == --it2 ); v3.resize( 4 ); // Should contain 4 elements: 0,2,2,2 QVERIFY( v3.size() == 4 ); QVERIFY( v3[0] == 0 ); QVERIFY( v3[1] == 2 ); QVERIFY( v3[2] == 2 ); QVERIFY( v3[3] == 2 ); QVERIFY( v3.capacity() >= 2007 ); it = v3.begin(); v3.insert( ++it, 2000, 2 ); v3.push_back( 9 ); v3.push_back( 3 ); it = v3.begin(); it2 = v3.end(); v3.erase( ++it, ----it2 ); // Should contain 3 elements: 0,9,3 QVERIFY( v3.size() == 3 ); v3.pop_back(); // Should contain 2 elements: 0,9 QVERIFY( v3.size() == 2 ); /* // instantiate other member functions Q3ValueVector<int>::const_iterator cit = v3.begin(); cit = v3.end(); Q3ValueVector<int>::size_type max_size = v3.max_size(); std::cout << "max size of vector:" << max_size << std::endl; const int& ci = v3.at( 1 ); const int& ci2 = v3[1]; const int& ci3 = v3.front(); const int& ci4 = v3.back(); v3.clear(); QStringList l1, l2; l1 << "Weis" << "Ettrich" << "Arnt" << "Sue"; l2 << "Torben" << "Matthias"; qCopy( l2.begin(), l2.end(), l1.begin() ); Q3ValueVector<QString> v( l1.size(), "Dave" ); qCopy( l2.begin(), l2.end(), v.begin() ); std::for_each( v.begin(), v.end(), qDebug ); std::vector<int> stdvec( 5, 100 ); Q3ValueVector<int> cvec( stdvec ); std::cout << "Should contain 5 elements: 100,100,100,100,100" << std::endl; print( cvec ); Q3ValueVector<int> cvec2 = stdvec; std::cout << "Should contain 5 elements: 100,100,100,100,100" << std::endl; print( cvec2 ); QFile f( "file.dta" ); f.open( QIODevice::WriteOnly ); QDataStream s( &f ); s << cvec2; f.close(); f.open( QIODevice::ReadOnly ); Q3ValueVector<int> in; s >> in; std::cout << "Should contain 5 elements: 100,100,100,100,100" << std::endl; print( in ); */ }
double CalcTetBadnessGrad (const Point3d & p1, const Point3d & p2, const Point3d & p3, const Point3d & p4, double h, int pi, Vec<3> & grad) { double vol, l, ll, lll; double err; const Point3d *pp1, *pp2, *pp3, *pp4; pp1 = &p1; pp2 = &p2; pp3 = &p3; pp4 = &p4; switch (pi) { case 2: { swap (pp1, pp2); swap (pp3, pp4); break; } case 3: { swap (pp1, pp3); swap (pp2, pp4); break; } case 4: { swap (pp1, pp4); swap (pp3, pp2); break; } } Vec3d v1 (*pp1, *pp2); Vec3d v2 (*pp1, *pp3); Vec3d v3 (*pp1, *pp4); Vec3d v4 (*pp2, *pp3); Vec3d v5 (*pp2, *pp4); Vec3d v6 (*pp3, *pp4); vol = -Determinant (v1, v2, v3) / 6; Vec3d gradvol; Cross (v5, v4, gradvol); gradvol *= (-1.0/6.0); double ll1 = v1.Length2(); double ll2 = v2.Length2(); double ll3 = v3.Length2(); double ll4 = v4.Length2(); double ll5 = v5.Length2(); double ll6 = v6.Length2(); ll = ll1 + ll2 + ll3 + ll4 + ll5 + ll6; l = sqrt (ll); lll = l * ll; if (vol <= 1e-24 * lll) { grad = Vec3d (0, 0, 0); return 1e24; } Vec3d gradll1 (*pp2, *pp1); Vec3d gradll2 (*pp3, *pp1); Vec3d gradll3 (*pp4, *pp1); gradll1 *= 2; gradll2 *= 2; gradll3 *= 2; Vec3d gradll (gradll1); gradll += gradll2; gradll += gradll3; /* Vec3d gradll; gradll = v1+v2+v3; gradll *= -2; */ err = 0.0080187537 * lll / vol; gradll *= (0.0080187537 * 1.5 * l / vol); Vec3d graderr(gradll); gradvol *= ( -0.0080187537 * lll / (vol * vol) ); graderr += gradvol; if (h > 0) { /* Vec3d gradll1 (*pp2, *pp1); Vec3d gradll2 (*pp3, *pp1); Vec3d gradll3 (*pp4, *pp1); gradll1 *= 2; gradll2 *= 2; gradll3 *= 2; */ err += ll / (h*h) + h*h * ( 1 / ll1 + 1 / ll2 + 1 / ll3 + 1 / ll4 + 1 / ll5 + 1 / ll6 ) - 12; graderr += (1/(h*h) - h*h/(ll1*ll1)) * gradll1; graderr += (1/(h*h) - h*h/(ll2*ll2)) * gradll2; graderr += (1/(h*h) - h*h/(ll3*ll3)) * gradll3; cout << "?"; } double errpow; if (teterrpow == 2) { errpow = err*err; grad = (2 * err) * graderr; } else { errpow = pow (err, teterrpow); grad = (teterrpow * errpow / err) * graderr; } return errpow; }
void Scene::init(){ primitives = new Primitive*[25]; nrOfPrimitives = 0; //wall at0,0,1 Vec3 v121( 0,0, 1 ); primitives[nrOfPrimitives] = new PlanePrim( v121, -13.0f ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 1 ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.0f ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f); Color c121( 1,1,1 ); primitives[nrOfPrimitives++]->getMaterial()->setColor(c121); //wall at 0 0 -1 Vec3 v12( 0,0, -1 ); primitives[nrOfPrimitives] = new PlanePrim( v12, 13.0f ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 1.0f ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.0f ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f); Color c12( 0.3f,0.3f,0.7f ); primitives[nrOfPrimitives++]->getMaterial()->setColor(c12); //- //the ground Vec3 v1( 0,1, 0 ); primitives[nrOfPrimitives] = new CheckerBoard( v1, 3.4f ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 0.7f ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 1.0f ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(0.0f); Color c1( 0.3f, 0.3f, 0.7f ); primitives[nrOfPrimitives++]->getMaterial()->setColor(c1); // // 0 -1 0 Vec3 v13( 0,-1, 0 ); primitives[nrOfPrimitives] = new PlanePrim( v13, -3.4f ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 1 ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 1.0f ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f - primitives[nrOfPrimitives]->getMaterial()->getDiffuse()); Color c13( 1,1,1 ); primitives[nrOfPrimitives++]->getMaterial()->setColor(c13); // //middle sphere Vec3 v2( 0, 1, 8 ); primitives[nrOfPrimitives] = new Sphere( v2, 1.0f ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 1 ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.2 ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f - primitives[nrOfPrimitives]->getMaterial()->getDiffuse()); Color c2( 1,1,1); primitives[nrOfPrimitives++]->getMaterial()->setColor( c2 ); //- //left sphere Vec3 v3( -5.5f, -0.5, 7 ); Color c3( 0.7f, 0.7f, 0 ); primitives[nrOfPrimitives] = new Sphere( v3, 2 ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 0.6f ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.9f ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f - primitives[nrOfPrimitives]->getMaterial()->getDiffuse()); primitives[nrOfPrimitives++]->getMaterial()->setColor( c3 ); //- //right sphere Vec3 v31( 5.5f, -0.5, 7 ); Color c31( 0.7f, 0.0f, 0 ); primitives[nrOfPrimitives] = new Sphere( v31, 2 ); primitives[nrOfPrimitives]->getMaterial()->setReflection( 0.6f ); primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.9f ); primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f); primitives[nrOfPrimitives++]->getMaterial()->setColor( c31 ); //- //a light Vec3 v4( 3, 2.5f, 3 ); Color c4(0.7f,0.7f,0.7f); primitives[nrOfPrimitives] = new Sphere( v4, 0.5f ); primitives[nrOfPrimitives]->isLight = true; primitives[nrOfPrimitives++]->getMaterial()->setColor( c4 ); //-- //another light Vec3 v5( 0, 5, 10 ); Color c5( 0.6f, 0.6f, 0.8f ); primitives[nrOfPrimitives] = new Sphere( v5, 0.5f ); primitives[nrOfPrimitives]->isLight = true; primitives[nrOfPrimitives++]->getMaterial()->setColor( c5 ); //-- }
void CIcosahedron::init( float s ){ this->clearMesh(); float p = ((1.0 + sqrt(5.0))/2.0)*s; TVector3 v0(s,0.0,p); this->iVertices.push_back(v0); TVector3 v1(-s,0.0,p); this->iVertices.push_back(v1); TVector3 v2(s,0.0,-p); this->iVertices.push_back(v2); TVector3 v3(-s,0.0,-p); this->iVertices.push_back(v3); TVector3 v4(0.0,p,s); this->iVertices.push_back(v4); TVector3 v5(0,-p,s); this->iVertices.push_back(v5); TVector3 v6(0,p,-s); this->iVertices.push_back(v6); TVector3 v7(0.0,-p,-s); this->iVertices.push_back(v7); TVector3 v8(p,s,0.0); this->iVertices.push_back(v8); TVector3 v9(-p,s,0.0); this->iVertices.push_back(v9); TVector3 v10(p,-s,0.0); this->iVertices.push_back(v10); TVector3 v11(-p,-s,0.0); this->iVertices.push_back(v11); TTriangle t0(0,4,1); this->iTriangles.push_back(t0); TTriangle t1(0,1,5); this->iTriangles.push_back(t1); TTriangle t2(0,5,10); this->iTriangles.push_back(t2); TTriangle t3(0,10,8); this->iTriangles.push_back(t3); TTriangle t4(0,8,4); this->iTriangles.push_back(t4); TTriangle t5(4,8,6); this->iTriangles.push_back(t5); TTriangle t6(4,6,9); this->iTriangles.push_back(t6); TTriangle t7(4,9,1); this->iTriangles.push_back(t7); TTriangle t8(1,9,11); this->iTriangles.push_back(t8); TTriangle t9(1,11,5); this->iTriangles.push_back(t9); TTriangle t10(2,7,3); this->iTriangles.push_back(t10); TTriangle t11(2,3,6); this->iTriangles.push_back(t11); TTriangle t12(2,6,8); this->iTriangles.push_back(t12); TTriangle t13(2,8,10); this->iTriangles.push_back(t13); TTriangle t14(2,10,7); this->iTriangles.push_back(t14); TTriangle t15(7,10,5); this->iTriangles.push_back(t15); TTriangle t16(7,5,11); this->iTriangles.push_back(t16); TTriangle t17(7,11,3); this->iTriangles.push_back(t17); TTriangle t18(3,11,9); this->iTriangles.push_back(t18); TTriangle t19(3,9,6); this->iTriangles.push_back(t19); }
int main(int argc, char **argv) { OpenMeshExtended mesh; typedef typename mesh_traits<OpenMeshExtended>::vertex_descriptor vd; //MyMesh mesh; OpenMeshXTraits::vertex_descriptor vhandle[8]; vhandle[0] = mesh.add_vertex(OpenMeshExtended::Point(-1, -1, 1)); vhandle[1] = mesh.add_vertex(OpenMeshExtended::Point( 1, -1, 1)); vhandle[2] = mesh.add_vertex(OpenMeshExtended::Point( 1, 1, 1)); vhandle[3] = mesh.add_vertex(OpenMeshExtended::Point(-1, 1, 1)); vhandle[4] = mesh.add_vertex(OpenMeshExtended::Point(-1, -1, -1)); vhandle[5] = mesh.add_vertex(OpenMeshExtended::Point( 1, -1, -1)); vhandle[6] = mesh.add_vertex(OpenMeshExtended::Point( 1, 1, -1)); vhandle[7] = mesh.add_vertex(OpenMeshExtended::Point(-1, 1, -1)); /* testujem iteratory */ auto test_vv_iter_pair = OpenMeshXTraits::get_adjacent_vertices(mesh, vhandle[0]); std::cout << "pre izolovany vrchol vyhodi rovny iterator:" << (test_vv_iter_pair.first == test_vv_iter_pair.second) << " great!" << std::endl; /*# testujem iteratory*/ std::vector<OpenMeshXTraits::vertex_descriptor> face_vhandles; face_vhandles.clear(); face_vhandles.push_back(vhandle[0]); face_vhandles.push_back(vhandle[1]); face_vhandles.push_back(vhandle[2]); face_vhandles.push_back(vhandle[3]); /*0 0 1*/ /* face_vhandles.clear(); face_vhandles.push_back(vhandle[3]); face_vhandles.push_back(vhandle[2]); face_vhandles.push_back(vhandle[1]); face_vhandles.push_back(vhandle[0]); */ /*0 0 -1*/ OpenMesh::PolyMesh_ArrayKernelT<>::FaceHandle omx_face = mesh.add_face(face_vhandles); OpenMeshExtended::Normal normal = mesh.calc_face_normal(omx_face); std::cout << "normala:" << normal << std::endl; flip_normals<OpenMeshExtended, advanced_mesh_traits<OpenMeshExtended>>(mesh); auto old_face_pair = mesh_traits<OpenMeshExtended>::get_all_faces(mesh); for (auto i = old_face_pair.first; i != old_face_pair.second; ++i) { auto old_face = *i; OpenMeshExtended::Normal n = mesh.calc_face_normal(old_face); std::cout << "norm:" << n << std::endl; } triangulate<OpenMeshExtended, advanced_mesh_traits<OpenMeshExtended>>(mesh); std::cout << "pocet je " << compute_components<OpenMeshExtended, OpenMeshXTraits>(mesh) << std::endl; OpenMeshXTraits::face_descriptor fh = *mesh.faces_begin(); for ( auto fvi = mesh.fv_begin(fh); fvi < mesh.fv_end(fh); ++fvi) { std::cout << "h" << std::endl; } for (auto e_it = mesh.edges_begin(); e_it != mesh.edges_end(); ++e_it) { std::cout << "joe" << e_it->idx() << std::endl; } boost::adjacency_matrix<boost::directedS> a(N); add_edge(A, B, a); my_mesh G; my_mesh::vertex v1(1); my_mesh::vertex v2(2); my_mesh::vertex v3(3); my_mesh::vertex v4(4); my_mesh::vertex v5(5); my_mesh::vertex v6(6); my_mesh::vertex v7(7); my_mesh::vertex v8(8); /* 2 testujem iteratory */ auto test_vv_iter_pair2 = my_mesh_traits::get_adjacent_vertices(G, &v1); std::cout << "2: pre izolovany vrchol vyhodi rovny iterator:" << (test_vv_iter_pair2.first == test_vv_iter_pair2.second) << " great!" << std::endl; /*# 2 testujem iteratory*/ my_mesh_traits::add_vertex(&v1, &G); my_mesh_traits::add_vertex(&v2, &G); my_mesh_traits::add_vertex(&v3, &G); my_mesh_traits::add_vertex(&v4, &G); my_mesh_traits::add_vertex(&v5, &G); my_mesh_traits::add_vertex(&v6, &G); my_mesh_traits::add_vertex(&v7, &G); my_mesh_traits::add_vertex(&v8, &G); my_mesh_traits::create_face(&v1, &v2, &v3, &G); my_mesh_traits::create_face(&v2, &v3, &v4, &G); my_mesh_traits::create_face(&v6, &v7, &v8, &G); std::cout << std::endl; auto my_pair = my_mesh_traits::get_all_vertices(G); for (auto i = my_pair.first; i != my_pair.second; ++i) { std::cout << (*i)->get_id() << ", "; } std::cout << std::endl; auto my_pair_edges = my_mesh_traits::get_all_edges(G); for (auto i = my_pair_edges.first; i != my_pair_edges.second; ++i) { std::cout << ((*i)->getVertices().first ? (*i)->getVertices().first->get_id() : 0) << "-" ; std::cout << ((*i)->getVertices().second ? (*i)->getVertices().second->get_id() : 0) << ","; } std::cout << std::endl; std::cout << G.isTriangle() << std::endl; std::cout << "joe more!!!!"; auto my_pair_vv = v1.get_adjacent_vertices();// get_adjacent_vertices(G, &v1); for (auto i = my_pair_vv.first; i != my_pair_vv.second; ++i) { std::cout << (*i)->get_id() << ","; } std::cout << std::endl; std::cout << "pocet je: " << compute_components<my_mesh, my_mesh_traits>(G) << std::endl; std::cout << "norma: c++0x" << std::endl; //M4D::Imaging::AImage::Ptr image = M4D::Imaging::ImageFactory::LoadDumpedImage( path ); return 0; }
void test_n_voronoi(void) { std::vector<Vector> pos; real L = 32; Vector a, b, c, d; a.x = 1.; a.y = 2.; b.x = 2.; b.y = 2.; c.x = 2.; c.y = 0.; d.x = 4.; d.y = 4.; pos = {a, b, c, d}; MATRIX n(4, 4); n.Zero(); calculate_n_voronoi(n, pos, L); MATRIX m(4, 4); /* 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 */ m.Set(0, 0, 0); m.Set(0, 1, 1); m.Set(0, 2, 1); m.Set(0, 3, 1); m.Set(1, 0, 1); m.Set(1, 1, 0); m.Set(1, 2, 1); m.Set(1, 3, 1); m.Set(2, 0, 1); m.Set(2, 1, 1); m.Set(2, 2, 0); m.Set(2, 3, 1); m.Set(3, 0, 1); m.Set(3, 1, 1); m.Set(3, 2, 1); m.Set(3, 3, 0); assert(n == m); /*9 particles Voronoi*/ MATRIX n2(9, 9); n2.Zero(); Vector v1(10,30), v2(20,30), v3(30,30), v4(10,20), v5(20,20), v6(30,20), v7(10,10), v8(20,10), v9(30,10); pos = {v1, v2, v3, v4, v5, v6, v7, v8, v9}; calculate_n_voronoi(n2, pos, L); MATRIX m2(9, 9); /* 0 1 1 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 0 0 1 0 0 1 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 0 1 0 0 0 1 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 1 1 0 */ m2.Set(0, 0, 0);m2.Set(0, 1, 1);m2.Set(0, 2, 1);m2.Set(0, 3, 1);m2.Set(0, 4, 0);m2.Set(0, 5, 0);m2.Set(0, 6, 1);m2.Set(0, 7, 0);m2.Set(0, 8, 0); m2.Set(1, 0, 1);m2.Set(1, 1, 0);m2.Set(1, 2, 1);m2.Set(1, 3, 0);m2.Set(1, 4, 1);m2.Set(1, 5, 0);m2.Set(1, 6, 0);m2.Set(1, 7, 1);m2.Set(1, 8, 0); m2.Set(2, 0, 1);m2.Set(2, 1, 1);m2.Set(2, 2, 0);m2.Set(2, 3, 0);m2.Set(2, 4, 0);m2.Set(2, 5, 1);m2.Set(2, 6, 0);m2.Set(2, 7, 0);m2.Set(2, 8, 1); m2.Set(3, 0, 1);m2.Set(3, 1, 0);m2.Set(3, 2, 0);m2.Set(3, 3, 0);m2.Set(3, 4, 1);m2.Set(3, 5, 1);m2.Set(3, 6, 1);m2.Set(3, 7, 0);m2.Set(3, 8, 0); m2.Set(4, 0, 0);m2.Set(4, 1, 1);m2.Set(4, 2, 0);m2.Set(4, 3, 1);m2.Set(4, 4, 0);m2.Set(4, 5, 1);m2.Set(4, 6, 0);m2.Set(4, 7, 1);m2.Set(4, 8, 0); m2.Set(5, 0, 0);m2.Set(5, 1, 0);m2.Set(5, 2, 1);m2.Set(5, 3, 1);m2.Set(5, 4, 1);m2.Set(5, 5, 0);m2.Set(5, 6, 0);m2.Set(5, 7, 0);m2.Set(5, 8, 1); m2.Set(6, 0, 1);m2.Set(6, 1, 0);m2.Set(6, 2, 0);m2.Set(6, 3, 1);m2.Set(6, 4, 0);m2.Set(6, 5, 0);m2.Set(6, 6, 0);m2.Set(6, 7, 1);m2.Set(6, 8, 1); m2.Set(7, 0, 0);m2.Set(7, 1, 1);m2.Set(7, 2, 0);m2.Set(7, 3, 0);m2.Set(7, 4, 1);m2.Set(7, 5, 0);m2.Set(7, 6, 1);m2.Set(7, 7, 0);m2.Set(7, 8, 1); m2.Set(8, 0, 0);m2.Set(8, 1, 0);m2.Set(8, 2, 1);m2.Set(8, 3, 0);m2.Set(8, 4, 0);m2.Set(8, 5, 1);m2.Set(8, 6, 1);m2.Set(8, 7, 1);m2.Set(8, 8, 0); assert(n2 == m2); }