Commit 92a6db0e for tesseract

commit 92a6db0e0f409eedf8864d3a9970a84500c28982
Author: Stefan Weil <sw@weilnetz.de>
Date:   Sat Aug 15 17:28:48 2026 +0200

    Fix CID 1451543 (Unused value)

    In Classify::MakeNewTempProtos the value assigned to A2 was never
    read, because the angle of the new temporary proto was computed from
    A1 only. The code which computes A2 dates back to the original
    implementation of 1991 and was probably meant to be used: X and Y of
    the new proto are the midpoints of the first and last feature, so the
    angle should be the midpoint of the two angles as well.

    Use the circular midpoint which takes the shorter arc between A1 and
    A2 into account, because the angles are normalized to the range 0..1.

    Assisted-by: OpenCode / big-pickle (opencode)
    Signed-off-by: Stefan Weil <sw@weilnetz.de>

diff --git a/src/classify/adaptmatch.cpp b/src/classify/adaptmatch.cpp
index 0aca62c6..f9f38fbe 100644
--- a/src/classify/adaptmatch.cpp
+++ b/src/classify/adaptmatch.cpp
@@ -1801,6 +1801,21 @@ PROTO_ID Classify::MakeNewTempProtos(FEATURE_SET Features, int NumBadFeat, FEATU
     Y2 = F2->Params[PicoFeatY];
     A2 = F2->Params[PicoFeatDir];

+    // The angle of the new proto is the circular midpoint of the angles
+    // of the first and last feature, so compute it along the shorter arc.
+    float delta = A2 - A1;
+    if (delta > 0.5f) {
+      delta -= 1.0f;
+    } else if (delta < -0.5f) {
+      delta += 1.0f;
+    }
+    float Angle = A1 + delta / 2.0f;
+    if (Angle < 0.0f) {
+      Angle += 1.0f;
+    } else if (Angle >= 1.0f) {
+      Angle -= 1.0f;
+    }
+
     Pid = AddIntProto(IClass);
     if (Pid == NO_PROTO) {
       return (NO_PROTO);
@@ -1813,7 +1828,7 @@ PROTO_ID Classify::MakeNewTempProtos(FEATURE_SET Features, int NumBadFeat, FEATU
    ConvertProto assumes that the Y dimension varies from -0.5 to 0.5
    instead of the -0.25 to 0.75 used in baseline normalization */
     Proto->Length = SegmentLength;
-    Proto->Angle = A1;
+    Proto->Angle = Angle;
     Proto->X = (X1 + X2) / 2;
     Proto->Y = (Y1 + Y2) / 2 - Y_DIM_OFFSET;
     FillABC(Proto);