Repository navigation
Description
Feature::getConvexHull() turns mixed empty/non-empty hulls into a full numeric-range bounding box
Summary
Feature::getConvexHull() merges multiple convex hulls by enlarge()-ing a DBoundingBox<2> with each constituent hull's getBoundingBox(). An empty ConvexHull2D returns the default DIntervalBase sentinels (min = +DBL_MAX, max = std::numeric_limits<double>::lowest()), so enlarging with it stretches the merged box across the entire numeric range in both dimensions.
The result is a feature that overlaps every position in RT and m/z.
Reproducer
ConvexHull2D::PointArrayType pts; // a normal, narrow hull
pts.push_back(ConvexHull2D::PointType(990.0, 699.995));
pts.push_back(ConvexHull2D::PointType(1010.0, 700.005));
ConvexHull2D narrow;
narrow.setHullPoints(pts);
Feature f;
f.setRT(1000.0); f.setMZ(700.0); f.setCharge(2);
std::vector<ConvexHull2D> hulls;
hulls.push_back(narrow);
hulls.push_back(ConvexHull2D()); // one empty hull alongside it
f.setConvexHulls(hulls);
DBoundingBox<2> bb = f.getConvexHull().getBoundingBox();Observed (DBL_MAX = 1.79769e+308):
| feature | merged m/z box | extent |
|---|---|---|
| 1 non-empty hull | [699.995 , 700.005] |
0.01 |
| 0 hulls | [1.79769e308 , -1.79769e308] |
-inf (inverted, matches nothing — fine) |
| 1 non-empty + 1 empty | [-1.79769e308 , 1.79769e308] |
+inf |
The RT dimension degenerates identically.
Impact
Any consumer that treats the merged bounding box as the feature's extent will match this feature against everything. Confirmed with PrecursorCorrection::correctToNearestFeature(): a precursor placed far away in both RT and m/z is still reported by the overlap stage ("Number of precursors with overlapping features: 1"). In that particular caller the damage is usually masked, because compatible_() afterwards rejects the pair on isotope-trace grounds — but the overlap predicate itself is genuinely universal, and other consumers of getConvexHull() have no such second filter.
It also penalises any spatial index built over these boxes: an +inf extent defeats width-based pruning (a global-max-extent or bucketed scheme silently loses the feature unless oversized boxes are given a linear-scan escape hatch). This came up while fixing #4787 — the m/z sweep-line landed there tolerates it (the interval simply spans the axis and contributes one candidate per query), but it is worth fixing at the source.
Suggested fix
Ignore invalid constituent boxes while merging, with care about what "invalid" means:
- reject a constituent only when
min > maxin a dimension (the default-sentinel signature); - keep point and line hulls where
min == max— these are legitimate; - do not guard with
DBoundingBox::isEmpty(), which classifies a zero-width dimension as empty and would therefore discard those legitimate hulls; - handle NaN coordinates explicitly;
- return an empty overall hull if every constituent is invalid;
- compute each constituent bounding box once instead of twice (the current loop calls
getBoundingBox()twice per hull).
Notes
- Independent of PrecursorCorrection use our kdtree or other structure for overlap checks #4787; deliberately kept out of that performance patch so the latter keeps a clean "predicate unchanged" story. Fixing this one does change matching behaviour, and should be reviewed on that basis.
- Refactoring: convex hulls #4289 (closed hull-storage refactor) and fix(Feature): eliminate cache-invalidation side effect in getConvexHulls() #9404 (closed, cache invalidation) are adjacent but neither reports this defect.
Activity
timosachsenberg commentedon Jul 26, 2026
Surfaced while fixing #4787 (PR #9801). The m/z sweep-line landed there tolerates the universal interval — it simply spans the axis and contributes one candidate per query — so that PR does not depend on this being fixed, and deliberately leaves the behaviour alone to keep a clean "matching predicate unchanged" story.
coderabbitai commentedon Jul 26, 2026
🔗 Related PRs
#9682 - fix(EmgFitter1D): make EMG fit robust to degenerate/edge input [merged]
#9711 - Improve isotope/adduct RT grouping for low-intensity mass traces (
#4483) [merged]📝 Issue Planner
Check the box below or use the
@coderabbitai plancommand to generate an implementation plan and prompts that you can use with your favorite coding assistant.🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord!
AlyanPremani05 commentedon Jul 26, 2026
@timosachsenberg would like to work on this.
timosachsenberg commentedon Jul 26, 2026
@AlyanPremani05 thank you. Please double-check and investigate if this changes semantics etc...
[FIX] PrecursorCorrection: drop the now-unused overlaps_() helper
[TEST] PrecursorCorrection: randomised differential check of the m/z …
[FIX] PrecursorCorrection: replace exhaustive feature overlap loop wi…