Skip to main content
Collision detection algorithms determine which droppable element should be activated when a draggable element is moved. Each algorithm has different characteristics and use cases.

defaultCollisionDetection

The default collision detection algorithm that combines pointer and shape intersection detection.

Description

Returns the droppable that has the greatest intersection area with the pointer coordinates. If there are no pointer coordinates, or the pointer is not intersecting with any droppable, returns the greatest intersection area between the collision shape and other intersecting droppable shapes.

Parameters

DragOperation
required
The current drag operation containing shape and position information
Droppable
required
The droppable element to check for collision

Returns

Collision | null
Returns a collision object with id, value, type, and priority properties, or null if no collision is detected

Usage Example


closestCenter

Detects collisions based on the distance between the center of the draggable and the center of droppables.

Description

Returns the distance between the droppable shape and the drag operation shape. Falls back to defaultCollisionDetection if a collision is already detected.

Parameters

DragOperation
required
The current drag operation containing shape and position information
Droppable
required
The droppable element to check for collision

Returns

Collision | null
Returns a collision object with value calculated as 1 / distance, or null if the droppable has no shape

Usage Example


closestCorners

Detects collisions based on the average distance between the corners of draggable and droppable elements.

Description

Returns the distance between the corners of the droppable shape and the drag operation shape. Calculates the average distance between all four corners.

Parameters

DragOperation
required
The current drag operation containing shape and position information
Droppable
required
The droppable element to check for collision

Returns

Collision | null
Returns a collision object with value calculated as 1 / (average corner distance), or null if the droppable has no shape

Usage Example


pointerIntersection

A high precision collision detection algorithm that detects whether the pointer intersects with a droppable element.

Description

Returns the distance between the pointer coordinates and the center of the droppable element if the pointer is within the droppable element. Returns null if the pointer is outside of the droppable element.

Parameters

DragOperation
required
The current drag operation containing pointer position
Droppable
required
The droppable element to check for pointer intersection

Returns

Collision | null
Returns a collision object with:
  • type: CollisionType.PointerIntersection
  • priority: CollisionPriority.High
  • value: 1 / distance from pointer to droppable center
Returns null if pointer is outside the droppable

Usage Example


pointerDistance

Detects collisions based on the distance between the pointer and the center of droppables.

Description

Returns the distance between the droppable shape center and the drag operation pointer position. Unlike pointerIntersection, this algorithm doesn’t require the pointer to be inside the droppable.

Parameters

DragOperation
required
The current drag operation containing pointer position
Droppable
required
The droppable element to check for collision

Returns

Collision | null
Returns a collision object with value calculated as 1 / distance, or null if the droppable has no shape

Usage Example


shapeIntersection

Detects collisions based on the intersection area between draggable and droppable shapes.

Description

Returns the droppable with the greatest intersection area with the collision shape. Uses both intersection ratio and distance to pointer for prioritization.

Parameters

DragOperation
required
The current drag operation containing shape information
Droppable
required
The droppable element to check for shape intersection

Returns

Collision | null
Returns a collision object with:
  • type: CollisionType.ShapeIntersection
  • priority: CollisionPriority.Normal
  • value: intersectionRatio / distance
Returns null if there’s no intersection or shapes are missing

Usage Example


directionBiased

A directional collision detection algorithm that prioritizes droppables in the direction of movement.

Description

Detects collisions based on the direction of drag movement. Only considers droppables that are positioned in the direction the draggable is moving. Falls back to defaultCollisionDetection when there’s no movement direction.

Parameters

DragOperation
required
The current drag operation containing shape, position, and direction information
Droppable
required
The droppable element to check for collision

Returns

Collision | null
Returns a collision object if the droppable is in the direction of movement, or null otherwise

Usage Example


CollisionDetector Type

All collision detection algorithms implement the CollisionDetector type:

Choosing an Algorithm

  • defaultCollisionDetection: Best general-purpose algorithm, works well for most use cases
  • closestCenter: Good for free-form layouts where items can be placed anywhere
  • closestCorners: Ideal for grid layouts with precise positioning requirements
  • pointerIntersection: Use when you need high precision pointer-based interactions
  • pointerDistance: Good for detecting the nearest droppable without requiring direct overlap
  • shapeIntersection: Best when you want to base collisions on overlapping areas
  • directionBiased: Optimal for keyboard navigation or when direction of movement matters