tesseract v5.3.3.20231005
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 <cmath> // for M_PI
23#include <cstdio>
24
25/*----------------------------------------------------------------------------
26 Public Code
27----------------------------------------------------------------------------*/
28
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
44float 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 }
51 Angle *= FullScale / NumRadsInCircle;
52 if (Angle < 0.0 || Angle >= FullScale) {
53 Angle = 0.0;
54 }
55 return (Angle);
56}
#define XDelta(A, B)
Definition: fpoint.h:38
#define AngleFrom(A, B)
Definition: fpoint.h:41
#define YDelta(A, B)
Definition: fpoint.h:39
float DistanceBetween(FPOINT A, FPOINT B)
Definition: fpoint.cpp:29
float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale)
Definition: fpoint.cpp:44
Definition: fpoint.h:29