Skip to content

@ue-too/board / clampByHandler

Function: clampByHandler()

clampByHandler(delta, camera, config): Point

Defined in: packages/board/src/camera/camera-rig/pan-handler.ts:536

Handler pipeline step that clamps "pan by" deltas to prevent boundary violations.

Parameters

delta

Point

Movement delta in world space

camera

BoardCamera

Current camera instance (provides boundaries and viewport dimensions)

config

PanHandlerClampConfig

Clamping configuration

Returns

Point

Adjusted delta that respects boundaries

Remarks

This handler ensures that applying the delta won't move the camera outside boundaries. It works by:

  1. Calculating the potential new position (current + delta)
  2. Clamping that position to boundaries
  3. Returning the difference (clamped - current) as the new delta

Behavior depends on configuration:

  • If clampTranslation is false: Returns delta unchanged
  • If limitEntireViewPort is false: Clamps based on camera center
  • If limitEntireViewPort is true: Ensures entire viewport stays in bounds

The resulting delta may be zero if the camera is already at a boundary and trying to move further outside.

Can be used standalone, but typically composed into a handler pipeline via createDefaultPanByHandler or createHandlerChain.

Example

typescript
// Standalone usage
camera.position = { x: 1950, y: 500 };
camera.boundaries = { max: { x: 2000 } };

const config: PanHandlerClampConfig = {
  clampTranslation: true,
  limitEntireViewPort: false
};

const delta = { x: 100, y: 0 };  // Try to move right
const clamped = clampByHandler(delta, camera, config);
// Result: { x: 50, y: 0 } - only move to boundary, not beyond

See