Exemplo n.º 1
0
TEST(QiOs, timeValCtor)
{
  qi::os::timeval t0 = qi::os::timeval();
  // t0 members are initialized to 0
  EXPECT_EQ(0, t0.tv_sec);
  EXPECT_EQ(0, t0.tv_usec);
  qi::os::timeval t1;
  // t1 members are initialized to 0
  EXPECT_EQ(0, t1.tv_sec);
  EXPECT_EQ(0, t1.tv_usec);

  // t2 members are not normalized
  qi::os::timeval t2(-1, -2);
  EXPECT_EQ(-1, t2.tv_sec);
  EXPECT_EQ(-2, t2.tv_usec);

  qi::Seconds s(123456789);
  qi::MicroSeconds us(123456);
  qi::NanoSeconds ns(789);
  qi::Duration d_us(s + us);
  qi::Duration d_ns(d_us + ns);
  qi::int64_t normalized_s = s.count();
  qi::int64_t normalized_us = us.count();

  // positive
  {
    qi::os::timeval tv0(d_us);
    EXPECT_EQ(normalized_s, tv0.tv_sec);
    EXPECT_EQ(normalized_us, tv0.tv_usec);

    qi::Duration d_back = qi::Seconds(tv0.tv_sec) +
                          qi::MicroSeconds(tv0.tv_usec);
    EXPECT_TRUE(d_us - d_back < qi::MicroSeconds(1));
    qi::os::timeval tv1(d_us);
    EXPECT_EQ(normalized_s, tv1.tv_sec);
    EXPECT_EQ(normalized_us, tv1.tv_usec);
  }
  // negative
  d_us = -d_us;
  d_ns = -d_ns;
  normalized_s = -s.count() - 1;
  normalized_us = -us.count() + 1000000;
  {
    qi::os::timeval tv0(d_us);
    EXPECT_EQ(normalized_s, tv0.tv_sec);
    EXPECT_EQ(normalized_us, tv0.tv_usec);

    qi::Duration d_back = qi::Seconds(tv0.tv_sec) +
                          qi::MicroSeconds(tv0.tv_usec);
    EXPECT_TRUE(d_us - d_back < qi::MicroSeconds(1));
    qi::os::timeval tv1(d_us);
    EXPECT_EQ(normalized_s, tv1.tv_sec);
    EXPECT_EQ(normalized_us, tv1.tv_usec);
  }
}
Exemplo n.º 2
0
// find a rotation that is the combination of two other
// rotations. This is used to allow us to add an overall board
// rotation to an existing rotation of a sensor such as the compass
// Note that this relies the set of rotations being complete. The
// optional 'found' parameter is for the test suite to ensure that it is.
enum Rotation rotation_combination(enum Rotation r1, enum Rotation r2, bool *found)
{
    Vector3f tv1, tv2;
    enum Rotation r;
    tv1(1,2,3);
    tv1.rotate(r1);
    tv1.rotate(r2);

    for (r=ROTATION_NONE; r<ROTATION_MAX;
         r = (enum Rotation)((uint8_t)r+1)) {
        Vector3f diff;
        tv2(1,2,3);
        tv2.rotate(r);
        diff = tv1 - tv2;
        if (diff.length() < 1.0e-6f) {
            // we found a match
            if (found) {
                *found = true;
            }
            return r;
        }
    }

