units
Use physical dimensions at compile-time or run-time.
Functions
eigen-compat-test.cpp File Reference

Test-cases for compatibility with Eigen. More...

#include "../vnix/units.hpp"
#include "catch.hpp"
#include <eigen3/Eigen/Geometry>
Include dependency graph for eigen-compat-test.cpp:

Go to the source code of this file.

Functions

 TEST_CASE ("Matrix methods can be called.","[dimval]")
 

Detailed Description

Test-cases for compatibility with Eigen.

License: BSD three-clause; see LICENSE.

Definition in file eigen-compat-test.cpp.

Function Documentation

TEST_CASE ( "Matrix methods can be called."  ,
""  [dimval] 
)

Definition at line 13 of file eigen-compat-test.cpp.

13  {
14  using namespace Eigen;
15  using namespace vnix::units;
16  using namespace vnix::units::flt;
17  AngleAxisf r(M_PI / 6, Vector3f(0, 0, 1));
18  auto f = newtons(Vector3f(1, 0, 0));
19  REQUIRE((f[0] / N).to_number() == 1.0);
20  REQUIRE((f[1] / N).to_number() == 0.0);
21  REQUIRE((f[2] / N).to_number() == 0.0);
22  auto f2 = r.toRotationMatrix() * f;
23  REQUIRE((f2[0] / N).to_number() == Approx(cos(M_PI / 6)));
24  REQUIRE((f2[1] / N).to_number() == Approx(sin(M_PI / 6)));
25  REQUIRE((f2[2] / N).to_number() == 0.0);
26  auto d = meters(Vector3f(0, 1, 0));
27  REQUIRE((d[0] / m).to_number() == 0.0);
28  REQUIRE((d[1] / m).to_number() == 1.0);
29  REQUIRE((d[2] / m).to_number() == 0.0);
30  auto v = d / (2.5_s);
31  REQUIRE((v[0] / (m / s)).to_number() == Approx(0.0));
32  REQUIRE((v[1] / (m / s)).to_number() == Approx(0.4));
33  REQUIRE((v[2] / (m / s)).to_number() == Approx(0.0));
34  flt::time t = 3.0_s;
35  auto d2 = d + v * t;
36  REQUIRE((d2[0] / m).to_number() == Approx(0.0));
37  REQUIRE((d2[1] / m).to_number() == Approx(2.2));
38  REQUIRE((d2[2] / m).to_number() == Approx(0.0));
39  auto e1 = f2.dot(d2);
40  REQUIRE((e1/J).to_number() == Approx(sin(M_PI / 6) * 2.2));
41  auto e2 = f2.cross(d2);
42  REQUIRE((e2[0]/J).to_number() == Approx(0.0));
43  REQUIRE((e2[1]/J).to_number() == Approx(0.0));
44  REQUIRE((e2[2]/J).to_number() == Approx(cos(M_PI / 6) * 2.2));
45 }
constexpr auto N
Constant-expression symbol for N.
Definition: units.hpp:2008
Definition: number.hpp:11
Single-precision dimensions and units.
Definition: units.hpp:1663
constexpr auto s
Constant-expression symbol for s.
Definition: units.hpp:1825
constexpr auto J
Constant-expression symbol for J.
Definition: units.hpp:2062
constexpr auto meters(T v)
Produce dimensioned quantity from number of meters.
Definition: units.hpp:1317
constexpr auto m
Constant-expression symbol for m.
Definition: units.hpp:1675
Model of a statically dimensioned physical quantity.
Definition: dimval.hpp:24
Classes and functions supporting a model of physically dimensioned quantities.
constexpr auto newtons(T v)
Produce dimensioned quantity from number of newtons.
Definition: units.hpp:1533