Coverage Report

Created: 2026-09-14 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tesseract/src/classify/fpoint.cpp
Line
Count
Source
1
/******************************************************************************
2
 ** Filename:    fpoint.cpp
3
 ** Purpose:     Abstract data type for a 2D point (floating point coords)
4
 ** Author:      Dan Johnson
5
 **
6
 ** (c) Copyright Hewlett-Packard Company, 1988.
7
 ** Licensed under the Apache License, Version 2.0 (the "License");
8
 ** you may not use this file except in compliance with the License.
9
 ** You may obtain a copy of the License at
10
 ** http://www.apache.org/licenses/LICENSE-2.0
11
 ** Unless required by applicable law or agreed to in writing, software
12
 ** distributed under the License is distributed on an "AS IS" BASIS,
13
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 ** See the License for the specific language governing permissions and
15
 ** limitations under the License.
16
 ******************************************************************************/
17
/*----------------------------------------------------------------------------
18
          Include Files and Type Defines
19
----------------------------------------------------------------------------*/
20
#define _USE_MATH_DEFINES // for M_PI
21
#include "fpoint.h"
22
#include <cmath> // for M_PI
23
#include <cstdio>
24
25
/*----------------------------------------------------------------------------
26
              Public Code
27
----------------------------------------------------------------------------*/
28
29
27.8k
float DistanceBetween(FPOINT A, FPOINT B) {
30
27.8k
  const double xd = XDelta(A, B);
31
27.8k
  const double yd = YDelta(A, B);
32
27.8k
  return sqrt(static_cast<double>(xd * xd + yd * yd));
33
27.8k
}
34
35
/**
36
 * Return the angle from Point1 to Point2 normalized to
37
 * lie in the range 0 to FullScale (where FullScale corresponds
38
 * to 2*pi or 360 degrees).
39
 * @param Point1 points to compute angle between
40
 * @param Point2 points to compute angle between
41
 * @param FullScale value to associate with 2*pi
42
 * @return angle
43
 */
44
27.8k
float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale) {
45
27.8k
  float NumRadsInCircle = 2.0 * M_PI;
46
47
27.8k
  float Angle = AngleFrom(*Point1, *Point2);
48
27.8k
  if (Angle < 0.0) {
49
11.2k
    Angle += NumRadsInCircle;
50
11.2k
  }
51
27.8k
  Angle *= FullScale / NumRadsInCircle;
52
27.8k
  if (Angle < 0.0 || Angle >= FullScale) {
53
0
    Angle = 0.0;
54
0
  }
55
27.8k
  return (Angle);
56
27.8k
}