import { interpolateNumberArray } from "d3-interpolate";
/**
 * Gets a well feature object based on it's name
 * @param wells_data A list of data features
 * @param name The name of the well. Case insensitive
 * @returns Returns the well if found
 */
export function getWellObjectByName(wells_data, name) {
    return wells_data.find((item) => { var _a, _b; return ((_b = (_a = item.properties) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === (name === null || name === void 0 ? void 0 : name.toLowerCase()); });
}
/**
 * Gets multiple well feature objects based on their names
 * @param wells_data A list of data features
 * @param name The names of the wells to find. Case insensitive
 * @returns Returns a list of all wells who's name was found
 */
export function getWellObjectsByName(wells_data, name) {
    const res = [];
    for (let i = 0; i < (name === null || name === void 0 ? void 0 : name.length); i++) {
        wells_data.find((item) => {
            var _a, _b, _c;
            if (((_b = (_a = item.properties) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === ((_c = name[i]) === null || _c === void 0 ? void 0 : _c.toLowerCase()))
                res.push(item);
        });
    }
    return res;
}
/**
 * Get measured depths array from well feature object
 * @param well_object A well feature object
 * @returns An array of measured depths for the well
 */
export function getWellMds(well_object) {
    return well_object.properties.md[0];
}
/**
 * Gets an interpolated world position along a well trajectory based on measured depth
 * @param well_xyz A wells trajectory positions
 * @param well_mds A wells trajectory measured depths
 * @param md The measured depth to get the position for
 * @returns The interpolated world position at the given measured depth
 */
export function getPositionByMD(well_xyz, well_mds, md) {
    const [l_idx, h_idx] = getNeighboringMdIndices(well_mds, md);
    const md_low = well_mds[l_idx];
    const md_normalized = (md - md_low) / (well_mds[h_idx] - md_low);
    return interpolateNumberArray(well_xyz[l_idx], well_xyz[h_idx])(md_normalized);
}
function getNeighboringMdIndices(mds, md) {
    const idx = mds.findIndex((x) => x >= md);
    if (idx === -1)
        return [];
    return idx === 0 ? [idx, idx + 1] : [idx - 1, idx];
}
//# sourceMappingURL=wells.js.map