MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / ImBezierCubicClosestPoint

Function ImBezierCubicClosestPoint

KBotExt/imgui/imgui.cpp:1606–1626  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1604//-----------------------------------------------------------------------------
1605
1606ImVec2 ImBezierCubicClosestPoint(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& p, int num_segments)
1607{
1608 IM_ASSERT(num_segments > 0); // Use ImBezierCubicClosestPointCasteljau()
1609 ImVec2 p_last = p1;
1610 ImVec2 p_closest;
1611 float p_closest_dist2 = FLT_MAX;
1612 float t_step = 1.0f / (float)num_segments;
1613 for (int i_step = 1; i_step <= num_segments; i_step++)
1614 {
1615 ImVec2 p_current = ImBezierCubicCalc(p1, p2, p3, p4, t_step * i_step);
1616 ImVec2 p_line = ImLineClosestPoint(p_last, p_current, p);
1617 float dist2 = ImLengthSqr(p - p_line);
1618 if (dist2 < p_closest_dist2)
1619 {
1620 p_closest = p_line;
1621 p_closest_dist2 = dist2;
1622 }
1623 p_last = p_current;
1624 }
1625 return p_closest;
1626}
1627
1628// Closely mimics PathBezierToCasteljau() in imgui_draw.cpp
1629static 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