GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: test/capsule_box_1.cpp Lines: 45 45 100.0 %
Date: 2024-02-09 12:57:42 Branches: 196 392 50.0 %

Line Branch Exec Source
1
/*
2
 * Software License Agreement (BSD License)
3
 *
4
 *  Copyright (c) 2014-2016, CNRS-LAAS and AIST
5
 *  All rights reserved.
6
 *
7
 *  Redistribution and use in source and binary forms, with or without
8
 *  modification, are permitted provided that the following conditions
9
 *  are met:
10
 *
11
 *   * Redistributions of source code must retain the above copyright
12
 *     notice, this list of conditions and the following disclaimer.
13
 *   * Redistributions in binary form must reproduce the above
14
 *     copyright notice, this list of conditions and the following
15
 *     disclaimer in the documentation and/or other materials provided
16
 *     with the distribution.
17
 *   * Neither the name of CNRS-LAAS and AIST nor the names of its
18
 *     contributors may be used to endorse or promote products derived
19
 *     from this software without specific prior written permission.
20
 *
21
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
 *  POSSIBILITY OF SUCH DAMAGE.
33
 */
34
35
/** \author Florent Lamiraux */
36
37
#define BOOST_TEST_MODULE FCL_GEOMETRIC_SHAPES
38
#include <boost/test/included/unit_test.hpp>
39
40
#define CHECK_CLOSE_TO_0(x, eps) BOOST_CHECK_CLOSE((x + 1.0), (1.0), (eps))
41
42
#include <cmath>
43
#include <hpp/fcl/distance.h>
44
#include <hpp/fcl/math/transform.h>
45
#include <hpp/fcl/collision.h>
46
#include <hpp/fcl/collision_object.h>
47
#include <hpp/fcl/shape/geometric_shapes.h>
48
49
#include "utility.h"
50
51
















4
BOOST_AUTO_TEST_CASE(distance_capsule_box) {
52
  using hpp::fcl::CollisionGeometryPtr_t;
53
  // Capsule of radius 2 and of height 4
54

4
  CollisionGeometryPtr_t capsuleGeometry(new hpp::fcl::Capsule(2., 4.));
55
  // Box of size 1 by 2 by 4
56

4
  CollisionGeometryPtr_t boxGeometry(new hpp::fcl::Box(1., 2., 4.));
57
58
  // Enable computation of nearest points
59
2
  hpp::fcl::DistanceRequest distanceRequest(true, 0, 0);
60
2
  hpp::fcl::DistanceResult distanceResult;
61
62

2
  hpp::fcl::Transform3f tf1(hpp::fcl::Vec3f(3., 0, 0));
63
2
  hpp::fcl::Transform3f tf2;
64
4
  hpp::fcl::CollisionObject capsule(capsuleGeometry, tf1);
65
4
  hpp::fcl::CollisionObject box(boxGeometry, tf2);
66
67
  // test distance
68
2
  hpp::fcl::distance(&capsule, &box, distanceRequest, distanceResult);
69
  // Nearest point on capsule
70
2
  hpp::fcl::Vec3f o1(distanceResult.nearest_points[0]);
71
  // Nearest point on box
72
2
  hpp::fcl::Vec3f o2(distanceResult.nearest_points[1]);
73



2
  BOOST_CHECK_CLOSE(distanceResult.min_distance, 0.5, 1e-1);
74



2
  BOOST_CHECK_CLOSE(o1[0], 1.0, 1e-1);
75



2
  CHECK_CLOSE_TO_0(o1[1], 1e-1);
76



2
  BOOST_CHECK_CLOSE(o2[0], 0.5, 1e-1);
77



2
  CHECK_CLOSE_TO_0(o2[1], 1e-1);
78
79
  // Move capsule above box
80

2
  tf1 = hpp::fcl::Transform3f(hpp::fcl::Vec3f(0., 0., 8.));
81
2
  capsule.setTransform(tf1);
82
83
  // test distance
84
2
  distanceResult.clear();
85
2
  hpp::fcl::distance(&capsule, &box, distanceRequest, distanceResult);
86
2
  o1 = distanceResult.nearest_points[0];
87
2
  o2 = distanceResult.nearest_points[1];
88
89



2
  BOOST_CHECK_CLOSE(distanceResult.min_distance, 2.0, 1e-1);
90



2
  CHECK_CLOSE_TO_0(o1[0], 1e-1);
91



2
  CHECK_CLOSE_TO_0(o1[1], 1e-1);
92



2
  BOOST_CHECK_CLOSE(o1[2], 4.0, 1e-1);
93
94



2
  CHECK_CLOSE_TO_0(o2[0], 1e-1);
95



2
  CHECK_CLOSE_TO_0(o2[1], 1e-1);
96



2
  BOOST_CHECK_CLOSE(o2[2], 2.0, 1e-1);
97
98
  // Rotate capsule around y axis by pi/2 and move it behind box
99

2
  tf1.setTranslation(hpp::fcl::Vec3f(-10., 0., 0.));
100

2
  tf1.setQuatRotation(hpp::fcl::makeQuat(sqrt(2) / 2, 0, sqrt(2) / 2, 0));
101
2
  capsule.setTransform(tf1);
102
103
  // test distance
104
2
  distanceResult.clear();
105
2
  hpp::fcl::distance(&capsule, &box, distanceRequest, distanceResult);
106
2
  o1 = distanceResult.nearest_points[0];
107
2
  o2 = distanceResult.nearest_points[1];
108
109



2
  BOOST_CHECK_CLOSE(distanceResult.min_distance, 5.5, 1e-1);
110



2
  BOOST_CHECK_CLOSE(o1[0], -6, 1e-2);
111



2
  CHECK_CLOSE_TO_0(o1[1], 1e-1);
112



2
  CHECK_CLOSE_TO_0(o1[2], 1e-1);
113



2
  BOOST_CHECK_CLOSE(o2[0], -0.5, 1e-2);
114



2
  CHECK_CLOSE_TO_0(o2[1], 1e-1);
115



2
  CHECK_CLOSE_TO_0(o2[2], 1e-1);
116
2
}