GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_geopositions.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 56 58 96.6%
Functions: 17 18 94.4%
Branches: 14 24 58.3%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/geopositions.hpp"
30 #include "gate/mathematics.hpp"
31
32 namespace gate
33 {
34
35 9 GeoPosition::GeoPosition(real64_t latitude, real64_t longitude, real64_t altitude)
36 {
37 9 this->latitude = latitude;
38 9 this->longitude = longitude;
39 9 this->altitude = altitude;
40 9 }
41 2 GeoPosition::GeoPosition(GeoPosition const& src)
42 {
43 2 this->latitude = src.latitude;
44 2 this->longitude = src.longitude;
45 2 this->altitude = src.altitude;
46 2 }
47 1 GeoPosition::GeoPosition(gate_geopos_t const& src)
48 {
49 1 this->latitude = src.latitude;
50 1 this->longitude = src.longitude;
51 1 this->altitude = src.altitude;
52 1 }
53 1 GeoPosition& GeoPosition::operator=(GeoPosition const& src)
54 {
55 1 this->latitude = src.latitude;
56 1 this->longitude = src.longitude;
57 1 this->altitude = src.altitude;
58 1 return *this;
59 }
60 12 GeoPosition::~GeoPosition() noexcept
61 {
62 12 }
63
64 17 gate_geopos_t const* GeoPosition::c_impl() const noexcept
65 {
66 17 return static_cast<gate_geopos_t const*>(this);
67 }
68
69 9 bool GeoPosition::operator==(gate_geopos_t const& that) const
70 {
71 9 return math::isZero(this->longitude - that.longitude)
72
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 && math::isZero(this->latitude - that.latitude)
73
4/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 1 times.
15 && math::isZero(this->altitude - that.altitude);
74 }
75 8 bool GeoPosition::operator==(GeoPosition const& that) const
76 {
77 8 return (*this) == *that.c_impl();
78 }
79 bool GeoPosition::operator!=(gate_geopos_t const& that) const
80 {
81 return !(*this == that);
82 }
83 4 bool GeoPosition::operator!=(GeoPosition const& that) const
84 {
85 4 return !(*this == that);
86 }
87 2 bool GeoPosition::operator< (GeoPosition const& that) const
88 {
89
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (this->longitude < that.longitude) return true;
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (this->latitude < that.latitude) return true;
91 2 return (this->altitude < that.altitude);
92 }
93 4 bool GeoPosition::operator<=(GeoPosition const& that) const
94 {
95
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (this->longitude < that.longitude) return true;
96
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (this->longitude > that.longitude) return false;
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (this->latitude < that.latitude) return true;
98
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (this->latitude > that.latitude) return false;
99 4 return (this->altitude <= that.altitude);
100 }
101 1 bool GeoPosition::operator> (GeoPosition const& that) const
102 {
103 1 return (that < *this);
104 }
105 2 bool GeoPosition::operator>=(GeoPosition const& that) const
106 {
107 2 return (that <= *this);
108 }
109 1 bool GeoPosition::operator!() const
110 {
111 1 return math::isZero(this->longitude)
112
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 && math::isZero(this->latitude)
113
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
2 && math::isZero(this->altitude);
114 }
115
116 1 real64_t GeoPosition::metersPerLatitude(real64_t latitude)
117 {
118 1 return gate_geopos_meters_per_latitude(latitude);
119 }
120 1 real64_t GeoPosition::metersPerLongitude(real64_t latitude)
121 {
122 1 return gate_geopos_meters_per_longitude(latitude);
123 }
124 3 real64_t GeoPosition::distance(GeoPosition const& pos1, GeoPosition const& pos2)
125 {
126 3 return gate_geopos_distance(pos1.c_impl(), pos2.c_impl());
127 }
128
129
130
131 } // end of namespace gate
132