gucoordinates
PercentCoordinate.cc
Go to the documentation of this file.
1/*
2 * PercentCoordinate.cc
3 * guvision_utils
4 *
5 * Created by Callum McColl on 19/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 "PercentCoordinate.hpp"
60#include "conversions.h"
61
62#if __cplusplus >= 201703L
63#include <optional>
64#endif
65
67
68GU::PercentCoordinate::PercentCoordinate(percent_d t_x, percent_d t_y) NOEXCEPT
69{
70 set_x(t_x);
71 set_y(t_y);
72}
73
75{
76 set_x(other.x());
77 set_y(other.y());
78}
79
81{
82 set_x(other.x);
83 set_y(other.y);
84}
85
86#if __cplusplus >= 201103L
88{
89 set_x(other.x());
90 set_y(other.y());
91}
92
94{
95 set_x(other.x);
96 set_y(other.y);
97}
98#endif
99
101
103{
104 if (&other == this)
105 {
106 return *this;
107 }
108 set_x(other.x());
109 set_y(other.y());
110 return *this;
111}
112
114{
115 if (&other == this)
116 {
117 return *this;
118 }
119 set_x(other.x);
120 set_y(other.y);
121 return *this;
122}
123
124#if __cplusplus >= 201103L
126{
127 if (&other == this) {
128 return *this;
129 }
130 set_x(other.x());
131 set_y(other.y());
132 return *this;
133}
134
136{
137 if (&other == this) {
138 return *this;
139 }
140 set_x(other.x);
141 set_y(other.y);
142 return *this;
143}
144#endif
145
146GU::PixelCoordinate GU::PercentCoordinate::pixelCoordinate(const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
147{
148 return pct_coord_to_px_coord(*this, resWidth, resHeight);
149}
150
151GU::CameraCoordinate GU::PercentCoordinate::cameraCoordinate(const pixels_u resWidth, const pixels_u resHeight) const NOEXCEPT
152{
153 return pixelCoordinate(resWidth, resHeight).cameraCoordinate();
154}
155
156GU::RelativeCoordinate GU::PercentCoordinate::relativeCoordinate(const GU::CameraPivot & cameraPivot, const int cameraOffset) const NOEXCEPT
157{
158 return pct_coord_to_rr_coord(*this, cameraPivot, cameraOffset);
159}
160
161percent_d GU::PercentCoordinate::x() const NOEXCEPT
162{
164}
165
166void GU::PercentCoordinate::set_x(const percent_d newValue) NOEXCEPT
167{
168 gu_percent_coordinate::x = newValue;
169}
170
171percent_d GU::PercentCoordinate::y() const NOEXCEPT
172{
174}
175
176void GU::PercentCoordinate::set_y(const percent_d newValue) NOEXCEPT
177{
178 gu_percent_coordinate::y = newValue;
179}
180
181percent_d GU::PercentCoordinate::xLowerBound() const NOEXCEPT
182{
184}
185
186percent_d GU::PercentCoordinate::xUpperBound() const NOEXCEPT
187{
189}
190
191percent_d GU::PercentCoordinate::yLowerBound() const NOEXCEPT
192{
194}
195
196percent_d GU::PercentCoordinate::yUpperBound() const NOEXCEPT
197{
199}
200
202{
203 return gu_percent_coordinate_equals(*this, other, 0.0001);
204}
205
207{
208 return !(*this == other);
209}
210
212{
213 return gu_percent_coordinate_equals(*this, other, 0.0001);
214}
215
217{
218 return !(*this == other);
219}
gu_pixel_coordinate pct_coord_to_px_coord(const gu_percent_coordinate coord, const pixels_u res_width, const pixels_u res_height)
Definition: conversions.c:105
gu_relative_coordinate pct_coord_to_rr_coord(const gu_percent_coordinate coord, const gu_camera_pivot camera_pivot, const int cameraOffset)
Definition: conversions.c:115
percent_d gu_percent_coordinate_x_upper_bound(const gu_percent_coordinate coord)
percent_d gu_percent_coordinate_y_upper_bound(const gu_percent_coordinate coord)
percent_d gu_percent_coordinate_y_lower_bound(const gu_percent_coordinate coord)
bool gu_percent_coordinate_equals(const gu_percent_coordinate lhs, const gu_percent_coordinate rhs, const percent_d tolerance)
percent_d gu_percent_coordinate_x_lower_bound(const gu_percent_coordinate coord)
bool operator!=(const PercentCoordinate &other) const NOEXCEPT
bool operator==(const PercentCoordinate &other) const NOEXCEPT
percent_d y() const NOEXCEPT
void set_y(const percent_d) NOEXCEPT
void set_x(const percent_d) NOEXCEPT
percent_d x() const NOEXCEPT
percent_d xUpperBound() const NOEXCEPT
PercentCoordinate & operator=(const PercentCoordinate &other) NOEXCEPT
percent_d xLowerBound() const NOEXCEPT
CameraCoordinate cameraCoordinate(const pixels_u, const pixels_u) const NOEXCEPT
RelativeCoordinate relativeCoordinate(const GU::CameraPivot &, const int) const NOEXCEPT
percent_d yLowerBound() const NOEXCEPT
PixelCoordinate pixelCoordinate(const pixels_u, const pixels_u) const NOEXCEPT
percent_d yUpperBound() const NOEXCEPT
A gu_percent_coordinate represents the coordinate of a pixel within an image.
percent_d y
The y coordinate of the pixel within the image as a percentage.
percent_d x
The x coordinate of the pixel within the image as a percentage.