mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
21 lines
517 B
TypeScript
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
|
|
}
|