gucoordinates
FieldCoordinate.cc
Go to the documentation of this file.
1/*
2 * FieldCoordinate.cc
3 * gucoordinates
4 *
5 * Created by Callum McColl on 21/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
59#include "FieldCoordinate.hpp"
60#include "conversions.h"
61
62#if __cplusplus >= 201703L
63#include <optional>
64#endif
65
67
68GU::FieldCoordinate::FieldCoordinate(GU::CartesianCoordinate t_position, degrees_t t_heading) NOEXCEPT
69{
70 set_position(t_position);
71 set_heading(t_heading);
72}
73
75{
76 set_position(other.position());
77 set_heading(other.heading());
78}
79
81{
82 set_position(other.position);
83 set_heading(other.heading);
84}
85
86#if __cplusplus >= 201103L
88{
89 set_position(other.position());
90 set_heading(other.heading());
91}
92
94{
95 set_position(other.position);
96 set_heading(other.heading);
97}
98#endif
99
101
103{
104 if (&other == this)
105 {
106 return *this;
107 }
108 set_position(other.position());
109 set_heading(other.heading());
110 return *this;
111}
112
114{
115 if (&other == this)
116 {
117 return *this;
118 }
119 set_position(other.position);
120 set_heading(other.heading);
121 return *this;
122}
123
124#if __cplusplus >= 201103L
126{
127 if (&other == this) {
128 return *this;
129 }
130 set_position(other.position());
131 set_heading(other.heading());
132 return *this;
133}
134
136{
137 if (&other == this) {
138 return *this;
139 }
140 set_position(other.position);
141 set_heading(other.heading);
142 return *this;
143}
144#endif
145
146GU::CartesianCoordinate GU::FieldCoordinate::cartesianCoordinateAt(const GU::CameraCoordinate &target, const GU::CameraPivot &cameraPivot, const int cameraOffset) const NOEXCEPT
147{
148 return cartesianCoordinateAt(target.relativeCoordinate(cameraPivot, cameraOffset));
149}
150
151GU::CartesianCoordinate GU::FieldCoordinate::cartesianCoordinateAt(const GU::PixelCoordinate &target, const GU::CameraPivot &cameraPivot, const int cameraOffset) const NOEXCEPT
152{
153 return cartesianCoordinateAt(target.relativeCoordinate(cameraPivot, cameraOffset));
154}
155
156GU::CartesianCoordinate GU::FieldCoordinate::cartesianCoordinateAt(const GU::PercentCoordinate &target, const GU::CameraPivot &cameraPivot, const int cameraOffset) const NOEXCEPT
157{
158 return cartesianCoordinateAt(target.relativeCoordinate(cameraPivot, cameraOffset));
159}
160
161GU::FieldCoordinate GU::FieldCoordinate::fieldCoordinateAt(const GU::CameraCoordinate &target, const GU::CameraPivot &cameraPivot, const int cameraOffset, const degrees_t targetHeading) const NOEXCEPT
162{
163 return fieldCoordinateAt(target.relativeCoordinate(cameraPivot, cameraOffset), targetHeading);
164}
165
166GU::FieldCoordinate GU::FieldCoordinate::fieldCoordinateAt(const GU::PixelCoordinate &target, const GU::CameraPivot &cameraPivot, const int cameraOffset, const degrees_t targetHeading) const NOEXCEPT
167{
168 return fieldCoordinateAt(target.relativeCoordinate(cameraPivot, cameraOffset), targetHeading);
169}
170
171GU::FieldCoordinate GU::FieldCoordinate::fieldCoordinateAt(const GU::PercentCoordinate &target, const GU::CameraPivot &cameraPivot, const int cameraOffset, const degrees_t targetHeading) const NOEXCEPT
172{
173 return fieldCoordinateAt(target.relativeCoordinate(cameraPivot, cameraOffset), targetHeading);
174}
175
177{
178 return rr_coord_to_cartesian_coord_from_field(target, *this);
179}
180
181GU::FieldCoordinate GU::FieldCoordinate::fieldCoordinateAt(const GU::RelativeCoordinate & target, const degrees_t targetHeading) const NOEXCEPT
182{
183 return rr_coord_to_field_coord_from_source(target, *this, targetHeading);
184}
185
187{
188 return field_coord_to_rr_coord_to_target(*this, target);
189}
190
192{
193 return relativeCoordinateTo(target.position());
194}
195
196GU::CameraCoordinate GU::FieldCoordinate::cameraCoordinateTo(const GU::CartesianCoordinate & target, const GU::CameraPivot & cameraPivot, const int cameraOffset, const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
197{
198 return relativeCoordinateTo(target).cameraCoordinate(cameraPivot, cameraOffset, resWidth, resHeight);
199}
200
201GU::CameraCoordinate GU::FieldCoordinate::cameraCoordinateTo(const GU::FieldCoordinate & target, const GU::CameraPivot & cameraPivot, const int cameraOffset, const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
202{
203 return relativeCoordinateTo(target).cameraCoordinate(cameraPivot, cameraOffset, resWidth, resHeight);
204}
205
206GU::PixelCoordinate GU::FieldCoordinate::pixelCoordinateTo(const GU::CartesianCoordinate & target, const GU::CameraPivot & cameraPivot, const int cameraOffset, const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
207{
208 return relativeCoordinateTo(target).pixelCoordinate(cameraPivot, cameraOffset, resWidth, resHeight);
209}
210
211GU::PixelCoordinate GU::FieldCoordinate::pixelCoordinateTo(const GU::FieldCoordinate & target, const GU::CameraPivot & cameraPivot, const int cameraOffset, const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
212{
213 return relativeCoordinateTo(target).pixelCoordinate(cameraPivot, cameraOffset, resWidth, resHeight);
214}
215
216GU::PercentCoordinate GU::FieldCoordinate::percentCoordinateTo(const GU::CartesianCoordinate & target, const GU::CameraPivot & cameraPivot, const int cameraOffset) const NOEXCEPT
217{
218 return relativeCoordinateTo(target).percentCoordinate(cameraPivot, cameraOffset);
219}
220
221GU::PercentCoordinate GU::FieldCoordinate::percentCoordinateTo(const GU::FieldCoordinate & target, const GU::CameraPivot & cameraPivot, const int cameraOffset) const NOEXCEPT
222{
223 return relativeCoordinateTo(target).percentCoordinate(cameraPivot, cameraOffset);
224}
225
226GU::CameraCoordinate GU::FieldCoordinate::clampedCameraCoordinateTo(const GU::CartesianCoordinate & target, const GU::CameraPivot & cameraPivot, const int cameraOffset, const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
227{
228 return relativeCoordinateTo(target).clampedCameraCoordinate(cameraPivot, cameraOffset, resWidth, resHeight);
229}
230
231GU::CameraCoordinate GU::FieldCoordinate::clampedCameraCoordinateTo(const GU::FieldCoordinate & target, const GU::CameraPivot & cameraPivot, const int cameraOffset, const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
232{
233 return relativeCoordinateTo(target).clampedCameraCoordinate(cameraPivot, cameraOffset, resWidth, resHeight);
234}
235
236GU::PixelCoordinate GU::FieldCoordinate::clampedPixelCoordinateTo(const GU::CartesianCoordinate & target, const GU::CameraPivot & cameraPivot, const int cameraOffset, const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
237{
238 return relativeCoordinateTo(target).clampedPixelCoordinate(cameraPivot, cameraOffset, resWidth, resHeight);
239}
240
241GU::PixelCoordinate GU::FieldCoordinate::clampedPixelCoordinateTo(const GU::FieldCoordinate & target, const GU::CameraPivot & cameraPivot, const int cameraOffset, const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
242{
243 return relativeCoordinateTo(target).clampedPixelCoordinate(cameraPivot, cameraOffset, resWidth, resHeight);
244}
245
246GU::PercentCoordinate GU::FieldCoordinate::clampedPercentCoordinateTo(const GU::CartesianCoordinate & target, const GU::CameraPivot & cameraPivot, const int cameraOffset) const NOEXCEPT
247{
248 return relativeCoordinateTo(target).clampedPercentCoordinate(cameraPivot, cameraOffset);
249}
250
251GU::PercentCoordinate GU::FieldCoordinate::clampedPercentCoordinateTo(const GU::FieldCoordinate & target, const GU::CameraPivot & cameraPivot, const int cameraOffset) const NOEXCEPT
252{
253 return relativeCoordinateTo(target).clampedPercentCoordinate(cameraPivot, cameraOffset);
254}
255
257{
259}
260
262{
264}
265
266degrees_t GU::FieldCoordinate::heading() const NOEXCEPT
267{
269}
270
271void GU::FieldCoordinate::set_heading(const degrees_t newValue) NOEXCEPT
272{
274}
275
276bool GU::FieldCoordinate::operator==(const FieldCoordinate &other) const NOEXCEPT
277{
278 return gu_field_coordinate_equals(*this, other);
279}
280
281bool GU::FieldCoordinate::operator!=(const FieldCoordinate &other) const NOEXCEPT
282{
283 return !(*this == other);
284}
285
287{
288 return gu_field_coordinate_equals(*this, other);
289}
290
292{
293 return !(*this == other);
294}
gu_field_coordinate rr_coord_to_field_coord_from_source(const gu_relative_coordinate coord, const gu_field_coordinate source, const degrees_t heading)
Definition: conversions.c:211
gu_cartesian_coordinate rr_coord_to_cartesian_coord_from_field(const gu_relative_coordinate coord, const gu_field_coordinate source)
Definition: conversions.c:196
gu_relative_coordinate field_coord_to_rr_coord_to_target(const gu_field_coordinate source, const gu_cartesian_coordinate target)
Definition: conversions.c:237
bool gu_field_coordinate_equals(const gu_field_coordinate lhs, const gu_field_coordinate rhs)
degrees_t heading() const NOEXCEPT
PixelCoordinate clampedPixelCoordinateTo(const GU::CartesianCoordinate &, const GU::CameraPivot &, const int, const pixels_u, const pixels_u) const NOEXCEPT
FieldCoordinate & operator=(const FieldCoordinate &other) NOEXCEPT
void set_heading(const degrees_t) NOEXCEPT
PercentCoordinate clampedPercentCoordinateTo(const GU::CartesianCoordinate &, const GU::CameraPivot &, const int) const NOEXCEPT
FieldCoordinate() NOEXCEPT
void set_position(const CartesianCoordinate) NOEXCEPT
PercentCoordinate percentCoordinateTo(const GU::CartesianCoordinate &, const GU::CameraPivot &, const int) const NOEXCEPT
CameraCoordinate cameraCoordinateTo(const GU::CartesianCoordinate &, const GU::CameraPivot &, const int, const pixels_u, const pixels_u) const NOEXCEPT
PixelCoordinate pixelCoordinateTo(const GU::CartesianCoordinate &, const GU::CameraPivot &, const int, const pixels_u, const pixels_u) const NOEXCEPT
CartesianCoordinate cartesianCoordinateAt(const GU::RelativeCoordinate &) const NOEXCEPT
CameraCoordinate clampedCameraCoordinateTo(const GU::CartesianCoordinate &, const GU::CameraPivot &, const int, const pixels_u, const pixels_u) const NOEXCEPT
RelativeCoordinate relativeCoordinateTo(const GU::CartesianCoordinate &) const NOEXCEPT
bool operator!=(const FieldCoordinate &other) const NOEXCEPT
bool operator==(const FieldCoordinate &other) const NOEXCEPT
CartesianCoordinate position() const NOEXCEPT
FieldCoordinate fieldCoordinateAt(const GU::RelativeCoordinate &, const degrees_t) const NOEXCEPT
A field_coordinate is a coordinate for an object that faces a certain direction (such as a robot) on ...
degrees_t heading
The direction where the object is facing.
gu_cartesian_coordinate position
The position of the object on the field.