MCPcopy Create free account
hub / github.com/Derious/cuMPC / alignedboxRotatable

Function alignedboxRotatable

dependence/eigen-3.4.0/test/geo_alignedbox.cpp:234–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232}
233
234template<typename BoxType, typename Rotation> void alignedboxRotatable(
235 const BoxType& box,
236 Rotation (*rotate)(typename NumTraits<typename BoxType::Scalar>::NonInteger /*_angle*/))
237{
238 alignedboxTranslatable(box);
239
240 typedef typename BoxType::Scalar Scalar;
241 typedef typename NumTraits<Scalar>::NonInteger NonInteger;
242 typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType;
243 typedef Transform<Scalar, BoxType::AmbientDimAtCompileTime, Isometry> IsometryTransform;
244 typedef Transform<Scalar, BoxType::AmbientDimAtCompileTime, Affine> AffineTransform;
245
246 const VectorType Zero = VectorType::Zero();
247 const VectorType Ones = VectorType::Ones();
248 const VectorType UnitX = VectorType::UnitX();
249 const VectorType UnitY = VectorType::UnitY();
250 // this is vector (0, 0, -1, -1, -1, ...), i.e. with zeros at first and second dimensions
251 const VectorType UnitZ = Ones - UnitX - UnitY;
252
253 // in this kind of comments the 3D case values will be illustrated
254 // box((-1, -1, -1), (1, 1, 1))
255 BoxType a(-Ones, Ones);
256
257 // to allow templating this test for both 2D and 3D cases, we always set all
258 // but the first coordinate to the same value; so basically 3D case works as
259 // if you were looking at the scene from top
260
261 VectorType minPoint = -2 * Ones;
262 minPoint[0] = -3;
263 VectorType maxPoint = Zero;
264 maxPoint[0] = -1;
265 BoxType c(minPoint, maxPoint);
266 // box((-3, -2, -2), (-1, 0, 0))
267
268 IsometryTransform tf2 = IsometryTransform::Identity();
269 // for some weird reason the following statement has to be put separate from
270 // the following rotate call, otherwise precision problems arise...
271 Rotation rot = rotate(NonInteger(EIGEN_PI));
272 tf2.rotate(rot);
273
274 c.transform(tf2);
275 // rotate by 180 deg around origin -> box((1, 0, -2), (3, 2, 0))
276
277 VERIFY_IS_APPROX(c.sizes(), a.sizes());
278 VERIFY_IS_APPROX((c.min)(), UnitX - UnitZ * Scalar(2));
279 VERIFY_IS_APPROX((c.max)(), UnitX * Scalar(3) + UnitY * Scalar(2));
280
281 rot = rotate(NonInteger(EIGEN_PI / 2));
282 tf2.setIdentity();
283 tf2.rotate(rot);
284
285 c.transform(tf2);
286 // rotate by 90 deg around origin -> box((-2, 1, -2), (0, 3, 0))
287
288 VERIFY_IS_APPROX(c.sizes(), a.sizes());
289 VERIFY_IS_APPROX((c.min)(), Ones * Scalar(-2) + UnitY * Scalar(3));
290 VERIFY_IS_APPROX((c.max)(), UnitY * Scalar(3));
291

Callers 1

Calls 5

alignedboxTranslatableFunction · 0.85
transformMethod · 0.80
sizesMethod · 0.80
linearExtMethod · 0.80
setIdentityMethod · 0.45

Tested by

no test coverage detected