Function constrainBounce

constrainBounce yields a function that affects t's position and velocity such that it bounces within bounds.

// Setup bounce with area constraints
// Reduce velocity by 10% with each impact
const b = constrainBounce({ width:200, height:500 }, 0.9);

// Thing
const t = {
position: { x: 50, y: 50 },
velocity: { x: 0.3, y: 0.01 }
};

// `b` returns an altereted version of `t`, with the
// bounce logic applied.
const bounced = b(t);

dampen parameter allows velocity to be dampened with each bounce. A value of 0.9 for example reduces velocity by 10%. A value of 1.1 will increase velocity by 10% with each bounce.