| 212 | } |
| 213 | |
| 214 | inline bool RectangleOverlapsLink( |
| 215 | const ImRect& rectangle, |
| 216 | const ImVec2& start, |
| 217 | const ImVec2& end, |
| 218 | const ImNodesAttributeType start_type) |
| 219 | { |
| 220 | // First level: simple rejection test via rectangle overlap: |
| 221 | |
| 222 | ImRect lrect = ImRect(start, end); |
| 223 | if (lrect.Min.x > lrect.Max.x) |
| 224 | { |
| 225 | ImSwap(lrect.Min.x, lrect.Max.x); |
| 226 | } |
| 227 | |
| 228 | if (lrect.Min.y > lrect.Max.y) |
| 229 | { |
| 230 | ImSwap(lrect.Min.y, lrect.Max.y); |
| 231 | } |
| 232 | |
| 233 | if (rectangle.Overlaps(lrect)) |
| 234 | { |
| 235 | // First, check if either one or both endpoinds are trivially contained |
| 236 | // in the rectangle |
| 237 | |
| 238 | if (rectangle.Contains(start) || rectangle.Contains(end)) |
| 239 | { |
| 240 | return true; |
| 241 | } |
| 242 | |
| 243 | // Second level of refinement: do a more expensive test against the |
| 244 | // link |
| 245 | |
| 246 | const CubicBezier cubic_bezier = |
| 247 | GetCubicBezier(start, end, start_type, GImNodes->Style.LinkLineSegmentsPerLength); |
| 248 | return RectangleOverlapsBezier(rectangle, cubic_bezier); |
| 249 | } |
| 250 | |
| 251 | return false; |
| 252 | } |
| 253 | |
| 254 | // [SECTION] coordinate space conversion helpers |
| 255 |
no test coverage detected