fix: a merged segment lost the scan it was built from, so pointAt read past the end

The constructor mergeLines uses took only the fitted parameters and the ray
indices, leaving c_data_ and r_data_ default-constructed. pointAt indexes
r_data_.xs directly, so asking a merged segment where one of its own rays is
read past the end of an empty vector.

Two callers already do exactly that. The reflective-tape check walks the ray
span of a wing and reads each point; the arc matcher gathers the points of
adjacent segments to fit a circle to them. The arc matcher is how it surfaced -
it segfaulted, and AddressSanitizer put it on line.cpp:58.

It stayed hidden because mergeLines almost never fires with the default
parameters: a gap wide enough to split at is already wider than max_line_gap,
which is the gate merging has to pass. That is the merge gate working as
intended, and it is also why this could not be reached from a synthesized
scene - a scene-based test here would guard nothing, so the regression test
builds a merged Line directly instead.

The constructor now takes the scan data, like the other one. A merged segment
is still built from the same scan, so there was never a reason for it to lose
it, and a consumer cannot tell a merged segment from a fresh one - the
invariant has to be that every segment answers for every ray it supports.

pointAt also bounds-checks now and returns NaN for a ray it does not carry.
That is a second line of defence, not the fix: every caller already has to
reject non-finite points because a real scan contains them, so a future
constructor that forgets the data degrades instead of reading out of bounds.
This commit is contained in:
2026-08-26 20:09:06 +07:00
parent 524f3432e2
commit 8df353ded6
4 changed files with 108 additions and 9 deletions

View File

@@ -405,7 +405,8 @@ void LineExtractor::mergeLines()
indices.insert(indices.end(), ind_1.begin(), ind_1.end());
indices.insert(indices.end(), ind_2.begin(), ind_2.end());
Line merged_line(L_m[1], L_m[0], cov, lines_[i - 1].getStart(), lines_[i].getEnd(), indices);
Line merged_line(c_data_, r_data_, L_m[1], L_m[0], cov, lines_[i - 1].getStart(),
lines_[i].getEnd(), indices);
merged_line.projectEndpoints();
lines_[i] = merged_line;
}