GeographicLib 2.3

AuxAngle.cpp
Go to the documentation of this file.
1/**
2 * \file AuxAngle.cpp
3 * \brief Implementation for the GeographicLib::AuxAngle class.
4 *
5 * \note This is just sample code. It is not part of GeographicLib itself.
6 *
7 * This file is an implementation of the methods described in
8 * - C. F. F. Karney,
9 * <a href="https://doi.org/10.1080/00396265.2023.2217604">
10 * On auxiliary latitudes,</a>
11 * Survey Review (2023);
12 * preprint
13 * <a href="https://arxiv.org/abs/2212.05818">arXiv:2212.05818</a>.
14 * .
15 * Copyright (c) Charles Karney (2022-2023) <karney@alum.mit.edu> and licensed
16 * under the MIT/X11 License. For more information, see
17 * https://geographiclib.sourceforge.io/
18 **********************************************************************/
19
20#include <GeographicLib/AuxAngle.hpp>
21
22 namespace GeographicLib {
23
24 using namespace std;
25
26 AuxAngle AuxAngle::NaN() {
27 return AuxAngle(numeric_limits<real>::quiet_NaN(),
28 numeric_limits<real>::quiet_NaN());
29 }
30
31 AuxAngle AuxAngle::normalized() const {
32 using std::isnan; // Needed for Centos 7, ubuntu 14
33 if ( isnan( tan() ) ||
34 (fabs(_y) > numeric_limits<real>::max()/2 &&
35 fabs(_x) > numeric_limits<real>::max()/2) )
36 // deal with
37 // (0,0), (inf,inf), (nan,nan), (nan,x), (y,nan), (toobig,toobig)
38 return NaN();
39 real r = hypot(_y, _x),
40 y = _y/r, x = _x/r;
41 // deal with r = inf, then one of y,x becomes 1
42 if (isnan(y)) y = copysign(real(1), _y);
43 if (isnan(x)) x = copysign(real(1), _x);
44 return AuxAngle(y, x);
45 }
46
47 AuxAngle AuxAngle::copyquadrant(const AuxAngle& p) const {
48 return AuxAngle(copysign(y(), p.y()), copysign(x(), p.x()));
49 }
50
51 AuxAngle& AuxAngle::operator+=(const AuxAngle& p) {
52 // Do nothing if p.tan() == 0 to preserve signs of y() and x()
53 if (p.tan() != 0) {
54 real x = _x * p._x - _y * p._y;
55 _y = _y * p._x + _x * p._y;
56 _x = x;
57 }
58 return *this;
59 }
60
61} // namespace GeographicLib
AuxAngle.hpp
Header for the GeographicLib::AuxAngle class.
GeographicLib::AuxAngle
An accurate representation of angles.
Definition: AuxAngle.hpp:47
GeographicLib::AuxAngle::y
Math::real y() const
Definition: AuxAngle.hpp:70
GeographicLib::AuxAngle::x
Math::real x() const
Definition: AuxAngle.hpp:75
GeographicLib::AuxAngle::normalized
AuxAngle normalized() const
Definition: AuxAngle.cpp:31
GeographicLib::AuxAngle::operator+=
AuxAngle & operator+=(const AuxAngle &p)
Definition: AuxAngle.cpp:51
GeographicLib::AuxAngle::NaN
static AuxAngle NaN()
Definition: AuxAngle.cpp:26
GeographicLib::AuxAngle::tan
Math::real tan() const
Definition: AuxAngle.hpp:113
GeographicLib::AuxAngle::copyquadrant
AuxAngle copyquadrant(const AuxAngle &p) const
Definition: AuxAngle.cpp:47
GeographicLib::AuxAngle::AuxAngle
AuxAngle(real y=0, real x=1)
Definition: AuxAngle.hpp:65
GeographicLib
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
std
Definition: NearestNeighbor.hpp:812