Closely mimics PathBezierToCasteljau() in imgui_draw.cpp
| 1522 | |
| 1523 | // Closely mimics PathBezierToCasteljau() in imgui_draw.cpp |
| 1524 | 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) |
| 1525 | { |
| 1526 | float dx = x4 - x1; |
| 1527 | float dy = y4 - y1; |
| 1528 | float d2 = ((x2 - x4) * dy - (y2 - y4) * dx); |
| 1529 | float d3 = ((x3 - x4) * dy - (y3 - y4) * dx); |
| 1530 | d2 = (d2 >= 0) ? d2 : -d2; |
| 1531 | d3 = (d3 >= 0) ? d3 : -d3; |
| 1532 | if ((d2 + d3) * (d2 + d3) < tess_tol * (dx * dx + dy * dy)) |
| 1533 | { |
| 1534 | ImVec2 p_current(x4, y4); |
| 1535 | ImVec2 p_line = ImLineClosestPoint(p_last, p_current, p); |
| 1536 | float dist2 = ImLengthSqr(p - p_line); |
| 1537 | if (dist2 < p_closest_dist2) |
| 1538 | { |
| 1539 | p_closest = p_line; |
| 1540 | p_closest_dist2 = dist2; |
| 1541 | } |
| 1542 | p_last = p_current; |
| 1543 | } |
| 1544 | else if (level < 10) |
| 1545 | { |
| 1546 | float x12 = (x1 + x2)*0.5f, y12 = (y1 + y2)*0.5f; |
| 1547 | float x23 = (x2 + x3)*0.5f, y23 = (y2 + y3)*0.5f; |
| 1548 | float x34 = (x3 + x4)*0.5f, y34 = (y3 + y4)*0.5f; |
| 1549 | float x123 = (x12 + x23)*0.5f, y123 = (y12 + y23)*0.5f; |
| 1550 | float x234 = (x23 + x34)*0.5f, y234 = (y23 + y34)*0.5f; |
| 1551 | float x1234 = (x123 + x234)*0.5f, y1234 = (y123 + y234)*0.5f; |
| 1552 | ImBezierCubicClosestPointCasteljauStep(p, p_closest, p_last, p_closest_dist2, x1, y1, x12, y12, x123, y123, x1234, y1234, tess_tol, level + 1); |
| 1553 | ImBezierCubicClosestPointCasteljauStep(p, p_closest, p_last, p_closest_dist2, x1234, y1234, x234, y234, x34, y34, x4, y4, tess_tol, level + 1); |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | // tess_tol is generally the same value you would find in ImGui::GetStyle().CurveTessellationTol |
| 1558 | // Because those ImXXX functions are lower-level than ImGui:: we cannot access this value automatically. |
no test coverage detected