1 /** 2 * @file point.h 3 * 2D points. 4 * 5 * @authors Copyright © 2013 Daniel Swanson <danij@dengine.net> 6 * 7 * @par License 8 * GPL: http://www.gnu.org/licenses/gpl.html 9 * 10 * <small>This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by the 12 * Free Software Foundation; either version 2 of the License, or (at your 13 * option) any later version. This program is distributed in the hope that it 14 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 16 * Public License for more details. You should have received a copy of the GNU 17 * General Public License along with this program; if not, write to the Free 18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 19 * 02110-1301 USA</small> 20 */ 21 22 #ifndef LIBDENG_DATA_POINT_H 23 #define LIBDENG_DATA_POINT_H 24 25 #include "liblegacy.h" 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /// @addtogroup legacyMath 32 /// @{ 33 34 /** 35 * 2D point with integer values. A handy POD structure for easy manipulation of 36 * two dimensional plane points. 37 */ 38 typedef struct Point2Raw_s { 39 union { 40 struct { 41 int x; 42 int y; 43 }; 44 int xy[2]; 45 }; 46 //#ifdef __cplusplus 47 // Point2Raw_s(int x_ = 0, int y_ = 0) : x(x_), y(y_) {} 48 // Point2Raw_s(Point2Raw_s const &other) : x(other.x), y(other.y) {} 49 //#endif 50 } Point2Raw; 51 52 struct point2_s; // The Point2f instance (opaque). 53 54 /** 55 * Point2 instance. Class for manipulating 2D plane points using integer precision. 56 * Use Point2_New() or one of the other constructors to instantiate. 57 */ 58 typedef struct point2_s Point2; 59 60 DENG_PUBLIC Point2 *Point2_New(void); 61 DENG_PUBLIC Point2 *Point2_NewWithCoords(int x, int y); 62 DENG_PUBLIC Point2 *Point2_NewFromRaw(Point2Raw const *rawPoint); 63 DENG_PUBLIC void Point2_Delete(Point2 *point); 64 65 DENG_PUBLIC Point2Raw *Point2_Raw(Point2 const *point, Point2Raw *rawPoint); 66 67 DENG_PUBLIC dd_bool Point2_IsNull(Point2 const *point); 68 69 DENG_PUBLIC int Point2_X(Point2 const *point); 70 DENG_PUBLIC int Point2_Y(Point2 const *point); 71 72 DENG_PUBLIC void Point2_SetX(Point2 *point, int x); 73 DENG_PUBLIC void Point2_SetY(Point2 *point, int y); 74 75 DENG_PUBLIC int const *Point2_XY(Point2 const *point); 76 DENG_PUBLIC void Point2_SetXY(Point2 *point, int x, int y); 77 78 DENG_PUBLIC void Point2_Translate(Point2 *point, Point2Raw const *delta); 79 DENG_PUBLIC void Point2_TranslateXY(Point2 *point, int x, int y); 80 DENG_PUBLIC void Point2_TranslateX(Point2 *point, int x); 81 DENG_PUBLIC void Point2_TranslateY(Point2 *point, int y); 82 83 DENG_PUBLIC void Point2_Sum(Point2 *point, Point2 const *other); 84 85 DENG_PUBLIC dd_bool Point2_Equality(Point2 const *point, Point2 const *other); 86 87 /** 88 * 2D point with floating point values. A handy POD structure for easy 89 * manipulation of two dimensional plane points. 90 */ 91 typedef struct Point2Rawf_s { 92 union { 93 struct { 94 double x; 95 double y; 96 }; 97 double xy[2]; 98 }; 99 #ifdef __cplusplus xPoint2Rawf_s100 Point2Rawf_s(double x_ = 0, double y_ = 0) : x(x_), y(y_) {} 101 #endif 102 } Point2Rawf; 103 104 struct point2f_s; // The Point2f instance (opaque). 105 106 /** 107 * Point2f instance. Class for manipulating 2D plane points using floating-point precision. 108 * Use Point2f_New() or one of the other constructors to instantiate. 109 */ 110 typedef struct point2f_s Point2f; 111 112 DENG_PUBLIC Point2f *Point2f_New(void); 113 DENG_PUBLIC Point2f *Point2f_NewWithCoords(double x, double y); 114 DENG_PUBLIC Point2f *Point2f_NewFromRaw(Point2Rawf const *rawPoint); 115 DENG_PUBLIC void Point2f_Delete(Point2f *point); 116 117 DENG_PUBLIC Point2Rawf *Point2f_Raw(Point2f const *point, Point2Rawf *rawPoint); 118 119 DENG_PUBLIC dd_bool Point2f_IsNull(Point2f const *point); 120 121 DENG_PUBLIC double Point2f_X(Point2f const *point); 122 DENG_PUBLIC double Point2f_Y(Point2f const *point); 123 124 DENG_PUBLIC void Point2f_SetX(Point2f *point, double x); 125 DENG_PUBLIC void Point2f_SetY(Point2f *point, double y); 126 127 DENG_PUBLIC double const *Point2f_XY(Point2f const *point); 128 DENG_PUBLIC void Point2f_SetXY(Point2f *point, double x, double y); 129 130 DENG_PUBLIC void Point2f_Translate(Point2f *point, Point2Rawf const *delta); 131 DENG_PUBLIC void Point2f_TranslateXY(Point2f *point, double x, double y); 132 DENG_PUBLIC void Point2f_TranslateX(Point2f *point, double x); 133 DENG_PUBLIC void Point2f_TranslateY(Point2f *point, double y); 134 135 DENG_PUBLIC void Point2f_Sum(Point2f *point, Point2f const *other); 136 137 DENG_PUBLIC dd_bool Point2f_Equality(Point2f const *point, Point2f const *other); 138 139 /** 140 * 3D point with integer values. A handy POD structure for easy manipulation of 141 * three dimensional space points. 142 */ 143 typedef struct Point3Raw_s { 144 union { 145 struct { 146 int x; 147 int y; 148 int z; 149 }; 150 int xy[2]; 151 int xyz[3]; 152 }; 153 } Point3Raw; 154 155 struct point3_s; // The Point3f instance (opaque). 156 157 /** 158 * Point3 instance. Class for manipulating 3D plane points using integer precision. 159 * Use Point3_New() or one of the other constructors to instantiate. 160 */ 161 typedef struct point3_s Point3; 162 163 DENG_PUBLIC Point3 *Point3_New(void); 164 DENG_PUBLIC Point3 *Point3_NewWithCoords(int x, int y, int z); 165 DENG_PUBLIC Point3 *Point3_NewFromRaw(Point3Raw const *rawPoint); 166 DENG_PUBLIC void Point3_Delete(Point3 *point); 167 168 DENG_PUBLIC Point3Raw *Point3_Raw(Point3 const *point, Point3Raw *rawPoint); 169 170 DENG_PUBLIC dd_bool Point3_IsNull(Point3 const *point); 171 172 DENG_PUBLIC int Point3_X(Point3 const *point); 173 DENG_PUBLIC int Point3_Y(Point3 const *point); 174 DENG_PUBLIC int Point3_Z(Point3 const *point); 175 176 DENG_PUBLIC void Point3_SetX(Point3 *point, int x); 177 DENG_PUBLIC void Point3_SetY(Point3 *point, int y); 178 DENG_PUBLIC void Point3_SetZ(Point3 *point, int z); 179 180 DENG_PUBLIC int const *Point3_XYZ(Point3 const *point); 181 DENG_PUBLIC void Point3_SetXYZ(Point3 *point, int x, int y, int z); 182 183 DENG_PUBLIC void Point3_Translate(Point3 *point, int x, int y, int z); 184 DENG_PUBLIC void Point3_TranslateX(Point3 *point, int x); 185 DENG_PUBLIC void Point3_TranslateY(Point3 *point, int y); 186 DENG_PUBLIC void Point3_TranslateZ(Point3 *point, int z); 187 188 DENG_PUBLIC void Point3_Sum(Point3 *point, Point3 const *other); 189 190 DENG_PUBLIC dd_bool Point3_Equality(Point3 const *point, Point3 const *other); 191 192 /** 193 * 3D point with floating point values. A handy POD structure for easy 194 * manipulation of three dimensional space points. 195 */ 196 typedef struct Point3Rawf_s { 197 union { 198 struct { 199 double x; 200 double y; 201 double z; 202 }; 203 double xy[2]; 204 double xyz[3]; 205 }; 206 } Point3Rawf; 207 208 struct point3f_s; // The Point3f instance (opaque). 209 210 /** 211 * Point3f instance. Class for manipulating 3D plane points using floating-point precision. 212 * Use Point3f_New() or one of the other constructors to instantiate. 213 */ 214 typedef struct point3f_s Point3f; 215 216 DENG_PUBLIC Point3f *Point3f_New(void); 217 DENG_PUBLIC Point3f *Point3f_NewWithCoords(double x, double y, double z); 218 DENG_PUBLIC Point3f *Point3f_NewFromRaw(Point3Rawf const *rawPoint); 219 DENG_PUBLIC void Point3f_Delete(Point3f *point); 220 221 DENG_PUBLIC Point3Rawf *Point3f_Raw(Point3f const *point, Point3Rawf *rawPoint); 222 223 DENG_PUBLIC dd_bool Point3f_IsNull(Point3f const *point); 224 225 DENG_PUBLIC double Point3f_X(Point3f const *point); 226 DENG_PUBLIC double Point3f_Y(Point3f const *point); 227 DENG_PUBLIC double Point3f_Z(Point3f const *point); 228 229 DENG_PUBLIC void Point3f_SetX(Point3f *point, double x); 230 DENG_PUBLIC void Point3f_SetY(Point3f *point, double y); 231 DENG_PUBLIC void Point3f_SetZ(Point3f *point, double z); 232 233 DENG_PUBLIC double const *Point3f_XYZ(Point3f const *point); 234 DENG_PUBLIC void Point3f_SetXYZ(Point3f *point, double x, double y, double z); 235 236 DENG_PUBLIC void Point3f_Translate(Point3f *point, double x, double y, double z); 237 DENG_PUBLIC void Point3f_TranslateX(Point3f *point, double x); 238 DENG_PUBLIC void Point3f_TranslateY(Point3f *point, double y); 239 DENG_PUBLIC void Point3f_TranslateZ(Point3f *point, double z); 240 241 DENG_PUBLIC void Point3f_Sum(Point3f *point, Point3f const *other); 242 243 DENG_PUBLIC dd_bool Point3f_Equality(Point3f const *point, Point3f const *other); 244 245 /// @} 246 247 #ifdef __cplusplus 248 } // extern "C" 249 #endif 250 251 #endif /* LIBDENG_DATA_POINT_H */ 252