# PowerSearch3D web port: numerical behavior Engine version: 1.0.0. Source baseline: TcellSearchSim commit `0155df7`. The Qt/C++ source in the repository is unchanged. The browser engine is in `web/engine.mjs`. This is a numerical port with the explicit corrections below; it does not claim bitwise equivalence to desktop output or biological validation. ## Source mapping | Desktop code | Browser behavior | | --- | --- | | `RectangularPrism::updateSearcherPositions` | All 11 generated motion modes, first-step normalized Gaussian direction, subsequent spherical inclination change and Rodrigues rotation, boundary rejection | | `SearchSpace` distribution methods | Fitted speed and turning distributions below | | `Model::addSearchers` | CSV import, grouping, bounds, empirical speed and turning samples | | `Model::placeTargets` | Uniform points in spherical clusters intersected with the volume | | `SearchSpace::testpath`, `Model::calcTargetsFound` | Segment contacts, three counting modes, per-cell first contacts and efficiencies | | `Model::doAnalysis` | Explicit replicates, separate dataset and cluster-radius conditions, descriptive summaries | | `Visualizer`, `MainWindow`, `Histogram` | Rotatable 3D projection with panning, trajectory playback, speed/angle histograms, comparison charts and exports | ## Motion distributions Positions and path lengths are in micrometers (µm); timestamps and time steps are in seconds. Generated step length is `max(0.0001, speed * step_duration)`. | Mode | Speed (µm/s) | Subsequent inclination change | | --- | --- | --- | | Observed | Original positions and timestamps | Original turns | | Brownian | Constant 0.11 | Uniform [0, π) | | Log-normal | exp(Normal(-2.5, 0.9329²)) | Uniform [0, π) | | Generalized Pareto | 0.0006 + 0.13 (U^-0.12 - 1) / 0.12 | Uniform [0, π) | | Power law (legacy) | (1.15 / 0.0006535) (U / 0.0006535)^-2.15 | Uniform [0, π) | | Exponential | -0.1033 ln(U) | Uniform [0, π) | | Gamma | Gamma(shape=1.5914, scale=0.0730) | Uniform [0, π) | | Correlated random walk | Constant 0.11 | Gamma(2.1586, 0.598799) radians | | Log-normal CRW | Log-normal as above | Gamma(2.1586, 0.598799) radians | | Gamma CRW | Gamma as above | Gamma(2.1586, 0.598799) radians | | Bootstrap speeds | Sample empirical speeds with replacement | Uniform [0, π) | | Bootstrap speeds + angles | Sample empirical speeds with replacement | Sample empirical turning angles with replacement | The source's “Brownian” label describes a constant-speed random-turn model, not an exact Wiener diffusion process. Its uniform turning angle is retained rather than replaced with isotropic independent directions. The legacy power-law formula is also retained verbatim; it is not silently replaced by a conventional Pareto inverse CDF. Gamma turning values above π are not truncated. The initial direction is a normalized 3D standard normal vector. Subsequent directions apply the source's spherical inclination increment, then rotate the result about the previous accepted direction by a uniform angle in [0, 2π). Generated paths include their initial position. A rejected boundary proposal records a stationary position and consumes its step duration, keeping the last accepted heading. This makes waiting intervals explicit and avoids interpolating contacts across an unrecorded pause. Stationary segments under 1e-6 µm do not make contacts, matching the original detection guard. ## Geometry and totals: intentional corrections * The desktop segment projection uses `target - end` where the projection formula requires `target - start`. The web version uses the correct clamped projection; targets near the middle of a long segment are detected, and endpoint distances are respected. * The original aggregate distance and time loops repeatedly read the first searcher. Web totals sum every individual track. * The desktop distance method ignores paths with only two points. The web engine includes every actual segment. * The original path count and additional time-resolution multiplication introduce an off-by-one and double scaling. Web time is elapsed time, summed across cells. * First contact is the first segment/sphere intersection interpolated in time, measured from each track's start. The original uses segment index times the global resolution. Cells with no contact retain null, not a zero or sentinel. * The original density scaling and integer target-placement arithmetic are replaced by an explicit target count, targets per cluster, and continuous uniform cluster centers. Target placement uses the cluster/volume intersection directly, including negative-coordinate and thin volumes. A partial final cluster supplies exactly the requested target count. * Imported tracks are grouped by numeric ID and sorted by timestamp. Duplicated timestamps, missing numbers, infinities, and malformed headers are rejected. Tracks shorter than four points are omitted with a warning, consistent with the desktop's actual threshold. Every segment supplies an empirical speed, using its own timestamp difference. Turns exclude zero-length directions. * The median observed interval initializes the UI time step. Axes narrower than 1 µm are expanded symmetrically to 1 µm so planar data still has a finite search volume. These expanded bounds are included in JSON. ## Search budgets and contacts Without observed data, the time rule runs the selected number of attempted steps per cell. The distance rule uses a total distance across all cells and clips the last step to that budget. Both rules have an explicit time-step safety cap. With “Match generated search effort to observed tracks” enabled, generated runs use the sum of observed elapsed times or observed path distances as their budget, according to the stopping rule. The final time step may be shorter to meet the time budget exactly. Allocation across cells proceeds in rounds; it does not force each simulated cell to match its corresponding observed track duration. Observed mode always uses the full original tracks. The `truncated` export field reports when the safety cap prevented reaching a requested budget. All contact modes use non-destructive trajectories and target fields, as the original implementation does: * Unique targets: a target contributes at most one contact across all cells. * Unique searcher–target pairs: a target contributes once per cell. * All segment–target encounters: a target can contribute once per segment per cell, including adjacent segments while a cell stays within detection range. This is not a count of distinct entry/exit episodes. Aggregate efficiency uses the selected count divided by total path distance or total elapsed searcher time. Per-cell efficiencies always use that cell's unique target count. First-contact means exclude non-contacting cells; the number of contacting cells is displayed and exported. Playback and cumulative encounter plots align each track at its own start time. ## Replication, summaries and persistence A seeded Mulberry32 stream supplies uniforms strictly between 0 and 1. Normal sampling uses Box–Muller; gamma sampling uses Marsaglia–Tsang rejection. Target and movement streams are separate. Replicate/dataset seed derivation is recorded in `engine.mjs`, and each effective target seed is exported. Models within a condition use paired target fields and starting positions. Radii share seed inputs, but different rejection histories can produce different cluster centers. Seeds reproduce this engine, not the original mixed C `rand`/Boost stream. The optional independent-fields setting adds a condition-specific stream offset so unpaired comparisons do not reuse target fields or starts. Summaries include mean, sample standard deviation, range, interpolated quartiles, and median. First-contact summaries average each replicate's conditional mean; replicates without any contact are excluded and their contributing `n` is in JSON. The UI table shows mean ± sample SD, not a confidence interval. Replicates are an explicit configurable count, replacing the desktop's hardcoded nested 10×100 analysis loop. Comparisons use each condition's replicate values against the first condition. Shared random fields within one dataset use paired t tests. The independent-fields option or different datasets use Welch t tests, with equal-variance Student t and Mann–Whitney results also exported. T-test probabilities are computed using the regularized incomplete beta function. Mann–Whitney uses average ranks, tie correction, continuity correction, and a normal approximation (not ALGLIB's original approximation). Both one-sided t tails and the primary two-sided probability are exported. Holm-adjusted primary p-values cover the complete family of available metric/condition comparisons. Samples shorter than two and zero-variance t tests are marked undefined. These tests describe generated replicates and do not establish biological significance. Small-sample Mann–Whitney approximations should be interpreted accordingly. Reference-minus-comparison differences are explicit in exports. The source's Hopkins variant is computed on every target field using its own random stream: sum each target's nearest other-target distance as U, sum each target's nearest distance to an equally sized uniform reference field as W, and return U/(U+W). Values near zero indicate stronger clustering in this convention; no distance powers are used. This preserves the source definition rather than substituting a different Hopkins convention. Fields with fewer than two targets have no defined value. Squared displacement from each track's initial position is available as a CSV with elapsed time. Results remain in the open tab until replaced or reloaded. Cancel terminates the worker and preserves the previous completed result. JSON retains all replicate summaries and full trajectories, targets, distributions, and per-cell results for the first replicate of each condition. CSV trajectory exports use the same five-column input format. Large views are downsampled to about 30,000 display vertices; calculations and exported retained trajectories are not downsampled. ## Work bounds Maximums: 500 searchers, 10,000 steps, 5,000 targets, 100 replicates, eight radii, eight CSV datasets, and 1,000 runs. Each CSV is at most 10 MB / 200,000 points; combined file size is at most 20 MB. Work is additionally limited to 500,000 points per run, about one million retained trajectory points across conditions, and 150 million estimated distance checks (including Hopkins) per experiment. These are conservative upper bounds. The worker is cancelable without a server job. ## Validation `npm test` exercises analytical segment geometry, exact path/time totals, counting modes, first contacts, import failures, deterministic seeds, every motion mode, fitted distribution means, rotation invariants, boundary rejection, search budgets, placement in thin/negative volumes, and work limits. `tests/native_reference.cpp` compiles against the unchanged original C++ core to capture Pareto, exponential, and legacy power-law outputs for a known uniform input. Their fixtures are compared against the web formulas within single-float rounding. This verifies those formulas, not complete stochastic run equivalence. `tests/statistics-fixture.json` contains independent SciPy reference values for paired, Student, Welch, and tie-corrected Mann–Whitney tests. Their unit tests also cover Holm correction, missing observations, and degenerate samples. `tests/browser_check.py` covers desktop/mobile interactions and downloads.