* Whether the given mouse trajectory line defined by the slope and y intercept falls within the * submenu as defined by `submenuPoints` * @param submenuPoints the submenu DOMRect points. * @param m the slope of the trajectory line. * @param b the y intercept of the trajectory line. * @return tr
(submenuPoints: DOMRect, m: number, b: number)
| 84 | * @return true if any point on the line falls within the submenu. |
| 85 | */ |
| 86 | function isWithinSubmenu(submenuPoints: DOMRect, m: number, b: number) { |
| 87 | const {left, right, top, bottom} = submenuPoints; |
| 88 | |
| 89 | // Check for intersection with each edge of the submenu (left, right, top, bottom) |
| 90 | // by fixing one coordinate to that edge's coordinate (either x or y) and checking if the |
| 91 | // other coordinate is within bounds. |
| 92 | return ( |
| 93 | (m * left + b >= top && m * left + b <= bottom) || |
| 94 | (m * right + b >= top && m * right + b <= bottom) || |
| 95 | ((top - b) / m >= left && (top - b) / m <= right) || |
| 96 | ((bottom - b) / m >= left && (bottom - b) / m <= right) |
| 97 | ); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * TargetMenuAim predicts if a user is moving into a submenu. It calculates the |