Pixel Data JS - v0.28.0
    Preparing search index...

    Function trimMaskRectBounds

    • Intersects a target rectangle with a boundary, trimming dimensions and masks in-place. This utility calculates the axis-aligned intersection between the target and bounds. If the target includes a mask (as in a NullableMaskRect), the mask is physically cropped and re-aligned using extractMaskBuffer to match the new dimensions.

      Type Parameters

      Parameters

      • target: T

        The rectangle or selection object to be trimmed. Note: This object is mutated in-place.

      • bounds: Rect

        The boundary rectangle defining the maximum allowable area (e.g., canvas dimensions).

      Returns void

      const selection = { x: -10, y: -10, w: 50, h: 50, mask: new Uint8Array(2500) };
      const canvas = { x: 0, y: 0, w: 100, h: 100 };
      // Selection will be moved to (0,0) and resized to 40x40.
      // The mask is cropped by 10 px on the top and left.
      trimRectBounds(selection, canvas);