예제 #1
0
	//生成6个面 clip 是 wvp matrix
	/////////////////////////
	void Frustum::Construct(Matrix4x4 & clip)
	{
		Vector4  & column1(clip.GetColumn(0));
		Vector4  & column2(clip.GetColumn(1));
		Vector4  & column3(clip.GetColumn(2));
		Vector4  & column4(clip.GetColumn(3));
		//根据平面方程
		//Near:    (P0,P4,P5)     n=(0,0,-1),d=0              0x+0y-1z+0=0     
		m_planes[0] = column4 - column3;//这个函数规格化平面方程,使|a,b,c| == 1。
		//Far:      (P2,P6,P7)     n=(0,0,1),d=-1              0x+0y+1z-1=0  
		m_planes[1] = column4 + column3;
		//Left:     (P0,P3,P7)     n=(-1,0,0),d=-1          -1x+0y+0z-1=0     
		m_planes[2] = column4 - column1;
		//Right:    (P1,P5,P6)     n=(1,0,0),d=-1              1x+0y+0z-1=0    
		m_planes[3] = column4 + column1;
		//Top:      (P4,P7,P6)     n=(0,1,0),d=-1              0x+1y+0z-1=0   
		m_planes[4] = column4 + column2;
		//Bottom:   (P0,P1,P2)     n=(0,-1,0),d=-1            0x-1y+0z-1=0     
		m_planes[5] = column4 - column2;
		//归一
		for(int i=0; i<6; i++)
		{
			m_planes[i].Normalize();
		}
		//做个标记???
		//  build a bit-field that will tell us the indices for the nearest and farthest vertices from each plane...
		for(int i=0; i<6; i++)
		{
			m_flag[i]  = ((m_planes[i].x<0) ? 1 : 0) | ((m_planes[i].y<0) ? 2 : 0) | ((m_planes[i].z) ? 4 : 0);
		}

	}
