MCPcopy Create free account
hub / github.com/RenderKit/embree / ImBezierCubicClosestPoint

Function ImBezierCubicClosestPoint

tutorials/common/imgui/imgui.cpp:1501–1521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1499//-----------------------------------------------------------------------------
1500
1501ImVec2 ImBezierCubicClosestPoint(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& p, int num_segments)
1502{
1503 IM_ASSERT(num_segments > 0); // Use ImBezierCubicClosestPointCasteljau()
1504 ImVec2 p_last = p1;
1505 ImVec2 p_closest;
1506 float p_closest_dist2 = FLT_MAX;
1507 float t_step = 1.0f / (float)num_segments;
1508 for (int i_step = 1; i_step <= num_segments; i_step++)
1509 {
1510 ImVec2 p_current = ImBezierCubicCalc(p1, p2, p3, p4, t_step * i_step);
1511 ImVec2 p_line = ImLineClosestPoint(p_last, p_current, p);
1512 float dist2 = ImLengthSqr(p - p_line);
1513 if (dist2 < p_closest_dist2)
1514 {
1515 p_closest = p_line;
1516 p_closest_dist2 = dist2;
1517 }
1518 p_last = p_current;
1519 }
1520 return p_closest;
1521}
1522
1523// Closely mimics PathBezierToCasteljau() in imgui_draw.cpp
1524static void ImBezierCubicClosestPointCasteljauStep(const ImVec2& p, ImVec2& p_closest, ImVec2& p_last, float& p_closest_dist2, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float tess_tol, int level)

Callers

nothing calls this directly

Calls 3

ImBezierCubicCalcFunction · 0.85
ImLineClosestPointFunction · 0.85
ImLengthSqrFunction · 0.85

Tested by

no test coverage detected