MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / ImLineClosestPoint

Function ImLineClosestPoint

imgui_tiny_app/imgui/imgui.cpp:2149–2160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2147}
2148
2149ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p)
2150{
2151 ImVec2 ap = p - a;
2152 ImVec2 ab_dir = b - a;
2153 float dot = ap.x * ab_dir.x + ap.y * ab_dir.y;
2154 if (dot < 0.0f)
2155 return a;
2156 float ab_len_sqr = ab_dir.x * ab_dir.x + ab_dir.y * ab_dir.y;
2157 if (dot > ab_len_sqr)
2158 return b;
2159 return a + ab_dir * dot / ab_len_sqr;
2160}
2161
2162bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p)
2163{

Callers 3

ImTriangleClosestPointFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected