mirror of
https://github.com/ocornut/imgui.git
synced 2026-08-21 06:41:09 +00:00
(Breaking) Style: obsoleted style.CurveTessellationTol in favor of style.CurveTesselationMaxError.
cc #3127, #3664, #3665
This commit is contained in:
@@ -1370,7 +1370,7 @@ ImVec2 ImBezierQuadraticCalc(const ImVec2& p1, const ImVec2& p2, const ImVec2& p
|
||||
}
|
||||
|
||||
// Closely mimics ImBezierCubicClosestPointCasteljau() in imgui.cpp
|
||||
static void PathBezierCubicCurveToCasteljau(ImVector<ImVec2>* path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float tess_tol, int level)
|
||||
static void PathBezierCubicCurveToCasteljau(ImVector<ImVec2>* path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float max_error_sqr, int level)
|
||||
{
|
||||
float dx = x4 - x1;
|
||||
float dy = y4 - y1;
|
||||
@@ -1378,7 +1378,7 @@ static void PathBezierCubicCurveToCasteljau(ImVector<ImVec2>* path, float x1, fl
|
||||
float d3 = (x3 - x4) * dy - (y3 - y4) * dx;
|
||||
d2 = (d2 >= 0) ? d2 : -d2;
|
||||
d3 = (d3 >= 0) ? d3 : -d3;
|
||||
if ((d2 + d3) * (d2 + d3) < tess_tol * (dx * dx + dy * dy))
|
||||
if ((d2 + d3) * (d2 + d3) < max_error_sqr * (dx * dx + dy * dy))
|
||||
{
|
||||
path->push_back(ImVec2(x4, y4));
|
||||
}
|
||||
@@ -1390,16 +1390,16 @@ static void PathBezierCubicCurveToCasteljau(ImVector<ImVec2>* path, float x1, fl
|
||||
float x123 = (x12 + x23) * 0.5f, y123 = (y12 + y23) * 0.5f;
|
||||
float x234 = (x23 + x34) * 0.5f, y234 = (y23 + y34) * 0.5f;
|
||||
float x1234 = (x123 + x234) * 0.5f, y1234 = (y123 + y234) * 0.5f;
|
||||
PathBezierCubicCurveToCasteljau(path, x1, y1, x12, y12, x123, y123, x1234, y1234, tess_tol, level + 1);
|
||||
PathBezierCubicCurveToCasteljau(path, x1234, y1234, x234, y234, x34, y34, x4, y4, tess_tol, level + 1);
|
||||
PathBezierCubicCurveToCasteljau(path, x1, y1, x12, y12, x123, y123, x1234, y1234, max_error_sqr, level + 1);
|
||||
PathBezierCubicCurveToCasteljau(path, x1234, y1234, x234, y234, x34, y34, x4, y4, max_error_sqr, level + 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void PathBezierQuadraticCurveToCasteljau(ImVector<ImVec2>* path, float x1, float y1, float x2, float y2, float x3, float y3, float tess_tol, int level)
|
||||
static void PathBezierQuadraticCurveToCasteljau(ImVector<ImVec2>* path, float x1, float y1, float x2, float y2, float x3, float y3, float max_error_sqr, int level)
|
||||
{
|
||||
float dx = x3 - x1, dy = y3 - y1;
|
||||
float det = (x2 - x3) * dy - (y2 - y3) * dx;
|
||||
if (det * det * 4.0f < tess_tol * (dx * dx + dy * dy))
|
||||
if (det * det * 4.0f < max_error_sqr * (dx * dx + dy * dy))
|
||||
{
|
||||
path->push_back(ImVec2(x3, y3));
|
||||
}
|
||||
@@ -1408,8 +1408,8 @@ static void PathBezierQuadraticCurveToCasteljau(ImVector<ImVec2>* path, float x1
|
||||
float x12 = (x1 + x2) * 0.5f, y12 = (y1 + y2) * 0.5f;
|
||||
float x23 = (x2 + x3) * 0.5f, y23 = (y2 + y3) * 0.5f;
|
||||
float x123 = (x12 + x23) * 0.5f, y123 = (y12 + y23) * 0.5f;
|
||||
PathBezierQuadraticCurveToCasteljau(path, x1, y1, x12, y12, x123, y123, tess_tol, level + 1);
|
||||
PathBezierQuadraticCurveToCasteljau(path, x123, y123, x23, y23, x3, y3, tess_tol, level + 1);
|
||||
PathBezierQuadraticCurveToCasteljau(path, x1, y1, x12, y12, x123, y123, max_error_sqr, level + 1);
|
||||
PathBezierQuadraticCurveToCasteljau(path, x123, y123, x23, y23, x3, y3, max_error_sqr, level + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1418,8 +1418,9 @@ void ImDrawList::PathBezierCubicCurveTo(const ImVec2& p2, const ImVec2& p3, cons
|
||||
ImVec2 p1 = _Path.back();
|
||||
if (num_segments == 0)
|
||||
{
|
||||
IM_ASSERT(_Data->CurveTessellationTol > 0.0f);
|
||||
PathBezierCubicCurveToCasteljau(&_Path, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, _Data->CurveTessellationTol, 0); // Auto-tessellated
|
||||
IM_ASSERT(_Data->CurveTessellationMaxError > 0.0f);
|
||||
float max_error_sqr = _Data->CurveTessellationMaxError * _Data->CurveTessellationMaxError;
|
||||
PathBezierCubicCurveToCasteljau(&_Path, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, max_error_sqr, 0); // Auto-tessellated
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1434,8 +1435,9 @@ void ImDrawList::PathBezierQuadraticCurveTo(const ImVec2& p2, const ImVec2& p3,
|
||||
ImVec2 p1 = _Path.back();
|
||||
if (num_segments == 0)
|
||||
{
|
||||
IM_ASSERT(_Data->CurveTessellationTol > 0.0f);
|
||||
PathBezierQuadraticCurveToCasteljau(&_Path, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, _Data->CurveTessellationTol, 0);// Auto-tessellated
|
||||
IM_ASSERT(_Data->CurveTessellationMaxError > 0.0f);
|
||||
float max_error_sqr = _Data->CurveTessellationMaxError * _Data->CurveTessellationMaxError;
|
||||
PathBezierQuadraticCurveToCasteljau(&_Path, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, max_error_sqr, 0);// Auto-tessellated
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user