Skip to main content
Version: Next

offsetPointsToAvoidCollision

Callable

  • offsetPointsToAvoidCollision(points: Point2D[], regionType: RegionType, regions: RegionStore[], shouldApplyInitialOffset: boolean, pasteOffset?: number): Point2D[]

  • Shifts a region's control points until its center no longer overlaps any existing region, using repeated applications of getPasteShiftDelta.

    An initial shift is applied when shouldApplyInitialOffset is true (i.e. the region is being pasted onto the same file it was copied from). After that, the loop continues shifting until the center is collision-free or the number of attempts exceeds the count of existing regions.

    Collision is defined as a Chebyshev distance smaller than pasteOffset / 2 from any valid, non-cursor region center.


    Parameters

    • points: Point2D[]

      Original control points of the region to be pasted.

    • regionType: RegionType

      The type of the region.

    • regions: RegionStore[]

      All regions currently present on the target frame.

    • shouldApplyInitialOffset: boolean

      Whether to apply one shift before collision checking.

    • pasteOffset: number = PASTE_OFFSET

      Collision radius and shift magnitude in image pixels. Defaults to PASTE_OFFSET.

    Returns Point2D[]

    A new set of control points that does not collide with any existing region (or the best position found within the attempt limit).