GCC Code Coverage Report


Directory: ./
File: src/trajectory.cpp
Date: 2026-12-03 12:28:13
Warnings: 1 unchecked decisions!
Exec Total Coverage
Lines: 0 110 0.0%
Functions: 0 14 0.0%
Branches: 0 96 0.0%
Decisions: 0 82 0.0%

Line Branch Decision Exec Source
1 #include "trajectory.hpp"
2 #include "region.hpp"
3 #include "microtubule.hpp"
4 #include "segment.hpp"
5 #include "system.hpp"
6
7 ✗ Trajectory::Trajectory(SurfaceVector base_vec, std::vector<PointAtEdge> end_p, double l):
8 ✗ base(base_vec),
9 ✗ length(l),
10 prev_tr(0, Direction::FORWARD, nullptr),
11 next_tr(0, Direction::FORWARD, nullptr),
12 ✗ prev_tr_cos_angle(1.0),
13 ✗ next_tr_cos_angle(1.0)
14 {
15 #ifdef DBG_GEOMETRY
16 cout << "DBG/GEOMETRY: Trajectory created\n";
17 #endif
18
19 // assign end points of the trajectory
20
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ for (int i = 0; i < 2; i++)
21 {
22 ✗ end_point.push_back(end_p[i]);
23 }
24
25 // increase total number of trajectories in the geometry
26 ✗ base.region->geometry->system->count_trajectories++;
27
28 // initialize the intersection list of the trajectory
29 ✗ intersections.insert(std::pair<double, Intersection>(-1.0, Intersection()));
30
31 ✗ return;
32 }
33
34 ✗ Trajectory::~Trajectory()
35 {
36 // decrease total number of trajectories in the geometry
37 ✗ base.region->geometry->system->count_trajectories--;
38 ✗ return;
39 ✗ }
40
41 ✗ bool Trajectory::integrity_check()
42 {
43 bool valid(true);
44
45
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (prev_tr.trajectory != nullptr)
46 {
47
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (prev_tr.dir == Direction::BACKWARD)
48 {
49
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (prev_tr.trajectory->next_tr.trajectory != this)
50 {
51 valid = false;
52 ✗ std::cout << "Integrity: trajectory dependency chain broken.\n";
53 }
54 }
55 else
56 {
57
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (prev_tr.trajectory->prev_tr.trajectory != this)
58 {
59 valid = false;
60 ✗ std::cout << "Integrity: trajectory dependency chain broken.\n";
61 }
62 }
63 }
64
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (next_tr.trajectory != nullptr)
65 {
66
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (next_tr.dir == Direction::FORWARD)
67 {
68
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (next_tr.trajectory->prev_tr.trajectory != this)
69 {
70 valid = false;
71 ✗ std::cout << "Integrity: trajectory dependency chain broken.\n";
72 }
73 }
74 else
75 {
76
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (next_tr.trajectory->next_tr.trajectory != this)
77 {
78 valid = false;
79 ✗ std::cout << "Integrity: trajectory dependency chain broken.\n";
80 }
81 }
82 }
83
84 IntersectionItr is(wall_begin());
85
86
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ for (size_t is_count = 1; is_count < intersections.size(); is_count++)
87 {
88 is++;
89
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (is->second.mirror->second.mirror != is)
90 {
91 ✗ std::cout << "Integrity: intersection mirroring broken.\n";
92 valid = false;
93 }
94 }
95
96 std::list<Segment*>::iterator seg_itr(segments.begin());
97
98
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (seg_itr != segments.end())
99 {
100 ✗ is = (**seg_itr).start_itr;
101
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if ((**seg_itr).dir == Direction::FORWARD)
102 {
103
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (++is != (**seg_itr).end_itr)
104 {
105 ✗ is->second.occupancy--;
106 }
107 }
108 else
109 {
110
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (--is != (**seg_itr).end_itr)
111 {
112 ✗ is->second.occupancy--;
113 }
114 }
115 seg_itr++;
116 }
117 // now, check whether all occupancy counts are zero
118 is = intersections.begin();
119
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (++is != intersections.end())
120 {
121
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (is->second.occupancy != 0)
122 {
123 ✗ std::cerr << "Detected occupancy " << is->second.occupancy << " (should be zero).\n";
124 valid = false;
125 }
126 }
127
128 seg_itr = segments.begin();
129
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (seg_itr != segments.end())
130 {
131 ✗ is = (**seg_itr).start_itr;
132
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if ((**seg_itr).dir == Direction::FORWARD)
133 {
134
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (++is != (**seg_itr).end_itr)
135 {
136 ✗ is->second.occupancy++;
137 }
138 }
139 else
140 {
141
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (--is != (**seg_itr).end_itr)
142 {
143 ✗ is->second.occupancy++;
144 }
145 }
146 seg_itr++;
147 }
148
149
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (!valid)
150 {
151 ✗ std::cerr << "Invalid occupancy count found during integrity check.\n";
152 }
153
154 ✗ return valid;
155 }
156
157 ✗ double Trajectory::segment_length()
158 {
159 double sum_length(0.0);
160 std::list<Segment*>::iterator seg(segments.begin());
161
162 // calculate total length of all the segments present in the trajectory
163
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (seg != segments.end())
164 {
165 ✗ sum_length += (**seg).length();
166 seg++;
167 }
168 ✗ return sum_length;
169 }
170
171 ✗ double Trajectory::covered_length()
172 {
173 std::list<Segment*>::iterator seg(segments.begin());
174 std::list<double> start_points;
175 std::list<double> end_points;
176
177 // store the start and end point locations of segments in two seperate list
178
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (seg != segments.end())
179 {
180 ✗ start_points.push_back(std::min((**seg).start, (**seg).end));
181 ✗ end_points.push_back(std::max((**seg).start, (**seg).end));
182 seg++;
183 }
184
185 // make sure the last value of start-point-list is maximum of all values from both lists
186 start_points.push_back(VERY_LARGE);
187
188 // sort the distances
189 ✗ start_points.sort();
190 ✗ end_points.sort();
191
192 double previous_pos(0.0);
193 double current_pos(0.0);
194 int occupancy(0);
195 double c_length(0.0);
196 std::list<double>::iterator stepup(start_points.begin());
197 std::list<double>::iterator stepdown(end_points.begin());
198
199
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (stepdown != end_points.end())
200 {
201 current_pos = std::min(*stepup, *stepdown);
202
203 // sum up only once and if the trajectory is covered, i.e. avoid multiple addition for bundles
204
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (occupancy >= 1)
205 {
206 ✗ c_length += current_pos - previous_pos;
207 }
208
209 previous_pos = current_pos;
210
211 // occupancy increasing, chances of the presence of bundle increasing
212
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if ((*stepup) < (*stepdown))
213 {
214 stepup++;
215 ✗ occupancy++;
216 }
217
218 // occupancy decreasing, chances of the presence of bundle decresing
219 else
220 {
221 stepdown++;
222 ✗ occupancy--;
223 }
224 }
225
226 ✗ return c_length;
227 }
228
229 ✗ void Trajectory::invalidate_intersection(IntersectionItr& old_is)
230 {
231 std::list<MTTip*>::iterator tip(notification_list.begin());
232
233 // notify all tips on the current trajectory that a previous insertion is invalidated
234
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (tip != notification_list.end())
235 {
236 ✗ (**tip).notify_remove(old_is);
237 tip++;
238 }
239
240 ✗ return;
241 }
242
243 ✗ void Trajectory::new_intersection(IntersectionItr& new_is)
244 {
245 #ifdef DBG_GEOMETRY
246 cout << "DBG/GEOMETRY: Trajectory::newIntersection() called.\n";
247 #endif
248
249 std::list<Segment*>::iterator seg(segments.begin());
250
251 int occupancy(0);
252
253 // find whether the new intersection is a cross-intersection for the segment
254
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (seg != segments.end())
255 {
256 ✗ (**seg).mt->update_length();
257
258
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if ((**seg).crosses_intersection(new_is))
259 {
260 ✗ occupancy++;
261 }
262
263 seg++;
264 }
265
266 // assign complemetary occupancy for the new intersection
267 ✗ new_is->second.occupancy = occupancy;
268
269 // notify all tips on the current trajectory that a new insertion has happened
270 std::list<MTTip*>::iterator tip(notification_list.begin());
271
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ while (tip != notification_list.end())
272 {
273 ✗ (**tip).notify_insert(new_is);
274 tip++;
275 }
276
277 ✗ return;
278 }
279
280 ✗ int Trajectory::difference_sign(IntersectionItr itr1, double pos1, IntersectionItr itr2, double pos2)
281 {
282 // returns the sign of 'pos1 - pos2'. If the two positions are equal, the iterators are used instead to determine
283 // order.
284
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (pos1 - pos2 > ZERO_CUTOFF)
285 {
286 return 1;
287 }
288
289
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ else if (pos1 - pos2 < -ZERO_CUTOFF)
290 {
291 return -1;
292 }
293
294 else
295 {
296
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (itr1 == itr2)
297 {
298 return 0;
299 }
300
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (itr1 == wall_end())
301 {
302 return 1;
303 }
304
305 do
306 {
307 itr2++;
308
0/1
? Decision couldn't be analyzed.
✗ } while ((itr2 != wall_end()) && (itr1 != itr2));
309
310
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (itr1 == itr2)
311 {
312 return 1;
313 }
314 else
315 {
316 return -1;
317 }
318 }
319 }
320
321 ✗ TrjSegmentTag Trajectory::insert_segment(Segment* s)
322 {
323 #ifdef DBG_ASSERT
324 // check whether the size of the inserted segment equals zero, for insertion of non-zero segments, take care to
325 // update the occupancy numbers
326 if (std::abs(s->end - s->start) > ZERO_CUTOFF)
327 {
328 cerr << "DBG/ASSERT: ERROR: Not permitted to insert segment with non-zero length.\n";
329 exit(-1);
330 }
331 #endif
332
333 // insert a new segment to the trajectory
334 ✗ return segments.insert(segments.end(), s);
335 }
336
337 ✗ void Trajectory::remove_segment(TrjSegmentTag s)
338 {
339 #ifdef DBG_GEOMETRY
340 cout << "DBG/GEOMETRY: Trajectory::removeSegment() called.\n";
341 #endif
342
343 // remove segment
344 ✗ segments.erase(s);
345
346 // if the associated trajectory has no segement and no tips, then remove the whole trajectory
347 ✗ conditional_remove();
348
349 ✗ return;
350 }
351
352 ✗ TrjMTTipTag Trajectory::register_for_notifications(MTTip* p_tip)
353 {
354 // a new tip arrived on the trajectory, add it to the notification list
355 ✗ return notification_list.insert(notification_list.end(), p_tip);
356 }
357
358 ✗ void Trajectory::unregister_for_notifications(TrjMTTipTag tag)
359 {
360 // a tip is leaving the trajectory, remove it from the notification list
361 ✗ notification_list.erase(tag);
362
363 // if the associated trajectory has no tips and no segments, then remove the whole trajectory
364 ✗ conditional_remove();
365 ✗ return;
366 }
367
368 ✗ TrajectoryVector Trajectory::next_trajectory(Direction dir)
369 {
370
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (dir == Direction::FORWARD)
371 {
372 // direction forward and a next trajectory is waiting to take the tip on board
373
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (next_tr.trajectory != nullptr)
374 {
375 #ifdef DBG_GEOMETRY
376 cout << "DBG/GEOMETRY: Following existing trajectory link forward. [from "
377 << RegionTypeText[base.region->type] << " to " << RegionTypeText[nextTr.trajectory->base.region->type]
378 << "]\n";
379 #endif
380
381 ✗ return next_tr;
382 }
383 }
384
385 else
386 {
387 // direction backward and a previous trajectory is waiting to take the on board
388
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (prev_tr.trajectory != nullptr)
389 {
390 #ifdef DBG_GEOMETRY
391 cout << "DBG/GEOMETRY: Following existing trajectory link forward. [from "
392 << RegionTypeText[base.region->type] << " to " << RegionTypeText[prevTr.trajectory->base.region->type]
393 << "]\n";
394 #endif
395
396 ✗ return prev_tr;
397 }
398 }
399
400 // there is no next/previous trajectory to take the tip, so extend (create a new) trajectory
401 ✗ return base.region->geometry->extend_trajectory(this, dir);
402 }
403
404 ✗ void Trajectory::conditional_remove()
405 {
406 // if there is no segments and no tips, associted with a trajectory, then remove it rigth way
407
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
✗ if (segments.empty() && (notification_list.size() == 0))
408 {
409 ✗ base.region->remove_trajectory(this);
410 }
411
412 ✗ return;
413 }
414