@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
Current camera instance (provides boundaries and viewport dimensions)
config
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:
- Calculating the potential new position (current + delta)
- Clamping that position to boundaries
- Returning the difference (clamped - current) as the new delta
Behavior depends on configuration:
- If
clampTranslationis false: Returns delta unchanged - If
limitEntireViewPortis false: Clamps based on camera center - If
limitEntireViewPortis 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
// 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 beyondSee
- clampPoint for center-point clamping
- clampPointEntireViewPort for full-viewport clamping
- createDefaultPanByHandler for default pipeline usage