jsPsych/packages/plugin-free-sort-ordered/src/utils.ts
2025-05-04 22:46:56 -07:00

21 lines
517 B
TypeScript

export type boxArea = {
id: string;
left: number;
top: number;
width: number;
height: number;
};
export function inside_box(x: number, y: number, box_areas: boxArea[]): string | null {
for (const box_area of box_areas) {
const { id, left, top, width, height } = box_area;
const right = left + width;
const bottom = top + height;
if (x >= left && x <= right && y >= top && y <= bottom) {
return id; // point is inside this box
}
}
return null; // point not inside any box
}