GCC Code Coverage Report


Directory: ./
File: src/broadphase/default_broadphase_callbacks.cpp
Date: 2025-04-01 09:23:31
Exec Total Coverage
Lines: 15 43 34.9%
Branches: 5 24 20.8%

Line Branch Exec Source
1 /*
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2020, Toyota Research Institute
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 the copyright holder 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 Sean Curtis (sean@tri.global) */
36
37 #include "coal/broadphase/default_broadphase_callbacks.h"
38 #include <algorithm>
39
40 namespace coal {
41
42 1 bool defaultCollisionFunction(CollisionObject* o1, CollisionObject* o2,
43 void* data) {
44
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 assert(data != nullptr);
45 1 auto* collision_data = static_cast<CollisionData*>(data);
46 1 const CollisionRequest& request = collision_data->request;
47 1 CollisionResult& result = collision_data->result;
48
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (collision_data->done) return true;
50
51 1 collide(o1, o2, request, result);
52
53
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
2 if (result.isCollision() &&
54
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result.numContacts() >= request.num_max_contacts) {
55 1 collision_data->done = true;
56 }
57
58 1 return collision_data->done;
59 }
60
61 1222280 bool CollisionCallBackDefault::collide(CollisionObject* o1,
62 CollisionObject* o2) {
63 1222280 return defaultCollisionFunction(o1, o2, &data);
64 }
65
66 bool defaultDistanceFunction(CollisionObject* o1, CollisionObject* o2,
67 void* data, Scalar& dist) {
68 assert(data != nullptr);
69 auto* cdata = static_cast<DistanceData*>(data);
70 const DistanceRequest& request = cdata->request;
71 DistanceResult& result = cdata->result;
72
73 if (cdata->done) {
74 dist = result.min_distance;
75 return true;
76 }
77
78 distance(o1, o2, request, result);
79
80 dist = result.min_distance;
81
82 if (dist <= 0) return true; // in collision or in touch
83
84 return cdata->done;
85 }
86
87 33012 bool DistanceCallBackDefault::distance(CollisionObject* o1, CollisionObject* o2,
88 Scalar& dist) {
89 33012 return defaultDistanceFunction(o1, o2, &data, dist);
90 }
91
92 CollisionCallBackCollect::CollisionCallBackCollect(const size_t max_size)
93 : max_size(max_size) {
94 collision_pairs.resize(max_size);
95 }
96
97 bool CollisionCallBackCollect::collide(CollisionObject* o1,
98 CollisionObject* o2) {
99 collision_pairs.push_back(std::make_pair(o1, o2));
100 return false;
101 }
102
103 size_t CollisionCallBackCollect::numCollisionPairs() const {
104 return collision_pairs.size();
105 }
106
107 const std::vector<CollisionCallBackCollect::CollisionPair>&
108 CollisionCallBackCollect::getCollisionPairs() const {
109 return collision_pairs;
110 }
111
112 void CollisionCallBackCollect::init() { collision_pairs.clear(); }
113
114 bool CollisionCallBackCollect::exist(CollisionObject* o1,
115 CollisionObject* o2) const {
116 return exist(std::make_pair(o1, o2));
117 }
118
119 bool CollisionCallBackCollect::exist(const CollisionPair& pair) const {
120 return std::find(collision_pairs.begin(), collision_pairs.end(), pair) !=
121 collision_pairs.end();
122 }
123
124 } // namespace coal
125