tesseract  5.0.0-alpha-619-ge9db
fpoint.cpp
Go to the documentation of this file.
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 <cstdio>
23 #include <cmath> // for M_PI
24 
25 /*----------------------------------------------------------------------------
26  Public Code
27 ----------------------------------------------------------------------------*/
28 
29 float DistanceBetween(FPOINT A, FPOINT B) {
30  const double xd = XDelta(A, B);
31  const double yd = YDelta(A, B);
32  return sqrt(static_cast<double>(xd * xd + yd * yd));
33 }
34 
44 float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale) {
45  float NumRadsInCircle = 2.0 * M_PI;
46 
47  float Angle = AngleFrom (*Point1, *Point2);
48  if (Angle < 0.0)
49  Angle += NumRadsInCircle;
50  Angle *= FullScale / NumRadsInCircle;
51  if (Angle < 0.0 || Angle >= FullScale)
52  Angle = 0.0;
53  return (Angle);
54 }
fpoint.h
NormalizedAngleFrom
float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale)
Definition: fpoint.cpp:43
FPOINT
Definition: fpoint.h:28
AngleFrom
#define AngleFrom(A, B)
Definition: fpoint.h:40
DistanceBetween
float DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:28
YDelta
#define YDelta(A, B)
Definition: fpoint.h:38
XDelta
#define XDelta(A, B)
Definition: fpoint.h:37