Browse Source

ImDrawList: Minor optimisation.

ocornut 10 years ago
parent
commit
a48130b682
1 changed files with 8 additions and 5 deletions
  1. 8 5
      imgui.cpp

+ 8 - 5
imgui.cpp

@@ -7762,11 +7762,14 @@ void ImDrawList::PrimQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, con
 void ImDrawList::PrimLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)
 {
     const float inv_length = 1.0f / sqrtf(ImLengthSqr(b - a));
-    const ImVec2 hn = (b - a) * (thickness * 0.5f * inv_length);// half normalized
-    const ImVec2 hp0 = ImVec2(+hn.y, -hn.x);                    // half perpendiculars + user offset
-    const ImVec2 hp1 = ImVec2(-hn.y, +hn.x);
-
-    PrimQuad(a + hp0, b + hp0, b + hp1, a + hp1, col);
+    const float dx = (b.x - a.x) * (thickness * 0.5f * inv_length); // line direction, halved
+    const float dy = (b.y - a.y) * (thickness * 0.5f * inv_length); // line direction, halved
+
+    const ImVec2 pa(a.x + dy, a.y - dx);
+    const ImVec2 pb(b.x + dy, b.y - dx);
+    const ImVec2 pc(b.x - dy, b.y + dx);
+    const ImVec2 pd(a.x - dy, a.y + dx);
+    PrimQuad(pa, pb, pc, pd, col);
 }
 
 void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)