예제 #2
0
TEST_F(TupleSchemaTests, TupleSchemaTest) {
  std::vector<catalog::Column> columns;

  catalog::Column column1(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "A", true);
  catalog::Column column2(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "B", true);
  catalog::Column column3(VALUE_TYPE_TINYINT, GetTypeSize(VALUE_TYPE_TINYINT),
                          "C", true);
  catalog::Column column4(VALUE_TYPE_VARCHAR, 24, "D", false);

  columns.push_back(column1);
  columns.push_back(column2);
  columns.push_back(column3);
  columns.push_back(column4);

  catalog::Schema schema1(columns);
  LOG_INFO("%s", schema1.GetInfo().c_str());

  catalog::Schema schema2(columns);
  EXPECT_EQ(schema1, schema2);

  std::vector<oid_t> subset{0, 2};
  catalog::Schema *schema3 = catalog::Schema::CopySchema(&schema2, subset);
  LOG_INFO("%s", schema3->GetInfo().c_str());

  EXPECT_NE(schema1, (*schema3));

  delete schema3;
}
예제 #3
0
TEST_F(TupleTests, VarcharTest) {
  std::vector<catalog::Column> columns;

  catalog::Column column1(common::Type::INTEGER, common::Type::GetTypeSize(common::Type::INTEGER),
                          "A", true);
  catalog::Column column2(common::Type::INTEGER, common::Type::GetTypeSize(common::Type::INTEGER),
                          "B", true);
  catalog::Column column3(common::Type::TINYINT, common::Type::GetTypeSize(common::Type::TINYINT),
                          "C", true);
  catalog::Column column4(common::Type::VARCHAR, 25, "D", false);

  columns.push_back(column1);
  columns.push_back(column2);
  columns.push_back(column3);
  columns.push_back(column4);

  catalog::Schema *schema(new catalog::Schema(columns));

  storage::Tuple *tuple(new storage::Tuple(schema, true));
  auto pool = TestingHarness::GetInstance().GetTestingPool();

  tuple->SetValue(0, common::ValueFactory::GetIntegerValue(23), pool);
  tuple->SetValue(1, common::ValueFactory::GetIntegerValue(45), pool);
  tuple->SetValue(2, common::ValueFactory::GetTinyIntValue(1), pool);

  common::Value val = common::ValueFactory::GetVarcharValue("hello hello world", pool);
  tuple->SetValue(3, val, pool);
  common::Value value3 = (tuple->GetValue(3));
  common::Value cmp = (value3.CompareEquals(val));
  EXPECT_TRUE(cmp.IsTrue());

  LOG_INFO("%s", tuple->GetInfo().c_str());

  auto val2 = common::ValueFactory::GetVarcharValue("hi joy !", pool);
  tuple->SetValue(3, val2, pool);
  value3 = (tuple->GetValue(3));
  cmp = (value3.CompareNotEquals(val));
  EXPECT_TRUE(cmp.IsTrue());
  cmp = (value3.CompareEquals(val2));
  EXPECT_TRUE(cmp.IsTrue());

  LOG_INFO("%s", tuple->GetInfo().c_str());

  delete tuple;
  delete schema;
}
예제 #4
0
TEST_F(TupleTests, BasicTest) {
  std::vector<catalog::Column> columns;

  catalog::Column column1(common::Type::INTEGER, common::Type::GetTypeSize(common::Type::INTEGER),
                          "A", true);
  catalog::Column column2(common::Type::INTEGER, common::Type::GetTypeSize(common::Type::INTEGER),
                          "B", true);
  catalog::Column column3(common::Type::TINYINT, common::Type::GetTypeSize(common::Type::TINYINT),
                          "C", true);

  columns.push_back(column1);
  columns.push_back(column2);
  columns.push_back(column3);

  catalog::Schema *schema(new catalog::Schema(columns));

  storage::Tuple *tuple(new storage::Tuple(schema, true));
  auto pool = TestingHarness::GetInstance().GetTestingPool();

  tuple->SetValue(0, common::ValueFactory::GetIntegerValue(23), pool);
  tuple->SetValue(1, common::ValueFactory::GetIntegerValue(45), pool);
  tuple->SetValue(2, common::ValueFactory::GetTinyIntValue(1), pool);

  common::Value val0 = (tuple->GetValue(0));
  common::Value val1 = (tuple->GetValue(1));
  common::Value val2 = (tuple->GetValue(2));

  common::Value cmp = (val0.CompareEquals(
      common::ValueFactory::GetIntegerValue(23)));
  EXPECT_TRUE(cmp.IsTrue());
  cmp = (val1.CompareEquals(common::ValueFactory::GetIntegerValue(45)));
  EXPECT_TRUE(cmp.IsTrue());
  cmp = (val2.CompareEquals(common::ValueFactory::GetIntegerValue(1)));
  EXPECT_TRUE(cmp.IsTrue());

  tuple->SetValue(2, common::ValueFactory::GetTinyIntValue(2), pool);

  val2 = (tuple->GetValue(2));
  cmp = (val2.CompareEquals(common::ValueFactory::GetIntegerValue(2)));
  EXPECT_TRUE(cmp.IsTrue());

  LOG_INFO("%s", tuple->GetInfo().c_str());

  delete tuple;
  delete schema;
}
예제 #5
0
TEST_F(TupleSchemaTests, ColumnInfoTest) {
  std::vector<catalog::Column> columns;

  catalog::Column column1(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "A", true);
  catalog::Column column2(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "B", true);
  catalog::Column column3(VALUE_TYPE_TINYINT, GetTypeSize(VALUE_TYPE_TINYINT),
                          "C", true);

  columns.push_back(column1);
  columns.push_back(column2);
  columns.push_back(column3);

  EXPECT_EQ(column1, column2);
  EXPECT_NE(column1, column3);
}
index::Index *BuildIndex(const bool unique_keys, const IndexType index_type) {
  // Build tuple and key schema
  std::vector<std::vector<std::string>> column_names;
  std::vector<catalog::Column> columns;
  std::vector<catalog::Schema *> schemas;

  catalog::Column column1(type::Type::INTEGER,
                          type::Type::GetTypeSize(type::Type::INTEGER), "A",
                          true);
  catalog::Column column2(type::Type::INTEGER,
                          type::Type::GetTypeSize(type::Type::INTEGER), "B",
                          true);
  catalog::Column column3(type::Type::DECIMAL,
                          type::Type::GetTypeSize(type::Type::DECIMAL), "C",
                          true);
  catalog::Column column4(type::Type::INTEGER,
                          type::Type::GetTypeSize(type::Type::INTEGER), "D",
                          true);

  columns.push_back(column1);
  columns.push_back(column2);

  // INDEX KEY SCHEMA -- {column1, column2}
  std::vector<oid_t> key_attrs = {0, 1};
  key_schema = new catalog::Schema(columns);
  key_schema->SetIndexedColumns(key_attrs);

  columns.push_back(column3);
  columns.push_back(column4);

  // TABLE SCHEMA -- {column1, column2, column3, column4}
  tuple_schema = new catalog::Schema(columns);

  // Build index metadata
  index::IndexMetadata *index_metadata = new index::IndexMetadata(
      "test_index", 125, INVALID_OID, INVALID_OID, index_type,
      IndexConstraintType::DEFAULT, tuple_schema, key_schema, key_attrs,
      unique_keys);

  // Build index
  index::Index *index = index::IndexFactory::GetIndex(index_metadata);
  EXPECT_TRUE(index != NULL);

  return index;
}
예제 #7
0
index::Index *BuildIndex() {
  // Build tuple and key schema
  std::vector<std::vector<std::string>> column_names;
  std::vector<catalog::Column> columns;
  std::vector<catalog::Schema *> schemas;
  IndexType index_type = INDEX_TYPE_BTREE;
  // TODO: Uncomment the line below
  index_type = INDEX_TYPE_BWTREE;

  catalog::Column column1(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "A", true);
  catalog::Column column2(VALUE_TYPE_VARCHAR, 1024, "B", true);
  catalog::Column column3(VALUE_TYPE_DOUBLE, GetTypeSize(VALUE_TYPE_DOUBLE),
                          "C", true);
  catalog::Column column4(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "D", true);

  columns.push_back(column1);
  columns.push_back(column2);

  // INDEX KEY SCHEMA -- {column1, column2}
  key_schema = new catalog::Schema(columns);
  key_schema->SetIndexedColumns({0, 1});

  columns.push_back(column3);
  columns.push_back(column4);

  // TABLE SCHEMA -- {column1, column2, column3, column4}
  tuple_schema = new catalog::Schema(columns);

  // Build index metadata
  const bool unique_keys = false;

  index::IndexMetadata *index_metadata = new index::IndexMetadata(
      "test_index", 125, index_type, INDEX_CONSTRAINT_TYPE_DEFAULT,
      tuple_schema, key_schema, unique_keys);

  // Build index
  index::Index *index = index::IndexFactory::GetInstance(index_metadata);
  EXPECT_TRUE(index != NULL);

  return index;
}
예제 #8
0
TEST_F(TupleTests, VarcharTest) {
  std::vector<catalog::Column> columns;

  catalog::Column column1(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "A", true);
  catalog::Column column2(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "B", true);
  catalog::Column column3(VALUE_TYPE_TINYINT, GetTypeSize(VALUE_TYPE_TINYINT),
                          "C", true);
  catalog::Column column4(VALUE_TYPE_VARCHAR, 25, "D", false);

  columns.push_back(column1);
  columns.push_back(column2);
  columns.push_back(column3);
  columns.push_back(column4);

  catalog::Schema *schema(new catalog::Schema(columns));

  storage::Tuple *tuple(new storage::Tuple(schema, true));
  auto pool = TestingHarness::GetInstance().GetTestingPool();

  tuple->SetValue(0, ValueFactory::GetIntegerValue(23), pool);
  tuple->SetValue(1, ValueFactory::GetIntegerValue(45), pool);
  tuple->SetValue(2, ValueFactory::GetTinyIntValue(1), pool);

  Value val = ValueFactory::GetStringValue("hello hello world", pool);
  tuple->SetValue(3, val, pool);
  EXPECT_EQ(tuple->GetValue(3), val);

  LOG_INFO("%s", tuple->GetInfo().c_str());

  Value val2 = ValueFactory::GetStringValue("hi joy !", pool);
  tuple->SetValue(3, val2, pool);

  EXPECT_NE(tuple->GetValue(3), val);
  EXPECT_EQ(tuple->GetValue(3), val2);

  LOG_INFO("%s", tuple->GetInfo().c_str());

  delete tuple;
  delete schema;
}
예제 #9
0
Frustum::Frustum( const SMatrix4x4& matrix )
{
	//  build a view frustum based on the current view & projection matrices...
	SVector4 column4( matrix._14, matrix._24, matrix._34, matrix._44 );
	SVector4 column1( matrix._11, matrix._21, matrix._31, matrix._41 );
	SVector4 column2( matrix._12, matrix._22, matrix._32, matrix._42 );
	SVector4 column3( matrix._13, matrix._23, matrix._33, matrix._43 );

	SVector4 planes[6];
	planes[0] = column4 - column1;  // left
	planes[1] = column4 + column1;  // right
	planes[2] = column4 - column2;  // bottom
	planes[3] = column4 + column2;  // top
	planes[4] = column4 - column3;  // near
	planes[5] = column4 + column3;  // far

	int p;

	for (p=0; p<6; p++)  // normalize the planes
	{
		float dot = planes[p].x*planes[p].x + planes[p].y*planes[p].y + planes[p].z*planes[p].z;
		dot = 1.0f / sqrtf(dot);
		planes[p] = planes[p] * dot;
	}

	for (p=0; p<6; p++)
		camPlanes[p] = SPlane( planes[p].x, planes[p].y, planes[p].z, planes[p].w );

	//  build a bit-field that will tell us the indices for the nearest and farthest vertices from each plane...
	for (int i=0; i<6; i++)
		nVertexLUT[i] = ((planes[i].x<0.f)?1:0) | ((planes[i].y<0.f)?2:0) | ((planes[i].z<0.f)?4:0);

	for( int i=0; i<8; ++i ) // compute extrema
	{
		const SPlane& p0 = (i&1)?camPlanes[4] : camPlanes[5];
		const SPlane& p1 = (i&2)?camPlanes[3] : camPlanes[2];
		const SPlane& p2 = (i&4)?camPlanes[0] : camPlanes[1];

		PlaneIntersection( &pntList[i], p0, p1, p2 );
	}
}
예제 #10
0
TEST_F(TupleTests, BasicTest) {
  std::vector<catalog::Column> columns;

  catalog::Column column1(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "A", true);
  catalog::Column column2(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "B", true);
  catalog::Column column3(VALUE_TYPE_TINYINT, GetTypeSize(VALUE_TYPE_TINYINT),
                          "C", true);

  columns.push_back(column1);
  columns.push_back(column2);
  columns.push_back(column3);

  catalog::Schema *schema(new catalog::Schema(columns));

  storage::Tuple *tuple(new storage::Tuple(schema, true));
  auto pool = TestingHarness::GetInstance().GetTestingPool();

  tuple->SetValue(0, ValueFactory::GetIntegerValue(23), pool);
  tuple->SetValue(1, ValueFactory::GetIntegerValue(45), pool);
  tuple->SetValue(2, ValueFactory::GetTinyIntValue(1), pool);

  EXPECT_EQ(tuple->GetValue(0), ValueFactory::GetIntegerValue(23));
  EXPECT_EQ(tuple->GetValue(1), ValueFactory::GetIntegerValue(45));
  EXPECT_EQ(tuple->GetValue(2), ValueFactory::GetTinyIntValue(1));

  tuple->SetValue(2, ValueFactory::GetTinyIntValue(2), pool);

  EXPECT_EQ(tuple->GetValue(2), ValueFactory::GetTinyIntValue(2));

  LOG_INFO("%s", tuple->GetInfo().c_str());

  delete tuple;
  delete schema;
}