Check if a point is inside an edge's hover region (a rectangle extending outward from the edge)
| 601 | |
| 602 | // Check if a point is inside an edge's hover region (a rectangle extending outward from the edge) |
| 603 | bool IsPointInEdgeHoverRegion(const ImVec2& point, const ImVec2& p0, const ImVec2& p1, const ImVec2& outward_dir, float width) { |
| 604 | ImVec2 dir = p1 - p0; |
| 605 | float len = ImSqrt(ImLengthSqr(dir)); |
| 606 | if (len < 0.001f) |
| 607 | return false; |
| 608 | dir = dir / len; |
| 609 | |
| 610 | // Transform point to edge's local coordinate system |
| 611 | ImVec2 local = point - p0; |
| 612 | float along = local.x * dir.x + local.y * dir.y; |
| 613 | float across = local.x * outward_dir.x + local.y * outward_dir.y; |
| 614 | |
| 615 | // Check if within bounds (rectangle extends from edge outward) |
| 616 | return along >= 0 && along <= len && across >= 0 && across <= width; |
| 617 | } |
| 618 | |
| 619 | // Compute the outward direction for an edge (perpendicular, pointing away from box center) |
| 620 | ImVec2 ComputeEdgeOutwardDir(const ImVec2& p0, const ImVec2& p1, const ImVec2& box_center) { |