Ejemplo n.º 1
0
TEST(Mat5StaticFunTest, IdentityTest)
{
    Mat5 to_test = Mat5::Identity();

    for (int i = 0; i < to_test.getRows() * to_test.getCols(); ++i)
    {
        if (i / to_test.getRows() == i % to_test.getCols())
        {
            EXPECT_EQ(1, to_test(i / to_test.getRows(), i % to_test.getCols()));
        }
        else
        {
            EXPECT_EQ(0, to_test(i / to_test.getRows(), i % to_test.getCols()));
        }
    }
}
Ejemplo n.º 2
0
TEST(Mat5StaticFunTest, ZeroTest)
{
    Mat5 to_test = Mat5::Zero();

    for (int i = 0; i < to_test.getRows() * to_test.getCols(); ++i)
    {
        EXPECT_EQ(0, to_test(i / to_test.getRows(), i % to_test.getCols()));
    }
}
Ejemplo n.º 3
0
static void fields(FIELD *start,int group)
{
    FIELD *walk;
    TAG *scan;
    VALUE_LIST *tag;

    for (walk = start; walk; walk = walk->next) {
        if (walk->structure) {
            fields(walk->my_block,group);
            continue;
        }
        if (*walk->id != '_') {
            if (walk->value && walk->value->type == vt_case)
                to_c("    { %d, %d, %d, values_%d, %d }, /* %s */\n",group,
                     walk->pos,walk->size,walk->field,walk->var_len,walk->id);
            else to_c("    { %d, %d, %d, NULL, %d }, /* %s */\n",group,
                          walk->pos,walk->size,walk->var_len,walk->id);
        }
        if (walk->value)
            switch  (walk->value->type) {
            case vt_id:
                break;
            case vt_case:
            case vt_multi:
                for (scan = walk->value->tags; scan; scan = scan->next)
                    fields(scan->block,scan->group);
                to_test("static int unique_%d[] = { /* %s */\n",unique++,
                        walk->id);
                for (scan = walk->value->tags; scan; scan = scan->next) {
                    to_test("    %s,\n",scan->value);
                    for (tag = scan->more; tag; tag = tag->next)
                        to_test("    %s,\n",tag->value);
                }
                to_test("    -1\n};\n\n");
                break;
            case vt_length:
                fields(walk->value->block,group);
                break;
            default:
                abort();
            }
    }
}
Ejemplo n.º 4
0
TEST_F(Mat5Test, ScalarMultiplication)
{
    Mat5 to_test = 3 * TestMat;

    for (int i = 0; i < TestMat.getRows(); ++i)
    {
        for (int j = 0; j < TestMat.getCols(); ++j)
        {
            EXPECT_EQ(3 * TestMat(i, j), to_test(i, j));
        }
    }
}
Ejemplo n.º 5
0
void second(FIELD *def)
{
    int i;

    def->has_required = 0;
    to_c("\n/*\n");
    to_c(" * If a group contains required fields, these are listed in the\n");
    to_c(" * following arrays. Each list ends with -1. The variable names\n");
    to_c(" * end with the group number.\n */\n\n");
    dump_required(def,def,0);
    find_required(def);
    to_c("\n/*\n * Various information about groups.\n */\n\n");
    to_c("typedef struct {\n    int parent;\n    int *required;\n");
    to_c("    int start;\n    int length;\n    int offset;\n} GROUP;\n\n");
    to_c("static GROUP groups[] = {\n");
    if (def->has_required) to_c("    { -1, required_0 },\n");
    else to_c("    { -1, NULL },\n");
    to_test("static const char *groups[] = {\n");
    groups(def,0);
    to_test("    NULL\n};\n\n");
    to_c("};\n\n\n");
    to_c("/*\n * Named case selectors only have a limited set of valid\n");
    to_c(" * values. They are listed in the following arrays, each followed\n");
    to_c(" * by the number of the group it enables.\n */\n\n");
    values(def);
    to_c("\n/*\n * Various information about fields.\n */\n\n");
    to_c("typedef struct {\n    int parent;\n    int pos,size;\n");
    to_c("    int *values;\n    int actual;\n} FIELD;\n\n");
    to_c("static FIELD fields[] = {\n");
    fields(def,0);
    to_c("};\n\n");
    to_test("static int *unique[] = {\n");
    for (i = 0; i < unique; i++) to_test("    unique_%d,\n",i);
    to_test("    NULL\n};\n\n");
    if (dump) {
        to_dump("typedef struct {\n    unsigned long value;\n");
        to_dump("    const char *name;\n} SYM_NAME;\n\n");
        symbolic_names(def);
    }
}
Ejemplo n.º 6
0
static void groups(FIELD *start,int group)
{
    FIELD *walk;
    TAG *scan;

    for (walk = start; walk; walk = walk->next) {
        if (walk->structure) {
            groups(walk->my_block,group);
            continue;
        }
        if (walk->value)
            switch  (walk->value->type) {
            case vt_id:
                break;
            case vt_case:
            case vt_multi:
                for (scan = walk->value->tags; scan; scan = scan->next) {
                    int start_field,length,offset;

                    if (scan->block && scan->block->structure &&
                            scan->block->structure->instances < 0) {
                        start_field = scan->block->structure->first_field;
                        length = scan->block->structure->fields;
                        offset = scan->block->my_block->field-
                                 scan->block->structure->first_field;
                    }
                    else {
                        start_field = -1;
                        length = offset = 0;
                    }
                    if (scan->id) to_test("    \"%s\",\n",scan->id);
                    if (scan->block && scan->block->has_required)
                        if (scan->block->id)
                            to_c("    { %d, required_%d, %d, %d, %d }, "
                                 "/* %s */\n",group,scan->group,start_field,
                                 length,offset,scan->block->id);
                        else to_c("    { %d, required_%d, %d, %d, %d },\n",
                                      group,scan->group,start_field,length,offset);
                    else to_c("    { %d, NULL, %d, %d, %d },\n",group,
                                  start_field,length,offset);
                    groups(scan->block,scan->group);
                }
                break;
            case vt_length:
                groups(walk->value->block,group);
                break;
            default:
                abort();
            }
    }
}
Ejemplo n.º 7
0
TEST_F(Mat5Test, ZeroAddition)
{
    Mat5 to_test = TestMat;

    to_test += Mat5::Zero();

    for (int i = 0; i < TestMat.getRows(); ++i)
    {
        for (int j = 0; j < TestMat.getCols(); ++j)
        {
            EXPECT_EQ(TestMat(i, j), to_test(i, j));
        }
    }
}
Ejemplo n.º 8
0
TEST_F(Mat5Test, Addition)
{
    Mat5 to_test;

    to_test = TestMat + TestMat;

    for (int i = 0; i < TestMat.getRows(); ++i)
    {
        for (int j = 0; j < TestMat.getCols(); ++j)
        {
            EXPECT_EQ(2 * TestMat(i, j), to_test(i, j));
        }
    }
}
Ejemplo n.º 9
0
TEST_F(Mat5Test, ZeroMultiplication)
{
    Mat5 to_test = Mat5::Zero();

    to_test *= TestMat;

    for (int i = 0; i < TestMat.getRows(); ++i)
    {
        for (int j = 0; j < TestMat.getCols(); ++j)
        {
            EXPECT_EQ(0, to_test(i, j));
        }
    }
}
Ejemplo n.º 10
0
TEST_F(Mat5Test, IdentityMultiplication)
{
    Mat5 to_test = Mat5::Identity();

    to_test *= TestMat;

    for (int i = 0; i < TestMat.getRows(); ++i)
    {
        for (int j = 0; j < TestMat.getCols(); ++j)
        {
            EXPECT_EQ(TestMat(i, j), to_test(i, j));
        }
    }
}
Ejemplo n.º 11
0
TEST(PredicateOpTest, PredicateOpFiltersOutIntegersEqualToItsPredicate) {
  for (int i = 0; i < 10; i += 1) {
    MockOp next;
    PredicateOp to_test(i, &next);
    for (int j = 0; j < 10; j += 1) {
      to_test.Invoke(j);
      if (i == j) {
        EXPECT_FALSE(next.saw_invoke_);
      } else {
        EXPECT_TRUE(next.saw_invoke_);
        EXPECT_EQ(next.saw_which_, j);
      }
      next.saw_invoke_ = false;
    }
  }
}
Ejemplo n.º 12
0
void PhysiK::ParticleHashTable::generateIntersection(std::vector<IntersectionParticleParticle> &intersections){
	for(auto& iterator : voxelGrid){
		m_vector& test = iterator.second;
		const vec3& voxel = iterator.first;
		for(unsigned int i = 0 ; i < test.size();i++){
			m_pair& pair1= test[i];
			for(unsigned int j= i+1 ; j < test.size();j++){
				m_pair& pair2= test[j];
				IntersectionParticleParticle to_test(pair1.first,pair1.second,pair2.first,pair2.second);
				if(to_test.getParticle1()!=to_test.getParticle2()
						&&to_test.intersect()
						&&to_test.intersectPos().toVoxel()==voxel)//itersection in the voxel (avoid duplicate intersections)
					intersections.push_back(to_test);
			}
		}
	}
}
Ejemplo n.º 13
0
void PhysiK::ParticleHashTable::generateIntersectionWithTriangles(std::vector<IntersectionParticleTriangle> &intersections, TriangleHashTable &particlesHashtable){
	for(auto& iterator : voxelGrid){
		m_vector& test = iterator.second;
		const vec3& voxel = iterator.first;
		for(const m_pair& pair1 : test){
			Particle * particle = pair1.first->getPositions()+pair1.second;
			auto second_iterator = particlesHashtable.voxelGrid.find(voxel);
			if(second_iterator!=particlesHashtable.voxelGrid.end()){
				TriangleHashTable::m_vector& triangles = second_iterator->second;
				for(TriangleHashTable::m_pair& pair2 : triangles){
					IntersectionParticleTriangle to_test(pair2.first,pair2.second,particle,pair1.first->radius);
					if(to_test.intersect()||to_test.intersect(pair1.first->getOldPositions()[pair1.second]))
						intersections.push_back(to_test);
				}
			}
		}
	}
}
Ejemplo n.º 14
0
TEST(JoinOpTest, JoinOpFiltersOutIntegersThatAreInItsTable) {
  MockOp next;
  int some_evens_below_ten[] = {
    0, 2, 4, 6, 8
  };
  JoinOp to_test(&next);
  for (int i = 0; i < countof(some_evens_below_ten); i += 1) {
    to_test.Add(some_evens_below_ten[i]);
  }
  for (int i = 0; i < 10; i += 1) {
    to_test.Invoke(i);
    if (i%2 == 0) {
      EXPECT_FALSE(next.saw_invoke_);
    } else {
      EXPECT_TRUE(next.saw_invoke_);
      EXPECT_EQ(next.saw_which_, i);
    }
    next.saw_invoke_ = false;
  }
}
Ejemplo n.º 15
0
void PhysiK::TriangleHashTable::addObject(Body *body){
	for(unsigned int triangleOffset = 0 ; triangleOffset<body->nbTriangles ; triangleOffset++){
		Particle * particules[3];
		for(int j = 0 ; j < 3 ; j++)
			particules[j] = body->getPositions()+body->getTriangles()[triangleOffset][j];
		vec3 min;
		vec3 max;

		//on cherche le minimum et le maximum
		for(int j = 0 ; j < 3 ; j++){
			min[j] = std::min(std::min(particules[0]->pos[j],particules[1]->pos[j]),particules[2]->pos[j]);
			max[j] = std::max(std::max(particules[0]->pos[j],particules[1]->pos[j]),particules[2]->pos[j]);
		}

		vec3 min_voxel = min.toVoxel()-1.f;
		vec3 max_voxel = max.toVoxel()+1.f;

		for(float x = min_voxel.x ; x < max_voxel.x ; x++){
			for(float y = min_voxel.y ; y < max_voxel.y ; y++){
				for(float z = min_voxel.z ; z < max_voxel.z ; z++){
					vec3 voxel(x,y,z);
					Particle par(voxel.center().toWorld());
					//aproximate the cube with a particule
					CollisionParticuleTriangleConstraint to_test(
								&par,
							particules[0],
							particules[1],
							particules[2],
							vec3::voxelSize*sqrt(2.f)*0.5);
					if(to_test.eval()!=0){
						voxelGrid[voxel].push_back(std::make_pair(body,triangleOffset));
					}
				}
			}
		}
	}
}
Ejemplo n.º 16
0
int main(int argc,char **argv)
{
    const char *prefix;

    if (argc == 2 && !strcmp(argv[1],"-d")) debug = 1;
    if (argc == 2 && !strcmp(argv[1],"-D")) dump = 1;
    prefix = getenv("PREFIX");
    if (!prefix) prefix = dump ? "qd" : "q";
    open_files(prefix);
    to_h("/* THIS IS A MACHINE-GENERATED FILE. DO NOT EDIT ! */\n\n");
    to_c("/* THIS IS A MACHINE-GENERATED FILE. DO NOT EDIT ! */\n\n");
    to_c("#if HAVE_CONFIG_H\n");
    to_c("#include <config.h>\n");
    to_c("#endif\n\n");
    to_test("/* THIS IS A MACHINE-GENERATED FILE. DO NOT EDIT ! */\n\n");
    to_test("#if HAVE_CONFIG_H\n");
    to_test("#include <config.h>\n");
    to_test("#endif\n\n");
    if (dump) {
	to_dump("/* THIS IS A MACHINE-GENERATED FILE. DO NOT EDIT ! */\n\n");
	to_dump("#if HAVE_CONFIG_H\n");
	to_dump("#include <config.h>\n");
	to_dump("#endif\n\n");
    }
    to_c("/* (optional) user includes go here */\n\n");
    to_test("/* (optional) user includes go here */\n\n");
    if (dump) to_dump("/* (optional) user includes go here */\n\n");
    if (yyparse()) return 1;
    to_test("\n#ifndef NULL\n#define NULL ((void *) 0)\n#endif\n\n");
    if (dump) to_dump("\n#ifndef NULL\n#define NULL ((void *) 0)\n#endif\n\n");
    to_h("#ifndef Q_OUT_H\n#define Q_OUT_H\n\n");
    to_c("\n#include <stdlib.h>\n#include <stdio.h>\n");
    to_c("#include <string.h>\n#include <sys/types.h>\n\n");
    to_c("#include \"common.h\"\n#include \"op.h\"\n");
    to_c("#include \"%s.out.h\"\n",prefix);
    to_c("#include \"qlib.h\"\n\n");
    to_c("\n\nstatic void q_put(unsigned char *table,int pos,int size,"
      "unsigned long value);\n\n");
    first(def);
    second(def);
    third(def);
    to_h("#endif\n");
    to_c("\n/*\n * Sorry, this is necessary ...\n */\n\n");
    to_c("#include \"qlib.c\"\n");
    to_test("\n/*\n * Sorry, this is necessary ...\n */\n\n");
    to_test("#include \"qtest.c\"\n");
    if (dump) {
	to_dump("\n/*\n * Sorry, this is necessary ...\n */\n\n");
	to_dump("#define DUMP_MODE\n\n");
	to_dump("#include \"%s.out.c\"\n",prefix);
    }
    close_files();
    fprintf(stderr,"  %d groups, %d fields (%d var-len), construction area is "
      "%d bytes,\n",group,field,varlen_fields,(offset+7)/8);
    fprintf(stderr,"  %d words in constructor, %d words in parser",
      constr_size,parser_size);
    if (!dump) fprintf(stderr,".\n");
    else fprintf(stderr,",\n  %d symbolic names in %d tables.\n",symbols,
	  sym_tables);
    return 0;
}