@masatomakino/threejs-interactive-object
    Preparing search index...

    Function isContain

    • Determines whether a pointer event occurs within the boundaries of a specified viewport.

      Parameters

      • canvas: HTMLCanvasElement

        The HTML canvas element that defines the coordinate space

      • viewport: undefined | Vector4

        Optional viewport definition (Vector4: x, y, width, height). If undefined, always returns true

      • event: PointerEvent

        The pointer event to test for containment

      Returns boolean

      True if the pointer is within the viewport boundaries, false otherwise

      Performs boundary checking to determine if a pointer event (mouse, touch, pen) occurs within the specified viewport region. This function is essential for multi-viewport applications where different canvas regions handle different interactions or render different content.

      Boundary Logic: The function uses inclusive boundary checking (≤ and ≥) to ensure that pointer events exactly on viewport edges are considered within bounds. This prevents edge cases where interactions at viewport boundaries might be incorrectly rejected.

      Viewport Handling:

      • viewport === undefined: Always returns true (entire canvas is interactive)
      • viewport === null: Always returns true (entire canvas is interactive)
      • Valid viewport: Performs precise boundary checking against converted rectangle

      Coordinate Systems: The function automatically handles coordinate system differences between Three.js viewports (bottom-left origin) and DOM pointer events (top-left origin) by using convertToRectangle() for accurate boundary conversion.

      // Basic viewport containment check
      const viewport = new Vector4(100, 50, 200, 150);
      const isInViewport = isContain(canvas, viewport, event);

      // Full-canvas applications (no viewport restrictions)
      const isInCanvas = isContain(canvas, undefined, event); // Always true

      Used extensively by MouseEventManager for viewport boundary validation. Boundary checking is inclusive and optimized with early returns for undefined viewports.

      • convertToRectangle - Viewport to rectangle conversion utility
      • MouseEventManager - Primary consumer for interaction boundary validation
      • Rectangle - Boundary structure used internally