code: def test_mesh_normals_length_array(primitive):
      size = (45, 40)
      with TestingCanvas(size=size, bgcolor="k") as c:
          v = c.central_widget.add_view(border_width=0)
          v.camera = "arcball"
          v.camera.fov = 90
          # Create visual.
          meshdata = create_sphere(radius=1.0)
          mesh = scene.visuals.Mesh(
              meshdata=meshdata,
              shading=None,
              color=(0.1, 0.1, 0.1, 1.0),
          )
          v.add(mesh)
  
          if primitive == "face":
              n_normals = len(meshdata.get_faces())
          elif primitive == "vertex":
              n_normals = len(meshdata.get_vertices())
  
          lengths_0_5 = np.full(n_normals, 0.5, dtype=float)
          normals_0_5 = scene.visuals.MeshNormals(
              meshdata,
              primitive=primitive,
              color=(1, 0, 0),
              length=lengths_0_5,
          )
          normals_0_5.parent = mesh
          rendered_lengths_0_5 = c.render()
          normals_0_5.parent = None
  
          lengths_1_0 = np.full(n_normals, 1.0, dtype=float)
          normals_1_0 = scene.visuals.MeshNormals(
              meshdata,
              primitive=primitive,
              color=(1, 0, 0),
              length=lengths_1_0,
          )
          normals_1_0.parent = mesh
          rendered_lengths_1_0 = c.render()
          normals_1_0.parent = None
  
          # There should be more red pixels with the longer normals.
          n_pixels_0_5 = np.sum(rendered_lengths_0_5[..., 0] > 128)
          n_pixels_1_0 = np.sum(rendered_lengths_1_0[..., 0] > 128)
          assert n_pixels_1_0 > n_pixels_0_5
  
          lengths_ramp = np.linspace(0.5, 1.0, n_normals, dtype=float)
          normals_ramp = scene.visuals.MeshNormals(
              meshdata,
              primitive=primitive,
              color=(1, 0, 0),
              length=lengths_ramp,
          )
          normals_ramp.parent = mesh
          rendered_lengths_ramp = c.render()
          normals_ramp.parent = None
  
          # With the normals lengths from a ramp in [0.5, 1.0], there should be
          # more red pixels than with all normals of length 0.5 and less than
          # with all normals of length 1.0.
          n_pixels_ramp = np.sum(rendered_lengths_ramp[..., 0] > 128)
          assert n_pixels_0_5 < n_pixels_ramp < n_pixels_1_0
  
file_path: vispy/vispy/visuals/tests/test_mesh_normals.py
imports: import numpy
  import pytest
  from vispy import scene
  from vispy.geometry import create_sphere
  from vispy.testing import TestingCanvas, requires_application, run_tests_if_main, requires_pyopengl
label_desc: Use image node_id 3 for calling a global function with example usage: test_mesh_normals_length_array(primitive) without return types