mirror of
				https://github.com/ocornut/imgui.git
				synced 2025-11-04 01:34:32 +00:00 
			
		
		
		
	A tiny optimization to ImLineClosestPoint. Removed unnecessary sqrtf call.
ab_lenSqr -> ab_len_sqr Moved line where ab_len_sqr is computed after the first return
This commit is contained in:
		@@ -950,14 +950,13 @@ ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    ImVec2 ap = p - a;
 | 
					    ImVec2 ap = p - a;
 | 
				
			||||||
    ImVec2 ab_dir = b - a;
 | 
					    ImVec2 ab_dir = b - a;
 | 
				
			||||||
    float ab_len = sqrtf(ab_dir.x * ab_dir.x + ab_dir.y * ab_dir.y);
 | 
					 | 
				
			||||||
    ab_dir *= 1.0f / ab_len;
 | 
					 | 
				
			||||||
    float dot = ap.x * ab_dir.x + ap.y * ab_dir.y;
 | 
					    float dot = ap.x * ab_dir.x + ap.y * ab_dir.y;
 | 
				
			||||||
    if (dot < 0.0f)
 | 
					    if (dot < 0.0f)
 | 
				
			||||||
        return a;
 | 
					        return a;
 | 
				
			||||||
    if (dot > ab_len)
 | 
					    float ab_len_sqr = ab_dir.x * ab_dir.x + ab_dir.y * ab_dir.y;
 | 
				
			||||||
 | 
					    if (dot > ab_len_sqr)
 | 
				
			||||||
        return b;
 | 
					        return b;
 | 
				
			||||||
    return a + ab_dir * dot;
 | 
					    return a + ab_dir * dot / ab_len_sqr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p)
 | 
					bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user