Skip to content

Feature::getConvexHull() turns mixed empty/non-empty hulls into a full numeric-range bounding box #9802

Open

Description

@timosachsenberg

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 > max in 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

Activity

  1. timosachsenberg commented on Jul 26, 2026

    @timosachsenberg
    ContributorAuthor

    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.

  2. coderabbitai commented on Jul 26, 2026

    @coderabbitai
    Contributor
    🔗 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 plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 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:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  3. AlyanPremani05 commented on Jul 26, 2026

    @AlyanPremani05

    @timosachsenberg would like to work on this.

  4. timosachsenberg commented on Jul 26, 2026

    @timosachsenberg
    ContributorAuthor

    @AlyanPremani05 thank you. Please double-check and investigate if this changes semantics etc...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions