TEST(search, tdelete) {
  void* root = nullptr;

  pod_node n1(123);
  ASSERT_NE(nullptr, tsearch(&n1, &root, pod_node_cmp));

  // tdelete(3) leaks n1.
  pod_node not_there(456);
  ASSERT_EQ(nullptr, tdelete(&not_there, &root, pod_node_cmp));
  ASSERT_NE(nullptr, tdelete(&n1, &root, pod_node_cmp));
}
Exemple #2
0
  TEUCHOS_UNIT_TEST( Stokhos_NormalizedHermiteBasis, Norm2 ) {
    Teuchos::Array<double> n1(setup.p+1);
    Teuchos::Array<double> n2(setup.p+1);
    n1[0] = setup.basis.norm_squared(0);
    n2[0] = 1.0;
    for (int i=1; i<=setup.p; i++) {
      n1[i] = setup.basis.norm_squared(i);
      n2[i] = 1.0;
    }
    success = Stokhos::compareArrays(n1, "n1", n2, "n2", setup.rtol, setup.atol,
				     out);
  }
Exemple #3
0
void ashrith()
{
 aaa(xnxt,ynxt,h,wa);
 sss(xnxt,ynxt,h,ws);
 hhh(xnxt,ynxt,h,wh);
 rrr(xnxt,ynxt,h,wr);
 iii(xnxt,ynxt,h,wi);
 ttt(xnxt,ynxt,h,wt);
 hhh(xnxt,ynxt,h,wh);
 xnxt+=s/2;
 hhh(xnxt,ynxt,h,wh);
 xnxt+=s/2;
 ccc(xnxt,ynxt,h,wc);
 xnxt+=s/2;
 n1(xnxt,ynxt,h,w1);
 n1(xnxt,ynxt,h,w1);
 iii(xnxt,ynxt,h,wi);
 ttt(xnxt,ynxt,h,wt);
 n1(xnxt,ynxt,h,w1);
 n1(xnxt,ynxt,h,w1);
}
std::string BigData::Mod(std::string left, std::string right)
{

	char cSymbol = left[0];
	BigData n1(left.c_str() + 1);
	BigData n2(right.c_str() + 1);
	BigData n3 = n1 / n2;
	BigData n4 = n3*n2;
	BigData sRet(n1 - n4);
	sRet._strData[0] = cSymbol;
	return sRet._strData;
}
Exemple #5
0
void harsha()
{
 sss(xnxt,ynxt,h,ws);
 hhh(xnxt,ynxt,h,wh);
 rrr(xnxt,ynxt,h,wr);
 eee(xnxt,ynxt,h,we);
 eee(xnxt,ynxt,h,we);
 hhh(xnxt,ynxt,h,wh);
 aaa(xnxt,ynxt,h,wa);
 rrr(xnxt,ynxt,h,wr);
 sss(xnxt,ynxt,h,ws);
 hhh(xnxt,ynxt,h,wh);
 aaa(xnxt,ynxt,h,wa);
 xnxt+=s/2;
 n1(xnxt,ynxt,h,w1);
 n1(xnxt,ynxt,h,w1);
 iii(xnxt,ynxt,h,wi);
 ttt(xnxt,ynxt,h,wt);
 n8(xnxt,ynxt,h,w8);
 n8(xnxt,ynxt,h,w8);
}
void Mesh::LoadOBJ(const QStringRef &filename, const QStringRef &local_path)
{
    QString filepath = local_path.toString(); filepath.append(filename);
    std::vector<tinyobj::shape_t> shapes; std::vector<tinyobj::material_t> materials;
    std::string errors = tinyobj::LoadObj(shapes, materials, filepath.toStdString().c_str());
    std::cout << errors << std::endl;
    if(errors.size() == 0)
    {
        //Read the information from the vector of shape_ts
        for(unsigned int i = 0; i < shapes.size(); i++)
        {
            std::vector<float> &positions = shapes[i].mesh.positions;
            std::vector<float> &normals = shapes[i].mesh.normals;
            std::vector<float> &uvs = shapes[i].mesh.texcoords;
            std::vector<unsigned int> &indices = shapes[i].mesh.indices;
            for(unsigned int j = 0; j < indices.size(); j += 3)
            {
                glm::vec3 p1(positions[indices[j]*3], positions[indices[j]*3+1], positions[indices[j]*3+2]);
                glm::vec3 p2(positions[indices[j+1]*3], positions[indices[j+1]*3+1], positions[indices[j+1]*3+2]);
                glm::vec3 p3(positions[indices[j+2]*3], positions[indices[j+2]*3+1], positions[indices[j+2]*3+2]);

                Triangle* t = new Triangle(p1, p2, p3);
                if(normals.size() > 0)
                {
                    glm::vec3 n1(normals[indices[j]*3], normals[indices[j]*3+1], normals[indices[j]*3+2]);
                    glm::vec3 n2(normals[indices[j+1]*3], normals[indices[j+1]*3+1], normals[indices[j+1]*3+2]);
                    glm::vec3 n3(normals[indices[j+2]*3], normals[indices[j+2]*3+1], normals[indices[j+2]*3+2]);
                    t->normals[0] = n1;
                    t->normals[1] = n2;
                    t->normals[2] = n3;
                }
                if(uvs.size() > 0)
                {
                    glm::vec2 t1(uvs[indices[j]*2], uvs[indices[j]*2+1]);
                    glm::vec2 t2(uvs[indices[j+1]*2], uvs[indices[j+1]*2+1]);
                    glm::vec2 t3(uvs[indices[j+2]*2], uvs[indices[j+2]*2+1]);
                    t->uvs[0] = t1;
                    t->uvs[1] = t2;
                    t->uvs[2] = t3;
                }
                this->faces.append(t);
            }
        }
        std::cout << "" << std::endl;
        //TODO: .mtl file loading
    }
    else
    {
        //An error loading the OBJ occurred!
        std::cout << errors << std::endl;
    }
}
int main()
{
  graph_node<std::string> n1("A"), n2("B"), n3("C");
  graph_edge<std::string> e1(n1, n2, 3.0), e2(n1, n3, 1.47), e3(n2, n1, 3.0);

  std::cout << std::hash<graph_edge<std::string>>()(e1) << '\n';
  std::cout << std::hash<graph_edge<std::string>>()(e3) << '\n';
  std::cout << std::hash<graph_edge<std::string>>()(e2) << '\n';

  if (e1 == e3) {
    std::cout << "e1 == e3\n";
  }
}
void testTypeIDBase::copyTest()
{
  edmtest::empty e;
  edm::TypeIDBase id1(typeid(e));

  edm::TypeIDBase id3=id1;
  CPPUNIT_ASSERT(!(id1 < id3));
  CPPUNIT_ASSERT(!(id3 < id1));

  std::string n1(id1.name());
  std::string n3(id3.name());
  CPPUNIT_ASSERT(n1== n3);
}
dgBigVector dgCollisionConvexHull::FaceNormal (const dgEdge *face, const dgBigVector* const pool) const
{
	const dgEdge* edge = face;
	dgBigVector p0 (pool[edge->m_incidentVertex]);
	edge = edge->m_next;

	dgBigVector p1 (pool[edge->m_incidentVertex]);
	dgBigVector e1 (p1 - p0);

	dgBigVector normal (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
	for (edge = edge->m_next; edge != face; edge = edge->m_next) {
		dgBigVector p2 (pool[edge->m_incidentVertex]);
		dgBigVector e2 (p2 - p0);
		dgBigVector n1 (e1 * e2);
#ifdef _DEBUG
		dgFloat64 mag = normal % n1;
		dgAssert ( mag >= -dgFloat32 (0.1f));
#endif
		normal += n1;
		e1 = e2;
	} 
	dgFloat64 den = sqrt (normal % normal) + dgFloat64 (1.0e-24f);
	normal = normal.Scale3 (dgFloat64 (1.0f)/ den);

#ifdef _DEBUG
	edge = face;
	dgBigVector e0 (pool[edge->m_incidentVertex] - pool[edge->m_prev->m_incidentVertex]);	
	do {
		dgBigVector e1 (pool[edge->m_next->m_incidentVertex] - pool[edge->m_incidentVertex]);	
		dgBigVector n1 (e0 * e1);
		dgFloat64 x = normal % n1;
		dgAssert (x > -dgFloat64 (0.01f));
		e0 = e1;
		edge = edge->m_next;
	} while (edge != face);
#endif

	return normal;
}
Exemple #10
0
void MyMoneyPriceTest::testValidity()
{
  QString emptyId;
  MyMoneyPrice n1(emptyId, QString("to"), QDate(2005, 9, 23), MyMoneyMoney(1, 3),  QString("MySource"));
  MyMoneyPrice n2(QString("from"), emptyId, QDate(2005, 9, 23), MyMoneyMoney(1, 3),  QString("MySource"));
  MyMoneyPrice n3(QString("from"), QString("to"), QDate(), MyMoneyMoney(1, 3),  QString("MySource"));
  MyMoneyPrice n4(QString("from"), QString("to"), QDate(2005, 9, 23), MyMoneyMoney(1, 3),  QString("MySource"));

  QVERIFY(n1.isValid() == false);
  QVERIFY(n2.isValid() == false);
  QVERIFY(n3.isValid() == false);
  QVERIFY(n4.isValid() == true);
}
Exemple #11
0
/**
 * 円柱を構築する。(カラー版)
 * 側面のみ。上面と底面はなし。
 */
void VBORenderManager::addCylinder(const QString& geoName, const glm::mat4& modelMat, float baseRadius, float topRadius, float height, const QColor& color, int slices, int stacks) {
	std::vector<Vertex> verts;

	for (int i = 0; i < stacks; ++i) {
		float z1 = height / stacks * i;
		float z2 = height / stacks * (i + 1);
		float radius1 = (topRadius - baseRadius) / stacks * i + baseRadius;
		float radius2 = (topRadius - baseRadius) / stacks * (i + 1) + baseRadius;

		for (int j = 0; j < slices; ++j) {
			float theta1 = 2.0 * M_PI * j / slices;
			float theta2 = 2.0 * M_PI * (j + 1) / slices;
			float x1 = radius1 * cosf(theta1);
			float y1 = radius1 * sinf(theta1);
			float x2 = radius1 * cosf(theta2);
			float y2 = radius1 * sinf(theta2);
			float x3 = radius2 * cosf(theta2);
			float y3 = radius2 * sinf(theta2);
			float x4 = radius2 * cosf(theta1);
			float y4 = radius2 * sinf(theta1);

			glm::vec4 p1(x1, y1, z1, 1.0f);
			glm::vec4 p2(x2, y2, z1, 1.0f);
			glm::vec4 p3(x3, y3, z2, 1.0f);
			glm::vec4 p4(x4, y4, z2, 1.0f);
			p1 = modelMat * p1;
			p2 = modelMat * p2;
			p3 = modelMat * p3;
			p4 = modelMat * p4;

			glm::vec4 n1(x1, y1, sqrtf(x1*x1+y1*y1) / height * (baseRadius - topRadius), 0.0f);
			glm::vec4 n2(x2, y2, sqrtf(x2*x2+y2*y2) / height * (baseRadius - topRadius), 0.0f);
			glm::vec4 n3(x3, y3, sqrtf(x3*x3+y3*y3) / height * (baseRadius - topRadius), 0.0f);
			glm::vec4 n4(x4, y4, sqrtf(x4*x4+y4*y4) / height * (baseRadius - topRadius), 0.0f);
			n1 = modelMat * n1;
			n2 = modelMat * n2;
			n3 = modelMat * n3;
			n4 = modelMat * n4;

			verts.push_back(Vertex(glm::vec3(p1), color, glm::vec3(n1), glm::vec3()));
			verts.push_back(Vertex(glm::vec3(p2), color, glm::vec3(n2), glm::vec3()));
			verts.push_back(Vertex(glm::vec3(p3), color, glm::vec3(n3), glm::vec3()));

			verts.push_back(Vertex(glm::vec3(p1), color, glm::vec3(n1), glm::vec3()));
			verts.push_back(Vertex(glm::vec3(p3), color, glm::vec3(n3), glm::vec3()));
			verts.push_back(Vertex(glm::vec3(p4), color, glm::vec3(n4), glm::vec3()));
		}
	}

	addStaticGeometry(geoName, verts, "", GL_TRIANGLES, 1|mode_Lighting);
}
  void runEmptyRelationNoMemberCountTagTest()
  {
    //add some nodes to a map
    OsmMapPtr map(new OsmMap());
    ElementPtr n1(new Node(Status::Unknown1, 1, 0, 0, 0));
    ElementPtr n2(new Node(Status::Unknown2, 2, 0, 0, 0));
    ElementPtr n3(new Node(Status::Unknown1, 3, 0, 0, 0));
    ElementPtr n4(new Node(Status::Unknown2, 4, 0, 0, 0));
    map->addElement(n1);
    map->addElement(n2);
    map->addElement(n3);
    map->addElement(n4);

    //create two reviews involving the two pairs of nodes
    ReviewMarker reviewMarker;
    reviewMarker.mark(map, n1, n2, "note 1", "test 1");
    reviewMarker.mark(map, n3, n4, "note 2", "test 2");
    CPPUNIT_ASSERT_EQUAL((size_t)2, map->getRelations().size());
    CPPUNIT_ASSERT(reviewMarker.isNeedsReview(map, n1, n2));
    CPPUNIT_ASSERT(reviewMarker.isNeedsReview(map, n3, n4));

    //get the review relations
    set<ElementId> review1 = reviewMarker._getReviewRelations(map, n1->getElementId());
    CPPUNIT_ASSERT_EQUAL((size_t)1, review1.size());
    const ElementId r1Id = *review1.begin()++;
    set<ElementId> review2 = reviewMarker._getReviewRelations(map, n3->getElementId());
    CPPUNIT_ASSERT_EQUAL((size_t)1, review2.size());
    const ElementId r2Id = *review2.begin()++;
    RelationPtr relation1 = map->getRelation(r1Id.getId());
    RelationPtr relation2 = map->getRelation(r2Id.getId());

    //go ahead and remove their review member count tags
    relation1->getTags().remove(MetadataTags::HootReviewMembers());
    relation2->getTags().remove(MetadataTags::HootReviewMembers());

    //remove all of one of the review relation's members
    RemoveElementOp::removeElement(map, n3->getElementId());
    RemoveElementOp::removeElement(map, n4->getElementId());
    relation2->removeElement(n3->getElementId());
    relation2->removeElement(n4->getElementId());

    //run the visitor
    RemoveInvalidReviewRelationsVisitor v;
    map->visitRw(v);

    //the empty review relation should have been removed
    CPPUNIT_ASSERT_EQUAL((size_t)1, map->getRelations().size());
    CPPUNIT_ASSERT(map->containsElement(r1Id));
    CPPUNIT_ASSERT(!map->containsElement(r2Id));
  }
Exemple #13
0
int main(){
    TreeNode n0(10);
    TreeNode n1(5);
    TreeNode n2(15);
    TreeNode n3(6);
    TreeNode n4(20);
    n0.left = &n1;
    n0.right = &n2;
    n2.left = &n3;
    n2.right = &n4;
    bool res = isValidBST(&n0);
    printf("%s\n", res?"true":"false");
    return 0;
}
void PyVariableTests::testPyTape(){
    AbsExpNodeSptr n;
    PyTape t;
    PyExpNode n1(1,0,0,1,1,2,1); // this means t1=d0+d1
    PyExpNode n2(1,0,2,2,1,2,2); // this means t2=d0*t1
    PyExpNode n3(0,0,43,2,2,2,3); // this means t3=log(t2)
    t.push_back_node(n1);
    t.push_back_node(n2);
    t.push_back_node(n3);
    n = t.decode(active_node_vec, temp_node_vec);
    std::vector<double> dvec{16,2,77,29, 30};
    CPPUNIT_ASSERT(n->get_value(dvec)==log(288.0));
    
}
Exemple #15
0
LCVector LCOrbits::VectNormal(double t)
{
	LCVector n1(MT), n2(MT), r(MT);
	
	n1 = position(2,t)-position(3,t);
	n2 = position(3,t)-position(1,t);
	
	r.p[0] = n1.p[1]*n2.p[2]-n1.p[2]*n2.p[1];
	r.p[1] = n1.p[2]*n2.p[0]-n1.p[0]*n2.p[2];
	r.p[2] = n1.p[0]*n2.p[1]-n1.p[1]*n2.p[0];
	
	
	return (r.unit());
}
Exemple #16
0
void OmniRobot::init()
{
    period = 200;
    xw = 75.0; //mm
    yw = 75.0; //mm
    Dw = 50.0; //mm

    vector<float> u1 (2); u1(0) =  c1; u1(1) =  c1;
    vector<float> u2 (2); u2(0) =  c1; u2(1) = -c1;
    vector<float> u3 (2); u3(0) =  c1; u3(1) =  c1;
    vector<float> u4 (2); u4(0) =  c1; u4(1) = -c1;

    vector<float> n1 (2); n1(0) =  c1; n1(1) = -c1;
    vector<float> n2 (2); n2(0) = -c1; n2(1) = -c1;
    vector<float> n3 (2); n3(0) =  c1; n3(1) = -c1;
    vector<float> n4 (2); n4(0) = -c1; n4(1) = -c1;

    vector<float> b1 (2); b1(0) =  xw; b1(1) =  yw;
    vector<float> b2 (2); b2(0) =  xw; b2(1) = -yw;
    vector<float> b3 (2); b3(0) = -xw; b3(1) = -yw;
    vector<float> b4 (2); b4(0) = -xw; b4(1) =  yw;

    Mt(0,0) = n1(0); Mt(0,1) = n1(1); Mt(0,2) = b1(0)*u1(0) + b1(1)*u1(1);
    Mt(1,0) = n2(0); Mt(1,1) = n2(1); Mt(1,2) = b2(0)*u2(0) + b2(1)*u2(1);
    Mt(2,0) = n3(0); Mt(2,1) = n3(1); Mt(2,2) = b3(0)*u3(0) + b3(1)*u3(1);
    Mt(3,0) = n4(0); Mt(3,1) = n3(1); Mt(3,2) = b4(0)*u4(0) + b4(1)*u4(1);

    Mt = -1 * Mt;

    cmd(0) = 0.0; cmd(1) = 0.0; cmd(2) = 0.0;
    pwm(0) = 0.0; pwm(1) = 0.0; pwm(2) = 0.0; pwm(3) = 0.0;

    omniState = INIT_MODE;
    movementMode = ROTATE_MODE;
    power = 20;
    pplus = 1;
}
int main() {

    typedef DAG::Node<const idpair> INode;

    // create a set of nodes
    // the nodes will be kept track of in the Node children and parent collections so
    // shared_ptr is used.
    INode n0(idpair(0, 2));
    INode n1(idpair(1, 3));
    INode n2(idpair(2, 3));
    INode n3(idpair(3, 2));
    INode n4(idpair(4, 2));
    INode n5(idpair(5, 2));
    INode n6(idpair(6, 2));
    // and now define the polytree
    // add the directed (parent -> child) branches of the polytree
    // each link requires an addChild and an addParent
    n0.addChild(n1);  // link between n0 and n1
    n1.addChild(n2);  // link between n0 and n2 etc
    n1.addChild(n3);
    n3.addChild(n6);
    n3.addChild(n4);
    n4.addChild(n5);
    n5.addChild(n6);

    DAG::BFSRecurseVisitor<INode> bfs;
    // Start at node 0 for the following examples

    // Example 1
    // BFSVisitor uses an iterative method to traverse
    // output the Datatype of all children
    std::cout << std::endl << "TRAVERSE CHILDREN (start Node 0)  1 level" << std::endl;
    for (auto n : bfs.traverseChildren(n0, 1)) {
        std::cout << n->value().itype << ":" << n->value().ivalue << std::endl;
    }

    std::cout << std::endl << "TRAVERSE UNDIRECTED (start Node 5) 2 levels " << std::endl;
    for (auto n : bfs.traverseUndirected(n5, 2)) {
        std::cout << n->value().itype << ":" << n->value().ivalue << std::endl;
    }

    std::cout << std::endl << "TRAVERSE CHILDREN (start Node 0)  all levels" << std::endl;

    for (auto n : bfs.traverseChildren(n0)) {
        std::cout << n->value().itype << ":" << n->value().ivalue << std::endl;
    }

    return 0;
}
void testTypeIDBase::equalityTest()

{
  edmtest::empty e;
  edm::TypeIDBase id1(typeid(e));
  edm::TypeIDBase id2(typeid(e));
  
  CPPUNIT_ASSERT(!(id1 < id2));
  CPPUNIT_ASSERT(!(id2 < id1));

  std::string n1(id1.name());
  std::string n2(id2.name());

  CPPUNIT_ASSERT(n1==n2);
}
  void runBasicTest()
  {
    NodePtr n1(new Node(Status::Unknown1, -1, -104.8852148123, 38.8467218123, 5));
    n1->getTags()["highway"] = "bus_stop";
    n1->getTags()["name"] = "Bus Stop 1";
    n1->getTags()["source"] = "imagery";

    HOOT_STR_EQUALS("{\"type\":\"Feature\",\"properties\":{\"type\":\"node\",\"tags\":{\"error:circular\":\"5\",\"highway\":\"bus_stop\",\"name\":\"Bus Stop 1\"}},\"geometry\":{\"type\":\"Point\",\"coordinates\":[-104.8852148,38.8467218]}}",
      CalculateHashVisitor::toJsonString(n1));

    // validated here: http://onlinemd5.com/
    // for some reason the commandline sha1sum gives a different result.
    HOOT_STR_EQUALS("746c440be4fc11f9631d62d26cbba6aa97f73e3c",
      QString::fromUtf8(CalculateHashVisitor::toHash(n1).toHex().data()));
  }
Exemple #20
0
void QxrdPowderPoint::setSettingsValue(QSettings *settings, QString name)
{
  settings->beginGroup(name);

  settings->setValue("n1", n1());
  settings->setValue("n2", n2());
  settings->setValue("n3", n3());
  settings->setValue("x", x());
  settings->setValue("y", y());
  settings->setValue("r1", r1());
  settings->setValue("r2", r2());
  settings->setValue("az", az());

  settings->endGroup();
}
Exemple #21
0
/** answer is 4782 */
int main(int argc, char *argv[])
{
	largeNumber n1(1);
	largeNumber n2(1);
	int l = 2;
	while (n2.digit()<1000)
	{

		largeNumber n = n1+n2;
		n1 = n2;
		n2 = n;
		++ l;
	}
	std::cout<<l<<std::endl;
}
int main(int argc, char **argv) {
    ListNode n5(5, NULL);
    ListNode n4(4, &n5);
    ListNode n3(3, &n4);
    ListNode n2(2, &n3);
    ListNode n1(1, &n2);

    ListNode *head = s.removeNthFromEnd(&n1, 2);
    while (head != NULL) {
        printf("%d ", head->val);
        head = head->next;
    }
    printf("\n");
    return 0;
}
Exemple #23
0
Segment Segment::getShortestConnection(const Segment & other) const {

	const Node & n0 = getA();
	const Node & n1 = getB();
	const Node & n2 = other.getA();
	const Node & n3 = other.getB();

	float d0232 = glm::dot(n0() - n2(), n3() - n2());
	float d3210 = glm::dot(n3() - n2(), n1() - n0());
	float d3232 = glm::pow(other.getLength(), 2.f);
	float d0210 = glm::dot(n0() - n2(), n1() - n0());
	float d1010 = glm::pow(getLength(), 2.f);

	float d0 = (d0232 * d3210 - d0210 * d3232) / (d1010 * d3232 - d3210 * d3210);
	float d1 = (d0232 + d0 * d3210) / d3232;
	d0 = glm::clamp(d0, 0.f, 1.f);
	d1 = glm::clamp(d1, 0.f, 1.f);

	Node ni0 = n0 + d0 * (n1 - n0);
	Node ni1 = n2 + d1 * (n3 - n2);

	return Segment(ni0, ni1);

}
vec3 trace(const ray& theray, const world* world, const vec3& light_dir)
{
    range r(0, std::numeric_limits<float>::max());
    surface_hit hit;
    hit.t = std::numeric_limits<float>::max();

    ray object_ray = transform_ray(theray, world->object_matrix, world->object_normal_matrix);
    bool have_hit = world->root->intersect(object_ray, r, &hit);
    if(!have_hit)
        return world->background;

    vec4 n1(hit.normal.x, hit.normal.y, hit.normal.z, 0.0), n2;
    vec4 p1(hit.point.x, hit.point.y, hit.point.z, 1.0), p2;
    n2 = mat4_mult_vec4(world->object_normal_inverse, n1);
    p2 = mat4_mult_vec4(world->object_inverse, p1);
    vec3 normal = vec3(n2.x, n2.y, n2.z);
    vec3 point = vec3(p2.x, p2.y, p2.z);

    float brightness;

    float shadowed = false;

    if(cast_shadows)
    {
        struct ray shadowray;
        shadowray.o = vec3_add(point, vec3_scale(normal, .0001));
        shadowray.d = light_dir;
        surface_hit shadow_hit;
        shadow_hit.t = std::numeric_limits<float>::max();
        ray object_ray = transform_ray(shadowray, world->object_matrix, world->object_normal_matrix);
        shadowed = world->root->intersect(object_ray, range(0, std::numeric_limits<float>::max()), &shadow_hit);
    }

    if(shadowed) {

        brightness = .1;

    } else {

        brightness = vec3_dot(normal, light_dir);
        if(brightness < 0)
            brightness = 0;
        if(brightness > 1)
            brightness = 1;
    }

    return vec3_scale(hit.color, brightness);
}
Exemple #25
0
uint64_t scenario2(uint64_t hoppingPeriod, uint64_t beaconningPeriod,
		       size_t /*beaconCount*/, float /*senseBW*/)
{
	uint64_t band_start = 2.3995e9;
	uint64_t band_end = 2.5125e9;

	float band1 = band_start + (rand_cmwc() % ((band_end - band_start) / 1000000)) * 1e6;
	float band2 = band_start + (rand_cmwc() % ((band_end - band_start) / 1000000)) * 1e6;

	/*std::cout << "Band1: " << band1 / 1e6;
	std::cout << ", Band2: " << band2 / 1e6 << std::endl;*/

	HoppingPattern hp1(1000e3, Band(band_start, band_end), 1.1e6, HoppingPattern::LINEAR, 1e3);
	hp1.addAvailableEntry(Band(band1, band1+1e6), 0.0, 0.4);
	hp1.addAvailableEntry(Band(band2, band2+1e6), 0.5, 0.4);
	CogNode n1(42, 0, 0, beaconningPeriod, hp1, 1);

	HoppingPattern hp2(60e6, Band(band_start, band_end), 1.1e6, HoppingPattern::RANDOM,
			   hoppingPeriod, 1e6);
	CogNode n2(43, 0, 0, 10e3, hp2, 1);

	CogNode *nodes[] = { &n1, &n2 };
	size_t nodesCount = sizeof(nodes) / sizeof(CogNode *);

	while (true) {
		uint64_t next = -1;

		for (size_t i = 0; i < nodesCount; i++) {
			uint64_t nodeNext = nodes[i]->usUntilNextOperation();
			if (nodeNext < next)
				next = nodeNext;
		}

		//std::cout << "next = " << next << std::endl;

		// FIXME? If a node jumps to a frequency, it won't be able to
		// receive a message until the next tick change. That's pretty
		// much what we get in real life though :s
		for (size_t i = 0; i < nodesCount; i++) {
			nodes[i]->addTicks(next);
			if (n2.hasNeighbour(42)) {
				return n2.ticksSinceStart();
			}
		}
	}

	//std::cout << std::endl;
}
Exemple #26
0
TEST(QueueTest, StackTest)
{
    // Check that inserting several nodes to Stack acts as LIFO
    Stack queue; // yeah, that's terrible naming, w/e
    Node n1(0,1,4,5,false), n2(1,2,4,3,false),
         n3(2,1,3,6,false), n4(1,0,4,7,false);
    queue.insert(&n1);
    queue.insert(&n2);
    queue.insert(&n3);
    queue.insert(&n4);
    // Order should be n4,n3,n2,n1
    ASSERT_EQ(&n4, queue.removeFront());
    ASSERT_EQ(&n3, queue.removeFront());
    ASSERT_EQ(&n2, queue.removeFront());
    ASSERT_EQ(&n1, queue.removeFront());
}
int Normal2DF0D::operator()(Interface0DIterator& iter)
{
	FEdge *fe1, *fe2;
	getFEdges(iter, fe1, fe2);
	Vec3f e1(fe1->orientation2d());
	Vec2f n1(e1[1], -e1[0]);
	Vec2f n(n1);
	if (fe2 != NULL) {
		Vec3f e2(fe2->orientation2d());
		Vec2f n2(e2[1], -e2[0]);
		n += n2;
	}
	n.normalize();
	result = n;
	return 0;
}
Exemple #28
0
TEST(QueueTest, QueueFIFOTest)
{
    // Check that regular queue is FIFO
    StdQueue queue;
    Node n1(0,1,4,5), n2(1,2,4,3),
         n3(2,1,3,6), n4(1,0,4,7);
    queue.insert(&n1);
    queue.insert(&n2);
    queue.insert(&n3);
    queue.insert(&n4);
    // Order should be n1,n2,n3,n4
    ASSERT_EQ(&n1, queue.removeFront());
    ASSERT_EQ(&n2, queue.removeFront());
    ASSERT_EQ(&n3, queue.removeFront());
    ASSERT_EQ(&n4, queue.removeFront());
}
END_TEST


START_TEST(test_remove)
  {
  numa_node n0("../../../../test/test_files", 0);
  numa_node n1("../../../../test/test_files", 1);
  std::vector<numa_node> nodes;
  nodes.push_back(n0);
  nodes.push_back(n1);
  node_internals ni(nodes);

  remove_called = 0;
  ni.remove_job("1.napali");
  fail_unless(remove_called == 2);
  }
Exemple #30
0
int main(){
    TreeNode n1(1);
    TreeNode n2(2);
    TreeNode n3(3);
    TreeNode n4(4);
    TreeNode n5(5);
    TreeNode n6(6);
    n1.left = &n2;
    //n1.right = &n5;
    n2.left = &n3;
    n2.right = &n4;
    n5.right = &n6;
    bool r = hasPathSum(&n1, 1);
    printf("%s\n", r?"true":"false");
    return 0;
}