@@ -1050,20 +1050,27 @@ void ImDrawList::PathArcTo(const ImVec2& center, float radius, float a_min, floa
1050
1050
}
1051
1051
}
1052
1052
1053
- // Cubic bezier
1054
- ImVec2 ImBezierCalc (const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float t)
1053
+ ImVec2 ImBezierCubicCalc (const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float t)
1055
1054
{
1056
1055
float u = 1 .0f - t;
1057
- float w1 = u*u* u;
1058
- float w2 = 3 *u*u* t;
1059
- float w3 = 3 *u*t* t;
1060
- float w4 = t*t* t;
1061
- return ImVec2 (w1* p1.x + w2* p2.x + w3* p3.x + w4* p4.x , w1* p1.y + w2* p2.y + w3* p3.y + w4* p4.y );
1056
+ float w1 = u * u * u;
1057
+ float w2 = 3 * u * u * t;
1058
+ float w3 = 3 * u * t * t;
1059
+ float w4 = t * t * t;
1060
+ return ImVec2 (w1 * p1.x + w2 * p2.x + w3 * p3.x + w4 * p4.x , w1 * p1.y + w2 * p2.y + w3 * p3.y + w4 * p4.y );
1062
1061
}
1063
1062
1064
- // Cubic bezier
1065
- // Closely mimics BezierClosestPointCasteljauStep() in imgui.cpp
1066
- static void PathBezierToCasteljau (ImVector<ImVec2>* path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float tess_tol, int level)
1063
+ ImVec2 ImBezierQuadraticCalc (const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, float t)
1064
+ {
1065
+ float u = 1 .0f - t;
1066
+ float w1 = u * u;
1067
+ float w2 = 2 * u * t;
1068
+ float w3 = t * t;
1069
+ return ImVec2 (w1 * p1.x + w2 * p2.x + w3 * p3.x , w1 * p1.y + w2 * p2.y + w3 * p3.y );
1070
+ }
1071
+
1072
+ // Closely mimics ImBezierCubicClosestPointCasteljau() in imgui.cpp
1073
+ 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)
1067
1074
{
1068
1075
float dx = x4 - x1;
1069
1076
float dy = y4 - y1;
@@ -1083,39 +1090,12 @@ static void PathBezierToCasteljau(ImVector<ImVec2>* path, float x1, float y1, fl
1083
1090
float x123 = (x12 + x23) * 0 .5f , y123 = (y12 + y23) * 0 .5f ;
1084
1091
float x234 = (x23 + x34) * 0 .5f , y234 = (y23 + y34) * 0 .5f ;
1085
1092
float x1234 = (x123 + x234) * 0 .5f , y1234 = (y123 + y234) * 0 .5f ;
1086
- PathBezierToCasteljau (path, x1, y1, x12, y12, x123, y123, x1234, y1234, tess_tol, level + 1 );
1087
- PathBezierToCasteljau (path, x1234, y1234, x234, y234, x34, y34, x4, y4, tess_tol, level + 1 );
1088
- }
1089
- }
1090
-
1091
- // Cubic bezier
1092
- void ImDrawList::PathBezierCurveTo (const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments)
1093
- {
1094
- ImVec2 p1 = _Path.back ();
1095
- if (num_segments == 0 )
1096
- {
1097
- PathBezierToCasteljau (&_Path, p1.x , p1.y , p2.x , p2.y , p3.x , p3.y , p4.x , p4.y , _Data->CurveTessellationTol , 0 ); // Auto-tessellated
1098
- }
1099
- else
1100
- {
1101
- float t_step = 1 .0f / (float )num_segments;
1102
- for (int i_step = 1 ; i_step <= num_segments; i_step++)
1103
- _Path.push_back (ImBezierCalc (p1, p2, p3, p4, t_step * i_step));
1093
+ PathBezierCubicCurveToCasteljau (path, x1, y1, x12, y12, x123, y123, x1234, y1234, tess_tol, level + 1 );
1094
+ PathBezierCubicCurveToCasteljau (path, x1234, y1234, x234, y234, x34, y34, x4, y4, tess_tol, level + 1 );
1104
1095
}
1105
1096
}
1106
1097
1107
- // Quadratic bezier
1108
- ImVec2 ImQuadBezierCalc (const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, float t)
1109
- {
1110
- float u = 1 .0f - t;
1111
- float w1 = u * u;
1112
- float w2 = 2 * u * t;
1113
- float w3 = t * t;
1114
- return ImVec2 (w1 * p1.x + w2 * p2.x + w3 * p3.x , w1 * p1.y + w2 * p2.y + w3 * p3.y );
1115
- }
1116
-
1117
- // Quadratic bezier
1118
- static void PathQuadBezierToCasteljau (ImVector<ImVec2>* path, float x1, float y1, float x2, float y2, float x3, float y3, float tess_tol, int level)
1098
+ static void PathBezierQuadraticCurveToCasteljau (ImVector<ImVec2>* path, float x1, float y1, float x2, float y2, float x3, float y3, float tess_tol, int level)
1119
1099
{
1120
1100
float dx = x3 - x1, dy = y3 - y1;
1121
1101
float det = (x2 - x3) * dy - (y2 - y3) * dx;
@@ -1128,24 +1108,38 @@ static void PathQuadBezierToCasteljau(ImVector<ImVec2>* path, float x1, float y1
1128
1108
float x12 = (x1 + x2) * 0 .5f , y12 = (y1 + y2) * 0 .5f ;
1129
1109
float x23 = (x2 + x3) * 0 .5f , y23 = (y2 + y3) * 0 .5f ;
1130
1110
float x123 = (x12 + x23) * 0 .5f , y123 = (y12 + y23) * 0 .5f ;
1131
- PathQuadBezierToCasteljau (path, x1, y1, x12, y12, x123, y123, tess_tol, level + 1 );
1132
- PathQuadBezierToCasteljau (path, x123, y123, x23, y23, x3, y3, tess_tol, level + 1 );
1111
+ PathBezierQuadraticCurveToCasteljau (path, x1, y1, x12, y12, x123, y123, tess_tol, level + 1 );
1112
+ PathBezierQuadraticCurveToCasteljau (path, x123, y123, x23, y23, x3, y3, tess_tol, level + 1 );
1113
+ }
1114
+ }
1115
+
1116
+ void ImDrawList::PathBezierCubicCurveTo (const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments)
1117
+ {
1118
+ ImVec2 p1 = _Path.back ();
1119
+ if (num_segments == 0 )
1120
+ {
1121
+ PathBezierCubicCurveToCasteljau (&_Path, p1.x , p1.y , p2.x , p2.y , p3.x , p3.y , p4.x , p4.y , _Data->CurveTessellationTol , 0 ); // Auto-tessellated
1122
+ }
1123
+ else
1124
+ {
1125
+ float t_step = 1 .0f / (float )num_segments;
1126
+ for (int i_step = 1 ; i_step <= num_segments; i_step++)
1127
+ _Path.push_back (ImBezierCubicCalc (p1, p2, p3, p4, t_step * i_step));
1133
1128
}
1134
1129
}
1135
1130
1136
- // Quadratic bezier
1137
- void ImDrawList::PathQuadBezierCurveTo (const ImVec2& p2, const ImVec2& p3, int num_segments)
1131
+ void ImDrawList::PathBezierQuadraticCurveTo (const ImVec2& p2, const ImVec2& p3, int num_segments)
1138
1132
{
1139
1133
ImVec2 p1 = _Path.back ();
1140
1134
if (num_segments == 0 )
1141
1135
{
1142
- PathQuadBezierToCasteljau (&_Path, p1.x , p1.y , p2.x , p2.y , p3.x , p3.y , _Data->CurveTessellationTol , 0 ); // Auto-tessellated
1136
+ PathBezierQuadraticCurveToCasteljau (&_Path, p1.x , p1.y , p2.x , p2.y , p3.x , p3.y , _Data->CurveTessellationTol , 0 );// Auto-tessellated
1143
1137
}
1144
1138
else
1145
1139
{
1146
1140
float t_step = 1 .0f / (float )num_segments;
1147
1141
for (int i_step = 1 ; i_step <= num_segments; i_step++)
1148
- _Path.push_back (ImQuadBezierCalc (p1, p2, p3, t_step * i_step));
1142
+ _Path.push_back (ImBezierQuadraticCalc (p1, p2, p3, t_step * i_step));
1149
1143
}
1150
1144
}
1151
1145
@@ -1359,24 +1353,24 @@ void ImDrawList::AddNgonFilled(const ImVec2& center, float radius, ImU32 col, in
1359
1353
}
1360
1354
1361
1355
// Cubic Bezier takes 4 controls points
1362
- void ImDrawList::AddBezierCurve (const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness, int num_segments)
1356
+ void ImDrawList::AddBezierCubic (const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness, int num_segments)
1363
1357
{
1364
1358
if ((col & IM_COL32_A_MASK) == 0 )
1365
1359
return ;
1366
1360
1367
1361
PathLineTo (p1);
1368
- PathBezierCurveTo (p2, p3, p4, num_segments);
1362
+ PathBezierCubicCurveTo (p2, p3, p4, num_segments);
1369
1363
PathStroke (col, false , thickness);
1370
1364
}
1371
1365
1372
1366
// Quadratic Bezier takes 3 controls points
1373
- void ImDrawList::AddQuadBezierCurve (const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col, float thickness, int num_segments)
1367
+ void ImDrawList::AddBezierQuadratic (const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col, float thickness, int num_segments)
1374
1368
{
1375
1369
if ((col & IM_COL32_A_MASK) == 0 )
1376
1370
return ;
1377
1371
1378
1372
PathLineTo (p1);
1379
- PathQuadBezierCurveTo (p2, p3, num_segments);
1373
+ PathBezierQuadraticCurveTo (p2, p3, num_segments);
1380
1374
PathStroke (col, false , thickness);
1381
1375
}
1382
1376
0 commit comments