function anchorInDirection(rect, direction) {
if (direction === Direction.UP) {
return { x: rect.center.x, y: rect.top };
} else if (direction === Direction.DOWN) {
return { x: rect.center.x, y: rect.bottom };
} else if (direction === Direction.LEFT) {
return { x: rect.left, y: rect.center.y };
} else if (direction === Direction.RIGHT) {
return { x: rect.right, y: rect.center.y };
} else {
throw new Error('Not a valid direction');
}
}