Raycaster has a property called linePrecision which is in some sense a tolerance value for the ray/line intersection test. The default value is 1. If you decrease the value, it’s possible to mitigate the mentioned effect, see https://jsfiddle.net/k1ygqz2c/2/.

It’s in general hard to provide an “exact” ray/line intersection test since lines do not have a width from a mathematical point of view. The result of the intersection test is more an approximation.

Thank you. Unfortunately the result is not perfect. I think the best way to solve this issue is to draw a transparent square plane for intersections detection and then highlight the linear square. Because I need to highlight it when the cursor is inside it bounds.