code: def test_intersect(tmp_path):
      # Zoom level zero.
      # File 1: Parent space of all images.
      z_0_dir = tmp_path / "z_0"
      z_0_dir.mkdir()
      world = dict(
          x_pix_size=2,
          y_rotation=0,
          x_rotation=0,
          y_pix_size=2,
          x_center=1,
          y_center=1,
      )
      im = Image.new("RGB", (50, 50))
      _save_world(z_0_dir / "p0.tfw", world)
      im.save(z_0_dir / "p0.tif")
  
      # Zoom level one.
      # File 1: complete containment within p0.
      z_1_dir = tmp_path / "z_1"
      z_1_dir.mkdir()
      world = dict(
          x_pix_size=2,
          y_rotation=0,
          x_rotation=0,
          y_pix_size=2,
          x_center=21,
          y_center=21,
      )
      im = Image.new("RGB", (30, 30))
      _save_world(z_1_dir / "p1.tfw", world)
      im.save(z_1_dir / "p1.tif")
  
      # Zoom level two.
      # File 1: intersect right edge with p1 left edge.
      z_2_dir = tmp_path / "z_2"
      z_2_dir.mkdir()
      world = dict(
          x_pix_size=2,
          y_rotation=0,
          x_rotation=0,
          y_pix_size=2,
          x_center=6,
          y_center=21,
      )
      im = Image.new("RGB", (5, 5))
      _save_world(z_2_dir / "p2-1.tfw", world)
      im.save(z_2_dir / "p2-1.tif")
      # File 2: intersect upper right corner with p1
      #         lower left corner.
      world = dict(
          x_pix_size=2,
          y_rotation=0,
          x_rotation=0,
          y_pix_size=2,
          x_center=6,
          y_center=6,
      )
      im = Image.new("RGB", (5, 5))
      _save_world(z_2_dir / "p2-2.tfw", world)
      im.save(z_2_dir / "p2-2.tif")
      # File 3: complete containment within p1.
      world = dict(
          x_pix_size=2,
          y_rotation=0,
          x_rotation=0,
          y_pix_size=2,
          x_center=41,
          y_center=41,
      )
      im = Image.new("RGB", (5, 5))
      _save_world(z_2_dir / "p2-3.tfw", world)
      im.save(z_2_dir / "p2-3.tif")
      # File 4: overlap with p1 right edge.
      world = dict(
          x_pix_size=2,
          y_rotation=0,
          x_rotation=0,
          y_pix_size=2,
          x_center=76,
          y_center=61,
      )
      im = Image.new("RGB", (5, 5))
      _save_world(z_2_dir / "p2-4.tfw", world)
      im.save(z_2_dir / "p2-4.tif")
      # File 5: overlap with p1 bottom right corner.
      world = dict(
          x_pix_size=2,
          y_rotation=0,
          x_rotation=0,
          y_pix_size=2,
          x_center=76,
          y_center=76,
      )
      im = Image.new("RGB", (5, 5))
      _save_world(z_2_dir / "p2-5.tfw", world)
      im.save(z_2_dir / "p2-5.tif")
  
      # Provided in reverse order in order to test the area sorting.
      items = [
          ("dummy-z-2", z_2_dir),
          ("dummy-z-1", z_1_dir),
          ("dummy-z-0", z_0_dir),
      ]
      nic = cimg_nest.NestedImageCollection.from_configuration(
          "dummy", None, items
      )
  
      names = [collection.name for collection in nic._collections]
      zoom_levels = ["dummy-z-0", "dummy-z-1", "dummy-z-2"]
      assert names == zoom_levels
  
      # Check all images are loaded.
      for zoom, expected_image_count in zip(zoom_levels, [1, 1, 5]):
          images = nic._collections_by_name[zoom].images
          assert len(images) == expected_image_count
  
      # Check the image ancestry.
      zoom_levels = ["dummy-z-0", "dummy-z-1"]
      assert sorted(k[0] for k in nic._ancestry.keys()) == zoom_levels
  
      expected = [
          ("dummy-z-0", ["p1.tif"]),
          ("dummy-z-1", ["p2-3.tif", "p2-4.tif", "p2-5.tif"]),
      ]
      for zoom, image_names in expected:
          key = [k for k in nic._ancestry.keys() if k[0] == zoom][0]
          ancestry = nic._ancestry[key]
          fnames = sorted(item[1].filename.name for item in ancestry)
          assert image_names == fnames
  
      # Check image retrieval for specific domain.
      items = [
          (sgeom.box(20, 20, 80, 80), 3),
          (sgeom.box(20, 20, 75, 75), 1),
          (sgeom.box(40, 40, 85, 85), 3),
      ]
      for domain, expected in items:
          result = [
              image for image in nic.find_images(domain, "dummy-z-2")
          ]
          assert len(result) == expected
  
imports: import io
  from pathlib import Path
  import pickle
  import shutil
  import sys
  import warnings
  import numpy
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from PIL import Image
  import pytest
  import shapely.geometry
  from cartopy import config
  import cartopy.io.img_nest
  import cartopy.io.img_tiles
label_desc: Use image node_id 3 for calling a global function with example usage: test_intersect(tmp_path) without return types