1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use necsim_core::{
    cogs::{
        coalescence_sampler::CoalescenceRngSample, Habitat, LocallyCoherentLineageStore, MathsCore,
    },
    landscape::{IndexedLocation, Location},
    lineage::LineageInteraction,
};

#[must_use]
pub fn sample_interaction_at_location<
    M: MathsCore,
    H: Habitat<M>,
    S: LocallyCoherentLineageStore<M, H>,
>(
    location: Location,
    habitat: &H,
    lineage_store: &S,
    coalescence_rng_sample: CoalescenceRngSample,
) -> (IndexedLocation, LineageInteraction) {
    let chosen_coalescence_index = coalescence_rng_sample
        .sample_coalescence_index::<M>(habitat.get_habitat_at_location(&location));

    let indexed_location = IndexedLocation::new(location, chosen_coalescence_index);

    let optional_coalescence = lineage_store
        .get_global_lineage_reference_at_indexed_location(&indexed_location, habitat)
        .cloned();

    (indexed_location, optional_coalescence.into())
}