comparison mupdf-source/thirdparty/tesseract/src/classify/fpoint.cpp @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
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 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
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 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 }
51 Angle *= FullScale / NumRadsInCircle;
52 if (Angle < 0.0 || Angle >= FullScale) {
53 Angle = 0.0;
54 }
55 return (Angle);
56 }