def merge_components(local_component, target_component):
    """
    Find resulting component from merging the first (local) component into the second.  The resulting
    component will maintain the parent identifier of the target component.
    """
    local_bounds, local_center, local_size, local_parent = local_component
    target_bounds, target_center, target_size, target_parent = target_component

    merged_bounds = [
        min(local_bounds[0], target_bounds[0]),
        max(local_bounds[1], target_bounds[1]),
        min(local_bounds[2], target_bounds[2]),
        max(local_bounds[3], target_bounds[3]),
        min(local_bounds[4], target_bounds[4]),
        max(local_bounds[5], target_bounds[5]),
    ]

    merged_size = local_size + target_size

    # use weighted averaging to find center.  the center point is not guaranteed to occur at a
    # position containing the component (eg if it is "C" shape)
    merged_center = (
        local_center * local_size + target_center * target_size
    ) / merged_size

    return merged_bounds, merged_center, merged_size, target_parent