Skip to content

Add flat inverse / Bragg-peak convenience wrappers to dedx_wrappers.h #122

@grzanka

Description

@grzanka

Part of #118 (dedx_extra.c migration) · Phase D. Depends on Phase C (#121) landing first.

Problem

The core inverse functions (dedx_get_inverse_csda, dedx_get_inverse_stp in dedx_tools.h) require a caller-managed dedx_workspace* + dedx_config* (allocate → set ion_adedx_load_config → call → free). That lifecycle cannot be driven safely from JavaScript/WASM, so dedx_web wraps it in wasm/dedx_extra.c as "flat" one-call functions.

libdedx already ships this convenience style in dedx_wrappers.h (dedx_get_simple_stp_for_program, dedx_get_stp_table, dedx_get_csda_range_table, …). The flat inverse wrappers belong right next to them.

Proposed change

Add to include/dedx_wrappers.h (handling workspace/config lifecycle internally):

double dedx_get_inverse_csda_simple(int program, int ion, int target,
                                    double range, int *err);
double dedx_get_inverse_stp_simple(int program, int ion, int target,
                                   double stp, int side, int *err);
double dedx_get_bragg_peak_stp_simple(int program, int ion, int target, int *err);

(Names to match the existing *_simple_* convention — final call by a maintainer. dedx_web currently names them *_flat.)

These set cfg.ion_a from the nucleon-number accessor (Phase A, #119) before dedx_load_config, which is the subtle bit the inverse functions require.

Acceptance criteria

  • Declarations + Doxygen in dedx_wrappers.h; each wrapper is self-contained and re-entrant (fresh workspace per call — note for thread-safety make library thread-safe #86).
  • Tests mirroring an existing wrapper test.
  • dedx_web deletes dedx_get_inverse_csda_flat / dedx_get_inverse_stp_flat / dedx_get_bragg_peak_stp from wasm/dedx_extra.c and updates wasm/contract-manifest.json + docs/06-wasm-api-contract.md.

Reference

dedx_web wasm/dedx_extra.c (lines ~221–455).


Filed via Claude Code as part of the dedx_extra.c → libdedx migration plan.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions