gucoordinates
PixelCoordinate.cc
Go to the documentation of this file.
1/*
2 * PixelCoordinate.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 "PixelCoordinate.hpp"
60#include "conversions.h"
61
62#if __cplusplus >= 201703L
63#include <optional>
64#endif
65
67
68GU::PixelCoordinate::PixelCoordinate(pixels_t t_x, pixels_t t_y, pixels_u t_resWidth, pixels_u t_resHeight) NOEXCEPT
69{
70 set_x(t_x);
71 set_y(t_y);
72 set_resWidth(t_resWidth);
73 set_resHeight(t_resHeight);
74}
75
77{
78 set_x(other.x());
79 set_y(other.y());
80 set_resWidth(other.resWidth());
81 set_resHeight(other.resHeight());
82}
83
85{
86 set_x(other.x);
87 set_y(other.y);
88 set_resWidth(other.res_width);
89 set_resHeight(other.res_height);
90}
91
92#if __cplusplus >= 201103L
94{
95 set_x(other.x());
96 set_y(other.y());
97 set_resWidth(other.resWidth());
98 set_resHeight(other.resHeight());
99}
100
102{
103 set_x(other.x);
104 set_y(other.y);
105 set_resWidth(other.res_width);
106 set_resHeight(other.res_height);
107}
108#endif
109
111
113{
114 if (&other == this)
115 {
116 return *this;
117 }
118 set_x(other.x());
119 set_y(other.y());
120 set_resWidth(other.resWidth());
121 set_resHeight(other.resHeight());
122 return *this;
123}
124
126{
127 if (&other == this)
128 {
129 return *this;
130 }
131 set_x(other.x);
132 set_y(other.y);
133 set_resWidth(other.res_width);
134 set_resHeight(other.res_height);
135 return *this;
136}
137
138#if __cplusplus >= 201103L
140{
141 if (&other == this) {
142 return *this;
143 }
144 set_x(other.x());
145 set_y(other.y());
146 set_resWidth(other.resWidth());
147 set_resHeight(other.resHeight());
148 return *this;
149}
150
152{
153 if (&other == this) {
154 return *this;
155 }
156 set_x(other.x);
157 set_y(other.y);
158 set_resWidth(other.res_width);
159 set_resHeight(other.res_height);
160 return *this;
161}
162#endif
163
165{
166 return px_coord_to_cam_coord(*this);
167}
168
170{
171 return px_coord_to_pct_coord(*this);
172}
173
174GU::RelativeCoordinate GU::PixelCoordinate::relativeCoordinate(const GU::CameraPivot & cameraPivot, const int cameraOffset) const NOEXCEPT
175{
176 return percentCoordinate().relativeCoordinate(cameraPivot, cameraOffset);
177}
178
179pixels_t GU::PixelCoordinate::x() const NOEXCEPT
180{
182}
183
184void GU::PixelCoordinate::set_x(const pixels_t newValue) NOEXCEPT
185{
186 gu_pixel_coordinate::x = newValue;
187}
188
189pixels_t GU::PixelCoordinate::y() const NOEXCEPT
190{
192}
193
194void GU::PixelCoordinate::set_y(const pixels_t newValue) NOEXCEPT
195{
196 gu_pixel_coordinate::y = newValue;
197}
198
199pixels_u GU::PixelCoordinate::resWidth() const NOEXCEPT
200{
202}
203
204void GU::PixelCoordinate::set_resWidth(const pixels_u newValue) NOEXCEPT
205{
207}
208
209pixels_u GU::PixelCoordinate::resHeight() const NOEXCEPT
210{
212}
213
214void GU::PixelCoordinate::set_resHeight(const pixels_u newValue) NOEXCEPT
215{
217}
218
219pixels_t GU::PixelCoordinate::xLowerBound() const NOEXCEPT
220{
222}
223
224pixels_t GU::PixelCoordinate::xUpperBound() const NOEXCEPT
225{
227}
228
229pixels_t GU::PixelCoordinate::yLowerBound() const NOEXCEPT
230{
232}
233
234pixels_t GU::PixelCoordinate::yUpperBound() const NOEXCEPT
235{
237}
238
239bool GU::PixelCoordinate::operator==(const PixelCoordinate &other) const NOEXCEPT
240{
241 return gu_pixel_coordinate_equals(*this, other);
242}
243
244bool GU::PixelCoordinate::operator!=(const PixelCoordinate &other) const NOEXCEPT
245{
246 return !(*this == other);
247}
248
250{
251 return gu_pixel_coordinate_equals(*this, other);
252}
253
255{
256 return !(*this == other);
257}
gu_percent_coordinate px_coord_to_pct_coord(const gu_pixel_coordinate coord)
Definition: conversions.c:95
gu_camera_coordinate px_coord_to_cam_coord(const gu_pixel_coordinate coord)
Definition: conversions.c:85
pixels_t gu_pixel_coordinate_y_lower_bound(const gu_pixel_coordinate coord)
pixels_t gu_pixel_coordinate_y_upper_bound(const gu_pixel_coordinate coord)
pixels_t gu_pixel_coordinate_x_lower_bound(const gu_pixel_coordinate coord)
bool gu_pixel_coordinate_equals(const gu_pixel_coordinate lhs, const gu_pixel_coordinate rhs)
pixels_t gu_pixel_coordinate_x_upper_bound(const gu_pixel_coordinate coord)
bool operator==(const PixelCoordinate &other) const NOEXCEPT
RelativeCoordinate relativeCoordinate(const GU::CameraPivot &, const int) const NOEXCEPT
void set_y(const pixels_t) NOEXCEPT
pixels_t yUpperBound() const NOEXCEPT
pixels_t xLowerBound() const NOEXCEPT
PercentCoordinate percentCoordinate() const NOEXCEPT
pixels_t y() const NOEXCEPT
pixels_t x() const NOEXCEPT
PixelCoordinate() NOEXCEPT
void set_x(const pixels_t) NOEXCEPT
pixels_t yLowerBound() const NOEXCEPT
pixels_u resWidth() const NOEXCEPT
pixels_t xUpperBound() const NOEXCEPT
pixels_u resHeight() const NOEXCEPT
void set_resHeight(const pixels_u) NOEXCEPT
bool operator!=(const PixelCoordinate &other) const NOEXCEPT
void set_resWidth(const pixels_u) NOEXCEPT
CameraCoordinate cameraCoordinate() const NOEXCEPT
PixelCoordinate & operator=(const PixelCoordinate &other) NOEXCEPT
A gu_pixel_coordinate represents the coordinate of a pixel within an image.
pixels_u res_height
The height of the resolution of the image.
pixels_t x
The x coordinate of the pixel within the image.
pixels_u res_width
The width of the resolution of the image.
pixels_t y
The y coordinate of the pixel within the image.