Closely mimics PathBezierToCasteljau() in imgui_draw.cpp
| 1627 | |
| 1628 | // Closely mimics PathBezierToCasteljau() in imgui_draw.cpp |
| 1629 | static 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) |
| 1630 | { |
| 1631 | float dx = x4 - x1; |
| 1632 | float dy = y4 - y1; |
| 1633 | float d2 = ((x2 - x4) * dy - (y2 - y4) * dx); |
| 1634 | float d3 = ((x3 - x4) * dy - (y3 - y4) * dx); |
| 1635 | d2 = (d2 >= 0) ? d2 : -d2; |
| 1636 | d3 = (d3 >= 0) ? d3 : -d3; |
| 1637 | if ((d2 + d3) * (d2 + d3) < tess_tol * (dx * dx + dy * dy)) |
| 1638 | { |
| 1639 | ImVec2 p_current(x4, y4); |
| 1640 | ImVec2 p_line = ImLineClosestPoint(p_last, p_current, p); |
| 1641 | float dist2 = ImLengthSqr(p - p_line); |
| 1642 | if (dist2 < p_closest_dist2) |
| 1643 | { |
| 1644 | p_closest = p_line; |
| 1645 | p_closest_dist2 = dist2; |
| 1646 | } |
| 1647 | p_last = p_current; |
| 1648 | } |
| 1649 | else if (level < 10) |
| 1650 | { |
| 1651 | float x12 = (x1 + x2) * 0.5f, y12 = (y1 + y2) * 0.5f; |
| 1652 | float x23 = (x2 + x3) * 0.5f, y23 = (y2 + y3) * 0.5f; |
| 1653 | float x34 = (x3 + x4) * 0.5f, y34 = (y3 + y4) * 0.5f; |
| 1654 | float x123 = (x12 + x23) * 0.5f, y123 = (y12 + y23) * 0.5f; |
| 1655 | float x234 = (x23 + x34) * 0.5f, y234 = (y23 + y34) * 0.5f; |
| 1656 | float x1234 = (x123 + x234) * 0.5f, y1234 = (y123 + y234) * 0.5f; |
| 1657 | ImBezierCubicClosestPointCasteljauStep(p, p_closest, p_last, p_closest_dist2, x1, y1, x12, y12, x123, y123, x1234, y1234, tess_tol, level + 1); |
| 1658 | ImBezierCubicClosestPointCasteljauStep(p, p_closest, p_last, p_closest_dist2, x1234, y1234, x234, y234, x34, y34, x4, y4, tess_tol, level + 1); |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | // tess_tol is generally the same value you would find in ImGui::GetStyle().CurveTessellationTol |
| 1663 | // Because those ImXXX functions are lower-level than ImGui:: we cannot access this value automatically. |
no test coverage detected