gucoordinates
RelativeCoordinate.cc
Go to the documentation of this file.
1/*
2 * RelativeCoordinate.cc
3 * gucoordinates
4 *
5 * Created by Callum McColl on 20/06/2020.
6 * Copyright © 2020 Callum McColl. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials
18 * provided with the distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgement:
22 *
23 * This product includes software developed by Callum McColl.
24 *
25 * 4. Neither the name of the author nor the names of contributors
26 * may be used to endorse or promote products derived from this
27 * software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * -----------------------------------------------------------------------
42 * This program is free software; you can redistribute it and/or
43 * modify it under the above terms or under the terms of the GNU
44 * General Public License as published by the Free Software Foundation;
45 * either version 2 of the License, or (at your option) any later version.
46 *
47 * This program is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 * GNU General Public License for more details.
51 *
52 * You should have received a copy of the GNU General Public License
53 * along with this program; if not, see http://www.gnu.org/licenses/
54 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
55 * Fifth Floor, Boston, MA 02110-1301, USA.
56 *
57 */
58
60#include "conversions.h"
61
62#if __cplusplus >= 201703L
63#include <optional>
64#endif
65
67
68GU::RelativeCoordinate::RelativeCoordinate(degrees_d t_direction, millimetres_u t_distance) NOEXCEPT
69{
70 set_direction(t_direction);
71 set_distance(t_distance);
72}
73
75{
76 set_direction(other.direction());
77 set_distance(other.distance());
78}
79
81{
82 set_direction(other.direction);
83 set_distance(other.distance);
84}
85
86#if __cplusplus >= 201103L
88{
89 set_direction(other.direction());
90 set_distance(other.distance());
91}
92
94{
95 set_direction(other.direction);
96 set_distance(other.distance);
97}
98#endif
99
101
103{
104 if (&other == this)
105 {
106 return *this;
107 }
108 set_direction(other.direction());
109 set_distance(other.distance());
110 return *this;
111}
112
114{
115 if (&other == this)
116 {
117 return *this;
118 }
119 set_direction(other.direction);
120 set_distance(other.distance);
121 return *this;
122}
123
124#if __cplusplus >= 201103L
126{
127 if (&other == this) {
128 return *this;
129 }
130 set_direction(other.direction());
131 set_distance(other.distance());
132 return *this;
133}
134
136{
137 if (&other == this) {
138 return *this;
139 }
140 set_direction(other.direction);
141 set_distance(other.distance);
142 return *this;
143}
144#endif
145
146GU::CameraCoordinate GU::RelativeCoordinate::cameraCoordinate(const GU::CameraPivot &cameraPivot, const int cameraOffset, const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
147{
148 return percentCoordinate(cameraPivot, cameraOffset).cameraCoordinate(resWidth, resHeight);
149}
150
151GU::PixelCoordinate GU::RelativeCoordinate::pixelCoordinate(const GU::CameraPivot &cameraPivot, const int cameraOffset, const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
152{
153 return percentCoordinate(cameraPivot, cameraOffset).pixelCoordinate(resWidth, resHeight);
154}
155
156GU::PercentCoordinate GU::RelativeCoordinate::percentCoordinate(const GU::CameraPivot &cameraPivot, const int cameraOffset) const NOEXCEPT
157{
158 return GU::PercentCoordinate(rr_coord_to_pct_coord(*this, cameraPivot, cameraOffset));
159}
160
161GU::CameraCoordinate GU::RelativeCoordinate::clampedCameraCoordinate(const GU::CameraPivot &cameraPivot, const int cameraOffset, const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
162{
163 return clampedPercentCoordinate(cameraPivot, cameraOffset).cameraCoordinate(resWidth, resHeight);
164}
165
166GU::PixelCoordinate GU::RelativeCoordinate::clampedPixelCoordinate(const GU::CameraPivot &cameraPivot, const int cameraOffset, const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
167{
168 return clampedPercentCoordinate(cameraPivot, cameraOffset).pixelCoordinate(resWidth, resHeight);
169}
170
171GU::PercentCoordinate GU::RelativeCoordinate::clampedPercentCoordinate(const GU::CameraPivot &cameraPivot, const int cameraOffset) const NOEXCEPT
172{
173 return GU::PercentCoordinate(clamped_rr_coord_to_pct_coord(*this, cameraPivot, cameraOffset));
174}
175
177{
178 return cartesianCoordinate().relativeCoordinateTo(coord.cartesianCoordinate());
179}
180
182{
183 return rr_coord_to_cartesian_coord(*this);
184}
185
187{
188 return rr_coord_to_field_coord(*this, heading);
189}
190
191degrees_d GU::RelativeCoordinate::direction() const NOEXCEPT
192{
194}
195
196void GU::RelativeCoordinate::set_direction(const degrees_d newValue) NOEXCEPT
197{
199}
200
201millimetres_u GU::RelativeCoordinate::distance() const NOEXCEPT
202{
204}
205
206void GU::RelativeCoordinate::set_distance(const millimetres_u newValue) NOEXCEPT
207{
209}
210
212{
213 return gu_relative_coordinate_equals(*this, other, 0.00001);
214}
215
217{
218 return !(*this == other);
219}
220
222{
223 return gu_relative_coordinate_equals(*this, other, 0.00001);
224}
225
227{
228 return !(*this == other);
229}
gu_cartesian_coordinate rr_coord_to_cartesian_coord(const gu_relative_coordinate coord)
Definition: conversions.c:177
gu_percent_coordinate clamped_rr_coord_to_pct_coord(const gu_relative_coordinate coord, const gu_camera_pivot camera_pivot, const int cameraOffset)
Definition: conversions.c:157
gu_percent_coordinate rr_coord_to_pct_coord(const gu_relative_coordinate coord, const gu_camera_pivot camera_pivot, const int cameraOffset)
Definition: conversions.c:142
gu_field_coordinate rr_coord_to_field_coord(const gu_relative_coordinate coord, const degrees_t heading)
Definition: conversions.c:202
bool gu_relative_coordinate_equals(const gu_relative_coordinate lhs, const gu_relative_coordinate rhs, const double tolerance)
PixelCoordinate pixelCoordinate(const GU::CameraPivot &, const int, const pixels_u, const pixels_u) const NOEXCEPT
PercentCoordinate clampedPercentCoordinate(const GU::CameraPivot &, const int) const NOEXCEPT
void set_distance(const millimetres_u) NOEXCEPT
PixelCoordinate clampedPixelCoordinate(const GU::CameraPivot &, const int, const pixels_u, const pixels_u) const NOEXCEPT
void set_direction(const degrees_d) NOEXCEPT
millimetres_u distance() const NOEXCEPT
RelativeCoordinate relativeCoordinateTo(const RelativeCoordinate &) const NOEXCEPT
degrees_d direction() const NOEXCEPT
bool operator==(const RelativeCoordinate &other) const NOEXCEPT
CartesianCoordinate cartesianCoordinate() const NOEXCEPT
RelativeCoordinate & operator=(const RelativeCoordinate &other) NOEXCEPT
CameraCoordinate clampedCameraCoordinate(const GU::CameraPivot &, const int, const pixels_u, const pixels_u) const NOEXCEPT
CameraCoordinate cameraCoordinate(const GU::CameraPivot &, const int, const pixels_u, const pixels_u) const NOEXCEPT
bool operator!=(const RelativeCoordinate &other) const NOEXCEPT
PercentCoordinate percentCoordinate(const GU::CameraPivot &, const int) const NOEXCEPT
FieldCoordinate fieldCoordinate(const degrees_t) const NOEXCEPT
A coordinate that is relative to some other coordinate.
degrees_d direction
The heading towards the coordinate.
millimetres_u distance
The distance to the coordinate.