@ -45,7 +45,8 @@ CODE
// [SECTION] FORWARD DECLARATIONS
// [SECTION] CONTEXT AND MEMORY ALLOCATORS
// [SECTION] MAIN USER FACING STRUCTURES (ImGuiStyle, ImGuiIO)
// [SECTION] MISC HELPERS/UTILITIES (Geometry, String, Format, Hash, File functions)
// [SECTION] MISC HELPERS/UTILITIES (Geometry functions)
// [SECTION] MISC HELPERS/UTILITIES (String, Format, Hash functions)
// [SECTION] MISC HELPERS/UTILITIES (File functions)
// [SECTION] MISC HELPERS/UTILITIES (ImText* functions)
// [SECTION] MISC HELPERS/UTILITIES (Color functions)
@ -1106,12 +1107,12 @@ void ImGuiIO::ClearInputCharacters()
}
//-----------------------------------------------------------------------------
// [SECTION] MISC HELPERS/UTILITIES (Geometry , String, Format, Hash, File functions)
// [SECTION] MISC HELPERS/UTILITIES (Geometry functions)
//-----------------------------------------------------------------------------
ImVec2 ImBezierClosestPoint ( const ImVec2 & p , const ImVec2 & p 1, const ImVec2 & p2 , const ImVec2 & p3 , const ImVec2 & p4 , int num_segments )
ImVec2 ImBezierClosestPoint ( const ImVec2 & p 1, const ImVec2 & p2 , const ImVec2 & p3 , const ImVec2 & p4 , const ImVec2 & p , int num_segments )
{
IM_ASSERT ( num_segments > 0 ) ;
IM_ASSERT ( num_segments > 0 ) ; // Use ImBezierClosestPointCasteljau()
ImVec2 p_last = p1 ;
ImVec2 p_closest ;
float p_closest_dist2 = FLT_MAX ;
@ -1132,7 +1133,7 @@ ImVec2 ImBezierClosestPoint(const ImVec2& p, const ImVec2& p1, const ImVec2& p2,
}
// Closely mimics PathBezierToCasteljau() in imgui_draw.cpp
static void ClosestPointBezier Casteljau( 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 )
static void Bezier ClosestPointCasteljauStep ( 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 )
{
float dx = x4 - x1 ;
float dy = y4 - y1 ;
@ -1160,18 +1161,20 @@ static void ClosestPointBezierCasteljau(const ImVec2& p, ImVec2& p_closest, ImVe
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 ;
ClosestPointBezier Casteljau( p , p_closest , p_last , p_closest_dist2 , x1 , y1 , x12 , y12 , x123 , y123 , x1234 , y1234 , tess_tol , level + 1 ) ;
ClosestPointBezier Casteljau( p , p_closest , p_last , p_closest_dist2 , x1234 , y1234 , x234 , y234 , x34 , y34 , x4 , y4 , tess_tol , level + 1 ) ;
Bezier ClosestPointCasteljauStep ( p , p_closest , p_last , p_closest_dist2 , x1 , y1 , x12 , y12 , x123 , y123 , x1234 , y1234 , tess_tol , level + 1 ) ;
Bezier ClosestPointCasteljauStep ( p , p_closest , p_last , p_closest_dist2 , x1234 , y1234 , x234 , y234 , x34 , y34 , x4 , y4 , tess_tol , level + 1 ) ;
}
}
ImVec2 ImBezierClosestPointCasteljau ( const ImVec2 & p , const ImVec2 & p1 , const ImVec2 & p2 , const ImVec2 & p3 , const ImVec2 & p4 , float tess_tol )
// tess_tol is generally the same value you would find in ImGui::GetStyle().CurveTessellationTol
// Because those ImXXX functions are lower-level than ImGui:: we cannot access this value automatically.
ImVec2 ImBezierClosestPointCasteljau ( const ImVec2 & p1 , const ImVec2 & p2 , const ImVec2 & p3 , const ImVec2 & p4 , const ImVec2 & p , float tess_tol )
{
IM_ASSERT ( tess_tol > 0.0f ) ;
ImVec2 p_last = p1 ;
ImVec2 p_closest ;
float p_closest_dist2 = FLT_MAX ;
ClosestPointBezier Casteljau( p , p_closest , p_last , p_closest_dist2 , p1 . x , p1 . y , p2 . x , p2 . y , p3 . x , p3 . y , p4 . x , p4 . y , tess_tol , 0 ) ;
Bezier ClosestPointCasteljauStep ( p , p_closest , p_last , p_closest_dist2 , p1 . x , p1 . y , p2 . x , p2 . y , p3 . x , p3 . y , p4 . x , p4 . y , tess_tol , 0 ) ;
return p_closest ;
}
@ -1223,6 +1226,10 @@ ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c,
return proj_ca ;
}
//-----------------------------------------------------------------------------
// [SECTION] MISC HELPERS/UTILITIES (String, Format, Hash functions)
//-----------------------------------------------------------------------------
// Consider using _stricmp/_strnicmp under Windows or strcasecmp/strncasecmp. We don't actually use either ImStricmp/ImStrnicmp in the codebase any more.
int ImStricmp ( const char * str1 , const char * str2 )
{