Ejemplo n.º 1
0
int main()
{
    j() = 100; // 编译器帮我们做了一些事情:返回的是a的引用(内存地址),可以赋值。
    j();

    *(j2()) = 200; // 自己手动赋值,跟上面代码一样,只不过上面代码编译器帮我们做了
    j2();

    return 0;
}
Ejemplo n.º 2
0
void swappable_iterator_test(Iterator i, Iterator j)
{
    Iterator i2(i), j2(j);
    typename detail::iterator_traits<Iterator>::value_type bi = *i, bj = *j;
    iter_swap(i2, j2);
    typename detail::iterator_traits<Iterator>::value_type ai = *i, aj = *j;
    assert(bi == aj && bj == ai);
}
Ejemplo n.º 3
0
void test_comparison_operators() {
	cout << "Testing Comparison Operators" << endl;
	cout << "------------------------------------------------------------------" << endl;
	

	String s = "hello";
	String s2 = "world";
	String s3 = "My length should be 22";
	String j("where are");
	String j2(" you going.");
	String j3 = "where are";
	String j4 = " you going.";
	String x = "why";
	String w = "me";
	String y = "good";
	String z = "bad";
	String y1 = "good";
	
	
	cout << "size() function, Size of \"world\" = " << s2.size() << endl;
	cout << "size() function, Size of \"My length should be 22\" = " << s3.size() << endl;

	cout << "operator ==: \"why\" == \"me\" = "  << (x == w) << endl;
	cout << "operator ==: \"good\" ==  \"good\" = " << (y == y1) << endl;

	cout << "operator !=: \"why\" != \"me\" = "  << (x != w) << endl;
	cout << "operator !=: \"good\" !=  \"bad\" = " << (y != z) << endl;

	cout << "operator >: \"why\" > \"me\" = "  << (x > w) << endl;
	cout << "operator >: \"good\" >  \"bad\" = " << (y > z) << endl;

	cout << "operator <: \"why\" < \"me\" = "  << (x < w) << endl;
	cout << "operator <: \"bad\" <  \"good\" = " << (z < y) << endl;

	cout << "operator >=: \"why\" >= \"me\" = "  << (x >= w) << endl;
	cout << "operator >=: \"good\" >=  \"bad\" = " << (y >= z) << endl;

	cout << "operator <=: \"why\" <= \"me\" = "  << (x <= w) << endl;
	cout << "operator <=: \"good\" <=  \"bad\" = " << (y <= z) << endl;

	cout << "operator +: \"hello\" + \"world\" = "  << (s + s2) << endl;
	cout << "operator +: \"where are\" +  \" you going\". = " << (j + j2) << endl;
	

	cout << "operator +=: \"where are\" +=  \" you going\". = " << (j3 += j4) << endl;
	cout << "operator +=: \"why\" += \"you\". = " << (x += "you") << endl;

	
	cout << "------------------------------------------------------------------" << endl << endl;

}
Ejemplo n.º 4
0
int main(int argc, char * argv[])
{
  printf("hello\n");
  Polygon p1;
  Polygon p2;
  Polygons ps1;
  Polygons ps2;

  IntPoint i1(0, 0);
  IntPoint i2(0, 100);
  IntPoint i3(100, 100);
  IntPoint i4(100, 0);

  IntPoint j1(0, 0);
  IntPoint j2(50, 200);
  IntPoint j3(100, 0);

  p1.push_back(i1);
  p1.push_back(i2);
  p1.push_back(i3);
  p1.push_back(i4);

  p2.push_back(j1);
  p2.push_back(j2);
  p2.push_back(j3);

  ps1.push_back(p1);
  ps2.push_back(p2);

  Clipper clipper;

  clipper.AddPolygons(ps1, ptSubject);
  clipper.AddPolygons(ps2, ptClip);
  Polygons soln;
  clipper.Execute(ctIntersection, soln);

  for(int i = 0; i < soln.size(); i++)
  {
    Polygon& p = soln[i];
    for(int j = 0; j < p.size(); j++)
    {
      printf("Point:(%lld,%lld)\n", p[j].X, p[j].Y);
    }
  }

  printf("hehe\n");
  return 0;
}
Ejemplo n.º 5
0
void massive() {

  for ( int i = 0; i < 2; ++i ) { 

    double p = 30;
    double m = 5;

    PxPyPzM j1(p*sin(4.*atan(1.)*2./3.),p*cos(4.*atan(1.)*2./3.),0.,i==0?m:0.);
    PxPyPzM j2(p*sin(4.*atan(1.)*4./3.),p*cos(4.*atan(1.)*4./3.),0.,i==0?m:0.);
  
    double ht = j1.Et() + j2.Et();
    double mht = (j1 + j2).Pt();
    double dht = j1.Et() - j2.Et();
    double at = (0.5*(ht-dht))/sqrt(ht*ht-mht*mht);

    std::cout << (i==0?"[massive] ":"[massless] ")
	      << std::endl
	      << " M: " << j1.M()
	      << " Px: " << j1.Px()
	      << " Py: " << j1.Py()
	      << " Pz: " << j1.Pz()
	      << " P: " << j1.P()
	      << " E: " << j1.E()
	      << " PT: " << j1.Pt()
	      << " ET: " << j1.Et()
	      << std::endl
	      << " M: " << j2.M()
	      << " Px: " << j2.Px()
	      << " Py: " << j2.Py()
	      << " Pz: " << j2.Pz()
	      << " P: " << j2.P()
	      << " E: " << j2.E()
	      << " PT: " << j2.Pt()
	      << " ET: " << j2.Et()
	      << std::endl
	      << " ht: " << ht
	      << " dht: " << dht
	      << " mht: " << mht
	      << " at: " << at
	      << std::endl;

  }

}
Ejemplo n.º 6
0
void Node::debugPrint()
{
    if (name == "")
    {
        printf("Not printing debug information because 'name' wasn't set.\n");
        return;
    }

    QHashIterator<QString, QSet<Node*>*> i(*connections);
    while(i.hasNext())
    {
        i.next();
        QString string = i.key();
        QSet<Node*>* set = i.value();
        printf("%s FORWARD ON %s -> [ ", this->name.toStdString().c_str(), string.toStdString().c_str());

        QSetIterator<Node*> j(*set);
        while (j.hasNext())
        {
            printf("%s ", j.next()->name.toStdString().c_str());
        }
        printf("]\n");
    }

    QHashIterator<QString, QSet<Node*>*> i2(*reverseConnections);
    while(i2.hasNext())
    {
        i2.next();
        QString string2 = i2.key();
        QSet<Node*>* set2 = i2.value();
        printf("%s BACKWARD ON %s -> [ ", this->name.toStdString().c_str(), string2.toStdString().c_str());

        QSetIterator<Node*> j2(*set2);
        while (j2.hasNext())
        {
            printf("%s ", j2.next()->name.toStdString().c_str());
        }
        printf("]\n");
    }
}
Ejemplo n.º 7
0
double splineSolverNode::getJointsTotalLenght()
{
    double totalLength = 0;
    MPoint pBaseJoint, pEndJoint;
    for (int i = 0; i < joints.size(); i++)
    {
        MFnIkJoint j( joints[i]);
        pBaseJoint = j.rotatePivot(MSpace::kWorld);
        if( i == joints.size() - 1)
            //Effector Position
            pEndJoint = tran.rotatePivot(MSpace::kWorld);
        else
        {
            //get position of next joint
            MFnIkJoint j2( joints[i + 1]);
            pEndJoint = j2.rotatePivot(MSpace::kWorld);
        }
        MVector vBaseJoint(pBaseJoint[0]-pEndJoint[0], pBaseJoint[1]-pEndJoint[1], pBaseJoint[2]-pEndJoint[2]);
        totalLength += vBaseJoint.length();
    }
    return totalLength;
}
Ejemplo n.º 8
0
KoDockerManager::KoDockerManager(KoMainWindow *mainWindow)
    : QObject(mainWindow), d( new Private() )
{
    d->mainWindow = mainWindow;

    KConfigGroup cfg = KGlobal::config()->group("DockerManager");

    QStringList visibleList = cfg.readEntry("VisibleToolDockers", QStringList());

    QStringListIterator iter(visibleList);
    while (iter.hasNext()) {
        QString name = iter.next();
        //kDebug() << "name = " << name;
        d->loadDocker(name, true);
        //kDebug() << "visible = " << d->toolDockerVisibilityMap.value(name);
    }
    QStringList hiddenList = cfg.readEntry("HiddenToolDockers", QStringList());

    QStringListIterator j2(hiddenList);
    while (j2.hasNext()) {
        QString name = j2.next();
        d->loadDocker(name, false);
    }
}
Ejemplo n.º 9
0
void test_extract() {
    int counts = 0;
    tbb::flow::tuple<int,int> dont_care;
    tbb::flow::graph g;
    typedef tbb::flow::source_node<int> snode_type;
    tbb::flow::source_node<int> s0(g, source_body<int>(counts), /*is_active*/false ); 
    tbb::flow::join_node< tbb::flow::tuple<int,int>, tbb::flow::reserving > j0(g);
    tbb::flow::join_node< tbb::flow::tuple<int,int>, tbb::flow::reserving > j1(g);
    tbb::flow::join_node< tbb::flow::tuple<int,int>, tbb::flow::reserving > j2(g);
    tbb::flow::queue_node<int> q0(g);
    tbb::flow::queue_node<tbb::flow::tuple<int,int> > q1(g);
    tbb::flow::make_edge(s0, tbb::flow::get<0>(j0.input_ports()));
    /*  s0 ----+    */
    /*         | j0 */
    /*         +    */
    ASSERT(!counts, "source_node activated too soon");
    s0.activate();
    g.wait_for_all();  // should produce one value, buffer it.
    ASSERT(counts == 1, "source_node did not react to activation");

    g.reset(tbb::flow::rf_reset_bodies);
    counts = 0;
    s0.extract();
    /*  s0     +    */
    /*         | j0 */
    /*         +    */
    s0.activate();
    g.wait_for_all();  // no successors, so the body will not execute
    ASSERT(counts == 0, "source_node shouldn't forward (no successors)");
    s0.extract(tbb::flow::rf_reset_bodies);

    tbb::flow::make_edge(s0, tbb::flow::get<0>(j0.input_ports()));
    tbb::flow::make_edge(s0, tbb::flow::get<0>(j1.input_ports()));
    tbb::flow::make_edge(s0, tbb::flow::get<0>(j2.input_ports()));

    /*        /+    */
    /*       / | j0 */
    /*      /  +    */
    /*     /        */
    /*    / /--+    */
    /*  s0-/   | j1 */
    /*    \    +    */
    /*     \        */
    /*      \--+    */
    /*         | j2 */
    /*         +    */

    // do all joins appear in successor list?
    std::vector<tbb::flow::receiver<int>*> jv1;
    jv1.push_back(&(tbb::flow::get<0>(j0.input_ports())));
    jv1.push_back(&(tbb::flow::get<0>(j1.input_ports())));
    jv1.push_back(&(tbb::flow::get<0>(j2.input_ports())));
    tbb::flow::source_node<int>::successor_vector_type sv;
    s0.copy_successors(sv);
    ASSERT(lists_match(sv, jv1), "mismatch in successor list");

    tbb::flow::make_edge(q0, tbb::flow::get<1>(j2.input_ports()));
    tbb::flow::make_edge(j2, q1);
    s0.activate();

    /*        /+           */
    /*       / | j0        */
    /*      /  +           */
    /*     /               */
    /*    / /--+           */
    /*  s0-/   | j1        */
    /*    \    +           */
    /*     \               */
    /*      \--+           */
    /*         | j2----q1  */
    /*  q0-----+           */

    q0.try_put(1);
    g.wait_for_all();
    ASSERT(q1.try_get(dont_care), "join did not emit result");
    j2.extract();
    tbb::flow::make_edge(q0, tbb::flow::get<1>(j2.input_ports()));
    tbb::flow::make_edge(j2, q1);

    /*        /+           */
    /*       / | j0        */
    /*      /  +           */
    /*     /               */
    /*    / /--+           */
    /*  s0-/   | j1        */
    /*         +           */
    /*                     */
    /*         +           */
    /*         | j2----q1  */
    /*  q0-----+           */

    jv1.clear();
    jv1.push_back(&(tbb::flow::get<0>(j0.input_ports())));
    jv1.push_back(&(tbb::flow::get<0>(j1.input_ports())));
    s0.copy_successors(sv);
    ASSERT(lists_match(sv, jv1), "mismatch in successor list");

    q0.try_put(1);
    g.wait_for_all();
    ASSERT(!q1.try_get(dont_care), "extract of successor did not remove pred link");

    s0.extract();

    /*         +           */
    /*         | j0        */
    /*         +           */
    /*                     */
    /*         +           */
    /*  s0     | j1        */
    /*         +           */
    /*                     */
    /*         +           */
    /*         | j2----q1  */
    /*  q0-----+           */

    ASSERT(s0.successor_count() == 0, "successor list not cleared");
    s0.copy_successors(sv);
    ASSERT(sv.size() == 0, "non-empty successor list");

    tbb::flow::make_edge(s0, tbb::flow::get<0>(j2.input_ports()));

    /*         +           */
    /*         | j0        */
    /*         +           */
    /*                     */
    /*         +           */
    /*  s0     | j1        */
    /*    \    +           */
    /*     \               */
    /*      \--+           */
    /*         | j2----q1  */
    /*  q0-----+           */

    jv1.clear();
    jv1.push_back(&(tbb::flow::get<0>(j2.input_ports())));
    s0.copy_successors(sv);
    ASSERT(lists_match(sv, jv1), "mismatch in successor list");

    q0.try_put(1);
    g.wait_for_all();
    ASSERT(!q1.try_get(dont_care), "extract of successor did not remove pred link");
}
Ejemplo n.º 10
0
void VCharUnit::run() {
    VChar    x1('x');
    VChar    x2(0x78);
    VUNIT_ASSERT_EQUAL_LABELED(x1, 'x', "character ctor");
    VUNIT_ASSERT_EQUAL_LABELED(x2, 'x', "integer ctor");
    VUNIT_ASSERT_EQUAL_LABELED(x1, x2, "ctor equality");

    x1 = 'y';
    x2 = 0x79;
    VUNIT_ASSERT_EQUAL_LABELED(x1, 'y', "character assignment");
    VUNIT_ASSERT_EQUAL_LABELED(x2, 'y', "integer assignment");
    VUNIT_ASSERT_EQUAL_LABELED(x1, x2, "assignment equality");

    x1 = 'a';
    VUNIT_ASSERT_TRUE_LABELED(x1.isLowerCase(), "lower case");
    VUNIT_ASSERT_TRUE_LABELED(! x1.isUpperCase(), "not upper case");
    x2 = 'A';
    VUNIT_ASSERT_TRUE_LABELED(! x2.isLowerCase(), "not lower case");
    VUNIT_ASSERT_TRUE_LABELED(x2.isUpperCase(), "upper case");
    x2.toLowerCase();
    VUNIT_ASSERT_TRUE_LABELED(x2.isLowerCase(), "to lower case");
    VUNIT_ASSERT_EQUAL_LABELED(x2, x1, "to lower case equality");
    x1.toUpperCase();
    VUNIT_ASSERT_TRUE_LABELED(x1.isUpperCase(), "to upper case");
    VUNIT_ASSERT_EQUAL_LABELED(x1, 'A', "to upper case equality");

    x1 = 'b';
    VChar bigB = x1.upperCase();
    VUNIT_ASSERT_EQUAL_LABELED(bigB, 'B', "return upper case");
    VChar littleB = bigB.lowerCase();
    VUNIT_ASSERT_EQUAL_LABELED(littleB, 'b', "return lower case");
    VUNIT_ASSERT_EQUAL_LABELED(littleB.charValue(), 'b', "char value");
    VUNIT_ASSERT_EQUAL_LABELED(littleB.intValue(), 0x62, "int value");

    x1.set('c');
    VUNIT_ASSERT_EQUAL_LABELED(x1, 'c', "set char");
    x1.set(0x64);
    VUNIT_ASSERT_EQUAL_LABELED(x1, 'd', "set int");

    x1 = 'd';
    char littleD = x1;
    VUNIT_ASSERT_EQUAL_LABELED(littleD, 'd', "operator char");

    VChar    i1('i');
    VChar    i2('i');
    VChar    j1('j');
    VChar    j2('j');
    VUNIT_ASSERT_TRUE_LABELED(i1 != j1, "inequality");
    VUNIT_ASSERT_TRUE_LABELED(i1 < j1, "LT");
    VUNIT_ASSERT_TRUE_LABELED(!(i1 < i2), "not LT");
    VUNIT_ASSERT_TRUE_LABELED(j1 > i1, "GT");
    VUNIT_ASSERT_TRUE_LABELED(!(j1 > j2), "not GT");
    VUNIT_ASSERT_TRUE_LABELED(i1 <= i2, "LTE 1");
    VUNIT_ASSERT_TRUE_LABELED(i1 <= j1, "LTE 2");
    VUNIT_ASSERT_TRUE_LABELED(j1 >= j2, "GTE 1");
    VUNIT_ASSERT_TRUE_LABELED(j1 >= i1, "GTE 2");
    VUNIT_ASSERT_TRUE_LABELED(!(j1 <= i1), "not LTE");
    VUNIT_ASSERT_TRUE_LABELED(!(i1 >= j1), "not GTE");

    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase(VChar('x'), VChar('X')), "equalsIgnoreCase 1");
    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase('x', VChar('X')), "equalsIgnoreCase 2");
    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase(VChar('x'), 'X'), "equalsIgnoreCase 3");
    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase('x', 'X'), "equalsIgnoreCase 4");
    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase(VChar('5'), VChar('5')), "equalsIgnoreCase 5"); // test numbers
    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase(VChar('!'), VChar('!')), "equalsIgnoreCase 6"); // test punctuation
    VUNIT_ASSERT_TRUE_LABELED(VChar::equalsIgnoreCase(VChar(' '), VChar(' ')), "equalsIgnoreCase 7"); // test whitespace

    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase(VChar('x'), VChar('y')), "!equalsIgnoreCase 1");
    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase('x', VChar('y')), "!equalsIgnoreCase 2");
    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase(VChar('x'), 'y'), "!equalsIgnoreCase 3");
    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase('x', 'y'), "!equalsIgnoreCase 4");
    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase(VChar('5'), VChar('6')), "!equalsIgnoreCase 5"); // test numbers
    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase(VChar('!'), VChar('@')), "!equalsIgnoreCase 6"); // test punctuation
    VUNIT_ASSERT_FALSE_LABELED(VChar::equalsIgnoreCase(VChar(' '), VChar('\t')), "!equalsIgnoreCase 7"); // test whitespace

    // Test the known ranges of alpha/numeric/whitespace values.
    for (int i = 0; i < 256; ++i) {
        VChar    c(i);

        if ((i <= 0x20) || (i == 0x7F)) {
            // This is the range VChar considers "whitespace".
            this->test(
                !c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                !c.isAlpha() &&
                !c.isNumeric() &&
                !c.isAlphaNumeric() &&
                c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x2F) {
            // This is all punctuation.
            this->test(
                !c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                !c.isAlpha() &&
                !c.isNumeric() &&
                !c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x39) {
            // This is 0 thru 9.
            this->test(
                !c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                !c.isAlpha() &&
                c.isNumeric() &&
                c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x40) {
            // This is all punctuation.
            this->test(
                !c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                !c.isAlpha() &&
                !c.isNumeric() &&
                !c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x5A) {
            // This is A thru Z.
            this->test(
                !c.isLowerCase() &&
                c.isUpperCase() &&
                (c.intValue() == i) &&
                c.isAlpha() &&
                !c.isNumeric() &&
                c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x60) {
            // This is all punctuation.
            this->test(
                !c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                !c.isAlpha() &&
                !c.isNumeric() &&
                !c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x7A) {
            // This is a thru z.
            this->test(
                c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                c.isAlpha() &&
                !c.isNumeric() &&
                c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else if (i <= 0x7E) {
            // This is all punctuation.
            this->test(
                !c.isLowerCase() &&
                !c.isUpperCase() &&
                (c.intValue() == i) &&
                !c.isAlpha() &&
                !c.isNumeric() &&
                !c.isAlphaNumeric() &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        } else { // (we already checked 0x7F) so 0x80 <= i <= 0xFF
            // Properties of stuff at 0x80 and higher are not well-defined
            // and may vary based on the platform's ideas about upper case,
            // lower case, alphanumeric-ness, etc. Just test the basics.
            this->test(
                (c.intValue() == i) &&
                !c.isWhitespace(),
                VSTRING_FORMAT("%d char properties", i));
        }
    }

}
Ejemplo n.º 11
0
int main (int argc, char** argv)
{
  UnitTest t (14);

  try
  {
    // Basic parsing tests.
    std::string input = "{}";
    std::cout << "-- j1 -------------------\n"
              << "input: " << input << "\n";
    JSON j1 (input);
    j1.tree ()->dump ();

    input = "{\"name\":123}";
    std::cout << "-- j2 -------------------\n"
              << "input: " << input << "\n";
    JSON j2 (input);
    j2.tree ()->dump ();

    input = "{\"name\":123, \"array\":[1,2,3.4], \"map\":{\"m1\":\"v1\", \"m2\":\"v2\"}}";
    std::cout << "-- j3 -------------------\n"
              << "input: " << input << "\n";
    JSON j3 (input);
    j3.tree ()->dump ();

    // Sample ticket as a parsing test.
    input = "{\n"
            "\"ticket\": { \"type\":\"add\", \"client\":\"taskwarrior 2.x\"},\n"
            "\"auth\":   { \"user\":\"paul\", \"org\":\"gbf\", \"key\":\".........\",\n"
            "            \"locale\":\"en-US\" },\n"
            "\n"
            "\"add\":    { \"description\":\"Wash the dog\",\n"
            "            \"project\":\"home\",\n"
            "            \"due\":\"20101101T000000Z\" }\n"
            "}";
    std::cout << "-- j4 -------------------\n"
              << "input: " << input << "\n";
    JSON j4 (input);
    j4.tree ()->dump ();
    std::cout << "-------------------------\n";

    // Regular unit tests.
    t.is (JSON::encode ("1\b2"), "1\\b2",  "JSON::encode \\b -> \\\\b");
    t.is (JSON::decode ("1\\b2"), "1\b2",  "JSON::decode \\\\b -> \\b");

    t.is (JSON::encode ("1\n2"), "1\\n2",  "JSON::encode \\n -> \\\\n");
    t.is (JSON::decode ("1\\n2"), "1\n2",  "JSON::decode \\\\n -> \\n");

    t.is (JSON::encode ("1\r2"), "1\\r2",  "JSON::encode \\r -> \\\\r");
    t.is (JSON::decode ("1\\r2"), "1\r2",  "JSON::decode \\\\r -> \\r");

    t.is (JSON::encode ("1\t2"), "1\\t2",  "JSON::encode \\t -> \\\\t");
    t.is (JSON::decode ("1\\t2"), "1\t2",  "JSON::decode \\\\t -> \\t");

    t.is (JSON::encode ("1\\2"), "1\\\\2", "JSON::encode \\ -> \\\\");
    t.is (JSON::decode ("1\\\\2"), "1\\2", "JSON::decode \\\\ -> \\");

    t.is (JSON::encode ("1\x2"), "1\x2",   "JSON::encode \\x -> \\x (NOP)");
    t.is (JSON::decode ("1\x2"), "1\x2",   "JSON::decode \\x -> \\x (NOP)");

    t.is (JSON::encode ("1€2"), "1€2",     "JSON::encode € -> €");
    t.is (JSON::decode ("1\\u20ac2"),      "1€2", "JSON::decode \\u20ac -> €");

/*
  {
    "ticket":
    {
      "type":"synch",
      "client":"taskd-test-suite 1.0"
    },

    "synch":
    {
      "user":
      {
        "data":
        [
          {
            "uuid":"11111111-1111-1111-1111-111111111111",
            "status":"pending",
            "description":"This is a test",
            "entry":"20110111T124000Z"
          }
        ],
        "synch":"key"
      }
    },
  
    "auth":
    {
      "org":"gbf",
      "user":"******",
      "key":"K",
      "locale":"en-US"
    }
  }
*/
    input = "{\"ticket\":{\"type\":\"synch\",\"client\":\"taskd-test-suite 1.0\"},\"synch\":{\"user\":{\"data\":[{\"uuid\":\"11111111-1111-1111-1111-111111111111\",\"status\":\"pending\",\"description\":\"This is a test\",\"entry\":\"20110111T124000Z\"}],\"synch\":\"key\"}},\"auth\":{\"org\":\"gbf\",\"user\":\"Paul Beckingham\",\"key\":\"K\",\"locale\":\"en-US\"}}";
    std::cout << "-- j4 -------------------\n"
              << "input: " << input << "\n";
    JSON j5 (input);
    j5.tree ()->dump ();
  }

  catch (std::string& e) {t.diag (e);}

  return 0;
}
Ejemplo n.º 12
0
MStatus splineSolverNode::doSimpleSolver()
//
// Solve single joint in the x-y plane
//
// - first it calculates the angle between the handle and the end-effector.
// - then it determines which way to rotate the joint.
//
{
    //Do Real Solve
    //
    MStatus stat;
    float curCurveLength = curveFn.length();
    MPlug crvLengPlug = fnHandle.findPlug("cvLen");
    double initCurveLength = crvLengPlug.asDouble();
    //Twist
    MPlug twistRamp = fnHandle.findPlug("twistRamp");
    MRampAttribute curveAttribute( twistRamp, &stat );
    MPlug startTwistPlug = fnHandle.findPlug("strtw");
    double startTwist = startTwistPlug.asDouble();
    MPlug endTwistPlug = fnHandle.findPlug("endtw");
    double endTwist = endTwistPlug.asDouble();
    //Scale Ramp
    MPlug scaleRamp = fnHandle.findPlug("scaleRamp");
    MRampAttribute curveScaleAttribute( scaleRamp, &stat );
    //Roll
    MPlug rollPlug = fnHandle.findPlug("roll");
    double roll = rollPlug.asDouble();
    MPlug strPlug = fnHandle.findPlug("str");
    float stretchRatio = strPlug.asDouble();
    float normCrvLength = curCurveLength / initCurveLength;
    double scale[3] = {1 +stretchRatio*(normCrvLength -1), 1, 1};
    //Get Anchor Position
    MPlug ancPosPlug = fnHandle.findPlug("ancp");
    double anchorPos = ancPosPlug.asDouble();
    MPlug jointsTotLengthPlug = fnHandle.findPlug("jsLen");
    double jointsTotalLength = jointsTotLengthPlug.asDouble();
    double difLengthCurveJoints = curCurveLength - (jointsTotalLength * scale[0]);
    float startLength = 0.0 + anchorPos*( difLengthCurveJoints );
    float parm = curveFn.findParamFromLength( startLength );
    MPoint pBaseJoint, pEndJoint;
    curveFn.getPointAtParam( parm, pBaseJoint );
    //get Init normal
    MPlug initNormalPlug = fnHandle.findPlug("norm");
    double nx = initNormalPlug.child(0).asDouble();
    double ny = initNormalPlug.child(1).asDouble();
    double nz = initNormalPlug.child(2).asDouble();
    MVector eyeUp( nx, ny, nz );
    //get Init Tangent
    MPlug initTangentPlug = fnHandle.findPlug("tang");
    double tx = initTangentPlug.child(0).asDouble();
    double ty = initTangentPlug.child(1).asDouble();
    double tz = initTangentPlug.child(2).asDouble();
    MVector eyeV( tx, ty, tz );

    MFnIkJoint j( joints[0] );
    j.setTranslation( MVector( pBaseJoint ), MSpace::kWorld );
    float jointRotPercent = 1.0/joints.size();
    float currJointRot = 0;
    float prevTwist = 0;
    double angle;
    //j.setScale(scale);
    for (int i = 0; i < joints.size(); i++)
    {
        MFnIkJoint j( joints[i]);
        pBaseJoint = j.rotatePivot(MSpace::kWorld);
        //Calculate Scale
        float scaleValue;
        curveScaleAttribute.getValueAtPosition(currJointRot, scaleValue, &stat);
        //if ( scale[0] >= 1 ) // Stretch
        scale[1] = 1 + scaleValue * ( 1 - scale[0] );
        /*
        else //Squash
        	scale[1] = 1 + scaleValue * ( 1.0 - scale[0] );
        */
        if (scale[1] < 0)
            scale[1] = 0;
        scale[2] = scale[1];
        j.setScale(scale);
        //j.setRotation( rot, j.rotationOrder()  );
        if( i == joints.size() - 1)
            //Effector Position
            pEndJoint = tran.rotatePivot(MSpace::kWorld);
        else
        {
            //get position of next joint
            MFnIkJoint j2( joints[i + 1]);
            pEndJoint = j2.rotatePivot(MSpace::kWorld);
        }
        MVector vBaseJoint(pBaseJoint[0]-pEndJoint[0], pBaseJoint[1]-pEndJoint[1], pBaseJoint[2]-pEndJoint[2]);
        startLength += vBaseJoint.length();
        MVector eyeAim(1.0,0.0,0.0);
        MPoint pFinalPos;
        float parm = curveFn.findParamFromLength( startLength );
        //Aim to final Pos
        curveFn.getPointAtParam( parm, pFinalPos, MSpace::kWorld );
        MVector eyeU(pBaseJoint[0]-pFinalPos[0], pBaseJoint[1]-pFinalPos[1], pBaseJoint[2]-pFinalPos[2]);
        eyeU.normalize();
        MVector eyeW( eyeU ^ eyeV );
        eyeW.normalize();
        eyeV = eyeW ^ eyeU;
        MQuaternion qU( -eyeAim, eyeU );

        MVector upRotated( eyeUp.rotateBy( qU ));
        angle = acos( upRotated*eyeV );

        //Calculate Twist
        {
            float twistValue;
            curveAttribute.getValueAtPosition(currJointRot, twistValue, &stat);
            double rotVal = (1-twistValue)*startTwist + twistValue*endTwist;
            angle += MAngle(rotVal, MAngle::kDegrees).asRadians();
            currJointRot += jointRotPercent;
        }
        //Calculate Roll
        angle += roll;

        MQuaternion qV(angle, eyeU);

        MQuaternion q(qU*qV);

        j.setRotation( q, MSpace::kWorld );
    }

    return MS::kSuccess;
}
Ejemplo n.º 13
0
Matrix TrackThread::getInterpolatedTensor( int id, float inx, float iny, float inz )
{
    float x = inx / m_dx;
    float y = iny / m_dy;
    float z = inz / m_dz;

    int x0 = (int) x;
    int y0 = (int) y;
    int z0 = (int) z;

    float xd = x - x0;
    float yd = y - y0;
    float zd = z - z0;

    int id_x0y0z0 = id;
    int id_x1y0z0 = min( m_blockSize - 1, id + 1 );
    int id_x0y1z0 = min( m_blockSize - 1, id + m_nx );
    int id_x1y1z0 = min( m_blockSize - 1, id + m_nx + 1 );
    int id_x0y0z1 = min( m_blockSize - 1, id + m_nx * m_ny );
    int id_x1y0z1 = min( m_blockSize - 1, id + m_nx * m_ny + 1 );
    int id_x0y1z1 = min( m_blockSize - 1, id + m_nx * m_ny + m_nx );
    int id_x1y1z1 = min( m_blockSize - 1, id + m_nx * m_ny + m_nx + 1 );

    Matrix i1( 3, 3 );
    Matrix i2( 3, 3 );
    Matrix j1( 3, 3 );
    Matrix j2( 3, 3 );
    Matrix w1( 3, 3 );
    Matrix w2( 3, 3 );
    Matrix iv( 3, 3 );

    for( int i = 1; i < 4; ++i )
    {
        for ( int j = 1; j < 4; ++j )
        {
            i1( i, j ) = m_logTensors->at( id_x0y0z0 )( i, j ) * ( 1.0 - zd ) + m_logTensors->at( id_x0y0z1 )( i, j ) * zd;
            i2( i, j ) = m_logTensors->at( id_x0y1z0 )( i, j ) * ( 1.0 - zd ) + m_logTensors->at( id_x0y1z1 )( i, j ) * zd;
            j1( i, j ) = m_logTensors->at( id_x1y0z0 )( i, j ) * ( 1.0 - zd ) + m_logTensors->at( id_x1y0z1 )( i, j ) * zd;
            j2( i, j ) = m_logTensors->at( id_x1y1z0 )( i, j ) * ( 1.0 - zd ) + m_logTensors->at( id_x1y1z1 )( i, j ) * zd;
        }
    }

    for( int i = 1; i < 4; ++i )
    {
        for ( int j = 1; j < 4; ++j )
        {
            w1( i, j ) = i1( i, j ) * ( 1.0 - yd ) + i2( i, j ) * yd;
            w2( i, j ) = j1( i, j ) * ( 1.0 - yd ) + j2( i, j ) * yd;
        }
    }

    for( int i = 1; i < 4; ++i )
    {
        for ( int j = 1; j < 4; ++j )
        {
            iv( i, j ) = w1( i, j ) * ( 1.0 - xd ) + w2( i, j ) * xd;
        }
    }

    return FMath::expT( iv );
}
Ejemplo n.º 14
0
int main(int argc, char **argv) {


  MassVariations theMass;

  TFile *f = new TFile(argv[1]);
  TTree *tree = (TTree *)f->Get("events");
  setSetBranchAddresses(tree);

  Long64_t nentries = tree->GetEntriesFast();

  Long64_t nb = 0;

  Long64_t withSolutions = 0, withoutSolutions = 0;

  for (Long64_t jentry=0; jentry<nentries;jentry++) {

      nb = tree->GetEntry(jentry);
    
      TLorentzVector l1(0, 0, 0, 0);
      l1.SetPtEtaPhiM(ev.ptlep1, ev.etalep1, ev.philep1, ev.mlep1);
      TLorentzVector l2(0, 0, 0, 0);
      l2.SetPtEtaPhiM(ev.ptlep2, ev.etalep2, ev.philep2, ev.mlep2);
      TLorentzVector j1(0, 0, 0, 0);
      j1.SetPtEtaPhiM(ev.ptb1, ev.etab1, ev.phib1, ev.mb1);
      TLorentzVector j2(0, 0, 0, 0);
      j2.SetPtEtaPhiM(ev.ptb2, ev.etab2, ev.phib2, ev.mb2);
      TLorentzVector n1(0, 0, 0, 0);
      n1.SetPtEtaPhiM(ev.ptnu1, ev.etanu1, ev.phinu1, ev.mnu1);
      TLorentzVector n2(0, 0, 0, 0);
      n2.SetPtEtaPhiM(ev.ptnu2, ev.etanu2, ev.phinu2, ev.mnu2);
   
 
      std::vector<TLorentzVector> jets;
      jets.push_back(j1);
      jets.push_back(j2);
      std::vector<Float_t> unc;
      unc.push_back(0.01);
      unc.push_back(0.01);
   
      //TVector2 MET(ev.ptMET*cos(ev.phiMET), ev.ptMET*sin(ev.phiMET));
      TVector2 MET(ev.ptMETNu*cos(ev.phiMETNu), ev.ptMETNu*sin(ev.phiMETNu));
      std::vector<TLorentzVector> nu1, nu2;


      theMass.performAllVariations(1, 1, 1, l1, l2, jets, unc, MET, nu1, nu2);

      if(nu1.size() != 0) withSolutions++;
      else withoutSolutions++;
 
      int debug2 = 1;
      if(debug2 == 1) {
          std::cout << "[MassVariations] Matched found with " << nu1.size() << " solutions." << std::endl;
          if(nu1.size() != 0) {
              for(Int_t i = 0; i < nu1.size(); i++) {
                  std::cout << "[MassVariations] Solution " << i << " ";
                  nu1[i].Print();
                  n1.Print();
                  nu2[i].Print();
                  n2.Print();
                  std::cout << std::endl;   
              }
          }
      }
  }  

  f->Close();

  std::cout << "Total number of events: " << withSolutions + withoutSolutions << std::endl;
  std::cout << "The top was reconstructed in " << 100.0*((float)withSolutions)/((float)withSolutions + withoutSolutions) << "% of the times" << std::endl;


  return 1;

}
Ejemplo n.º 15
0
Matrix TWCThread::getInterpolatedTensor( int &id, float &inx, float &iny, float &inz, float &dirX, float &dirY, float &dirZ )
{
    float x = inx / m_dx;
    float y = iny / m_dy;
    float z = inz / m_dz;

    int x0 = (int) x;
    int y0 = (int) y;
    int z0 = (int) z;

    float xd = x - x0;
    float yd = y - y0;
    float zd = z - z0;

    int id_x0y0z0 = id;
    int id_x1y0z0 = min( m_blockSize - 1, id + 1 );
    int id_x0y1z0 = min( m_blockSize - 1, id + m_nx );
    int id_x1y1z0 = min( m_blockSize - 1, id + m_nx + 1 );
    int id_x0y0z1 = min( m_blockSize - 1, id + m_nx * m_ny );
    int id_x1y0z1 = min( m_blockSize - 1, id + m_nx * m_ny + 1 );
    int id_x0y1z1 = min( m_blockSize - 1, id + m_nx * m_ny + m_nx );
    int id_x1y1z1 = min( m_blockSize - 1, id + m_nx * m_ny + m_nx + 1 );

    QVector<Matrix>* lt_x0y0z0 = testAngle( id_x0y0z0, dirX, dirY, dirZ );
    QVector<Matrix>* lt_x1y0z0 = testAngle( id_x1y0z0, dirX, dirY, dirZ );
    QVector<Matrix>* lt_x0y1z0 = testAngle( id_x0y1z0, dirX, dirY, dirZ );
    QVector<Matrix>* lt_x1y1z0 = testAngle( id_x1y1z0, dirX, dirY, dirZ );
    QVector<Matrix>* lt_x0y0z1 = testAngle( id_x0y0z1, dirX, dirY, dirZ );
    QVector<Matrix>* lt_x1y0z1 = testAngle( id_x1y0z1, dirX, dirY, dirZ );
    QVector<Matrix>* lt_x0y1z1 = testAngle( id_x0y1z1, dirX, dirY, dirZ );
    QVector<Matrix>* lt_x1y1z1 = testAngle( id_x1y1z1, dirX, dirY, dirZ );

    Matrix i1( 3, 3 );
    Matrix i2( 3, 3 );
    Matrix j1( 3, 3 );
    Matrix j2( 3, 3 );
    Matrix w1( 3, 3 );
    Matrix w2( 3, 3 );
    Matrix iv( 3, 3 );

    for( int i = 1; i < 4; ++i )
    {
        for ( int j = 1; j < 4; ++j )
        {
            i1( i, j ) = lt_x0y0z0->at( id_x0y0z0 )( i, j ) * ( 1.0 - zd ) + lt_x0y0z1->at( id_x0y0z1 )( i, j ) * zd;
            i2( i, j ) = lt_x0y1z0->at( id_x0y1z0 )( i, j ) * ( 1.0 - zd ) + lt_x0y1z1->at( id_x0y1z1 )( i, j ) * zd;
            j1( i, j ) = lt_x1y0z0->at( id_x1y0z0 )( i, j ) * ( 1.0 - zd ) + lt_x1y0z1->at( id_x1y0z1 )( i, j ) * zd;
            j2( i, j ) = lt_x1y1z0->at( id_x1y1z0 )( i, j ) * ( 1.0 - zd ) + lt_x1y1z1->at( id_x1y1z1 )( i, j ) * zd;
        }
    }

    for( int i = 1; i < 4; ++i )
    {
        for ( int j = 1; j < 4; ++j )
        {
            w1( i, j ) = i1( i, j ) * ( 1.0 - yd ) + i2( i, j ) * yd;
            w2( i, j ) = j1( i, j ) * ( 1.0 - yd ) + j2( i, j ) * yd;
        }
    }

    for( int i = 1; i < 4; ++i )
    {
        for ( int j = 1; j < 4; ++j )
        {
            iv( i, j ) = w1( i, j ) * ( 1.0 - xd ) + w2( i, j ) * xd;
        }
    }

    return FMath::expT( iv );
}