    // we found no matching rotation. Someone has edited the
    // rotations list and broken its completeness property ...
    if (found) {
        *found = false;
    }
    return ROTATION_NONE;
}
Exemplo n.º 3
0
bool Wall::intersect(vect2d ov1, vect2d ov2, vect2d& hit)
{

    // Transform both points into the wall's coordinate space.
    vect2d tv1 (j * (ov1-v1), ~j * (ov1-v1));
    vect2d tv2 (j * (ov2-v1), ~j * (ov2-v1));

    double xintercept;

    // If both points are on the same side of the wall, the line does
    // not intersect.
    if ((tv1.y > 0) == (tv2.y > 0)) {
	return false;
    }

    xintercept = tv1.x - ((tv2.x - tv1.x) / (tv2.y - tv1.y)) * tv1.y;
    // If the x intercept is within the bounds of the wall, transform
    // the intersection point back to normal coordinate space and
    // return true.
    if (xintercept >= 0 && xintercept <= len) {
	hit = j * xintercept + v1;
	return true;
    }
    return false;
}
SparseVector Basis::eval(const DenseVector &x) const
{
    // Set correct starting size and values: one element of 1.
    SparseMatrix tv1(1,1);  //tv1.resize(1);
    tv1.reserve(1);
    tv1.insert(0,0) = 1;
    SparseMatrix tv2 = tv1;

    // Evaluate all basisfunctions in each dimension i and generate the tensor product of the function values
    for (int dim = 0; dim < x.size(); dim++)
    {
        SparseVector xi = bases.at(dim).evaluate(x(dim));

        // Avoid matrix copy
        if (dim % 2 == 0)
        {
            tv1 = kroneckerProduct(tv2, xi); // tv1 = tv1 x xi
        }
        else
        {
            tv2 = kroneckerProduct(tv1, xi); // tv2 = tv1 x xi
        }
    }

    // Return correct vector
    if (tv1.size() == numBasisFunctions())
    {
        return tv1;
    }
    return tv2;
}
Exemplo n.º 5
0
		void Circle::appendBoundary(const IModel* p) {
			Circle c2;
			p->im_getBVolume(c2);
			Vec2 toC2 = c2.vCenter - vCenter;
			float lensq = toC2.len_sq();
			if(lensq >= ZEROVEC_LENGTH_SQ) {
				toC2 *= spn::RSqrt(lensq);
				Vec2 tv(support(toC2) - c2.support(-toC2));
				float r_min = std::min(fRadius, c2.fRadius);
				if(tv.dot(toC2) < 0 ||
					tv.len_sq() < spn::Square(r_min*2))
				{
					// 新たな円を算出
					Vec2 tv0(vCenter - toC2*fRadius),
						 tv1(c2.vCenter + toC2*c2.fRadius);
					fRadius = tv0.distance(tv1) * .5f;
					vCenter = (tv0+tv1) * .5f;
				} else {
					// 円が内包されている
					if(fRadius < c2.fRadius) {
						fRadius = c2.fRadius;
						vCenter = c2.vCenter;
					}
				}
			} else {
				// 円の中心が同じ位置にある
				fRadius = std::max(c2.fRadius, fRadius);
			}
		}
Exemplo n.º 6
0
BOOST_AUTO_TEST_CASE_TEMPLATE(time_value_test5, T, test_types) {
	lsd::time_value tv1(136416213.5), tv2;
	tv2 += (tv1 + 1.5).as_double();

	BOOST_CHECK_EQUAL(tv2 == tv1 + 1.5, true);
	BOOST_CHECK_EQUAL(tv2 != tv1 + 1.5, false);
	BOOST_CHECK_EQUAL(tv2 > tv1, true);
	BOOST_CHECK_EQUAL(tv1 < tv2, true);
}
Exemplo n.º 7
0
BOOST_AUTO_TEST_CASE_TEMPLATE(time_value_test4, T, test_types) {
	lsd::time_value tv1(136416213.5), tv2;
	tv2 = tv1 + 21.0003;

	BOOST_CHECK_EQUAL(tv1.days(), tv2.days());
	BOOST_CHECK_EQUAL(tv1.hours(), tv2.hours());
	BOOST_CHECK_EQUAL(tv1.minutes(), tv2.minutes());
	BOOST_CHECK_EQUAL(tv1.seconds() == tv2.seconds(), false);
	BOOST_CHECK_EQUAL(tv1.milliseconds(), tv2.milliseconds() - 21000);
	BOOST_CHECK_EQUAL(tv1.microseconds() == tv2.microseconds(), false);
}