MCPcopy Create free account
hub / github.com/Nelarius/imnodes / RectangleOverlapsLink

Function RectangleOverlapsLink

imnodes.cpp:214–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212}
213
214inline 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

Callers 1

Calls 5

ImSwapFunction · 0.85
GetCubicBezierFunction · 0.85
RectangleOverlapsBezierFunction · 0.85
ContainsMethod · 0.80
ImRectFunction · 0.50

Tested by

no test coverage detected