code: def test_project_onto_surface(method, ret_nn):
      """Test _project_onto_surface (gh-10930)."""
      locs = np.random.default_rng(0).normal(size=(10, 3))
      locs *= (
          2 / np.linalg.norm(locs, axis=1)[:, None]
      )  # lie on a sphere rad=2
      surf = _get_ico_surface(3)
      assert len(surf["rr"]) == 642
      assert_allclose(
          np.linalg.norm(surf["rr"], axis=1), 1.0, rtol=1e-3
      )  # unit
      # project
      weights, tri_idx, *out = _project_onto_surface(
          locs, surf, project_rrs=True, return_nn=ret_nn, method=method
      )
      locs /= 2.0  # back to unit
      assert_allclose(np.linalg.norm(locs, axis=1), 1.0, rtol=1e-5)
      assert len(out) == 2 if ret_nn else 1
      # for a sphere, both the rr (out[0]) and nn (out[1], if exists) should
      # both be very similar to each other and to our unit-length `locs`
      for kind, comp in zip(("rr", "nn"), out):
          assert_allclose(
              np.linalg.norm(comp, axis=1),
              1.0,
              atol=0.05,
              err_msg=f"{kind} not unit vectors for {method}",
          )
          cos = np.sum(locs * comp, axis=1)
          assert_allclose(
              cos,
              1.0,
              atol=0.05,  # ico > 3 would be even better tol
              err_msg=f"{kind} not in same direction as locs for {method}",
          )
  
imports: from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_equal
  from mne import decimate_surface, dig_mri_distances, get_montage_volume_labels, pick_types, read_surface, write_surface
  from mne._fiff.constants import FIFF
  from mne.channels import make_dig_montage
  from mne.datasets import testing
  from mne.io import read_info
  from mne.surface import _compute_nearest, _get_ico_surface, _marching_cubes, _normal_orth, _project_onto_surface, _read_patch, _tessellate_sphere, _voxel_neighbors, fast_cross_3d, get_head_surf, get_meg_helmet_surf, read_curvature
  from mne.transforms import _get_trans
  from mne.utils import _record_warnings, catch_logging, object_diff, requires_freesurfer
label_desc: Use image node_id 14 for calling a global function with example usage: test_project_onto_surface(method, ret_nn) without return types