1 /** 2 * @file rect.h 3 * Rectangles. 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_RECT_H 23 #define LIBDENG_DATA_RECT_H 24 25 #include "point.h" 26 #include "size.h" 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 /// @addtogroup legacyMath 33 /// @{ 34 35 /** 36 * Integer rectangle. Intended as a handy POD structure for manipulation 37 * of rectangles using integer precison. 38 */ 39 typedef struct RectRaw_s { 40 Point2Raw origin; 41 Size2Raw size; 42 } RectRaw; 43 44 /** 45 * Rect instance. 46 */ 47 struct rect_s; // The Rect instance (opaque). 48 typedef struct rect_s Rect; 49 50 DENG_PUBLIC Rect *Rect_New(void); 51 DENG_PUBLIC Rect *Rect_NewWithOriginSize(Point2 const *origin, Size2 const *size); 52 DENG_PUBLIC Rect *Rect_NewWithOriginSize2(int x, int y, int width, int height); 53 DENG_PUBLIC Rect *Rect_NewFromRaw(RectRaw const *rawRect); 54 55 DENG_PUBLIC void Rect_Delete(Rect *rect); 56 57 DENG_PUBLIC void Rect_Copy(Rect *rect, Rect const *other); 58 DENG_PUBLIC Rect *Rect_CopyRaw(Rect *rect, RectRaw const *rawRect); 59 60 DENG_PUBLIC RectRaw *Rect_Raw(Rect const *rect, RectRaw *rawRect); 61 62 DENG_PUBLIC dd_bool Rect_IsNull(Rect const *rect); 63 64 DENG_PUBLIC Point2 const *Rect_Origin(Rect const *rect); 65 DENG_PUBLIC int Rect_X(Rect const *rect); 66 DENG_PUBLIC int Rect_Y(Rect const *rect); 67 68 DENG_PUBLIC void Rect_SetOrigin(Rect *rect, Point2 const *origin); 69 DENG_PUBLIC void Rect_SetX(Rect *rect, int x); 70 DENG_PUBLIC void Rect_SetY(Rect *rect, int y); 71 DENG_PUBLIC void Rect_SetXY(Rect *rect, int x, int y); 72 73 DENG_PUBLIC void Rect_Translate(Rect *r, Point2Raw const *delta); 74 DENG_PUBLIC void Rect_TranslateX(Rect *rect, int x); 75 DENG_PUBLIC void Rect_TranslateY(Rect *rect, int y); 76 DENG_PUBLIC void Rect_TranslateXY(Rect *rect, int x, int y); 77 78 DENG_PUBLIC Size2 const *Rect_Size(Rect const *rect); 79 DENG_PUBLIC int Rect_Width(Rect const *rect); 80 DENG_PUBLIC int Rect_Height(Rect const *rect); 81 82 DENG_PUBLIC void Rect_SetSize(Rect *rect, Size2 const *size); 83 DENG_PUBLIC void Rect_SetWidth(Rect *rect, int width); 84 DENG_PUBLIC void Rect_SetHeight(Rect *rect, int height); 85 86 DENG_PUBLIC void Rect_SetWidthHeight(Rect *rect, int width, int height); 87 88 DENG_PUBLIC Point2Raw *Rect_TopLeft(Rect const *rect, Point2Raw *point); 89 DENG_PUBLIC Point2Raw *Rect_TopRight(Rect const *rect, Point2Raw *point); 90 DENG_PUBLIC Point2Raw *Rect_BottomLeft(Rect const *rect, Point2Raw *point); 91 DENG_PUBLIC Point2Raw *Rect_BottomRight(Rect const *rect, Point2Raw *point); 92 93 DENG_PUBLIC Rect *Rect_Normalize(Rect *rect); 94 DENG_PUBLIC Rect *Rect_Unite(Rect *rect, Rect const *other); 95 DENG_PUBLIC Rect *Rect_UniteRaw(Rect *rect, RectRaw const *other); 96 97 DENG_PUBLIC dd_bool Rect_Equality(Rect const *rect, Rect const *other); 98 99 /** 100 * Static non-members. 101 */ 102 DENG_PUBLIC RectRaw *Rect_Normalized(Rect const *rect, RectRaw *normalized); 103 DENG_PUBLIC RectRaw *Rect_United(Rect const *rect, Rect const *other, RectRaw *united); 104 105 /** 106 * Floating-point rectangle. Intended as a handy POD structure for 107 * manipulation of rectangles using floating point precison. 108 */ 109 typedef struct RectRawf_s { 110 Point2Rawf origin; 111 Size2Rawf size; 112 } RectRawf; 113 114 /** 115 * Rectf instance. 116 */ 117 struct rectf_s; // The Rectf instance (opaque). 118 typedef struct rectf_s Rectf; 119 120 DENG_PUBLIC Rectf *Rectf_New(void); 121 DENG_PUBLIC Rectf *Rectf_NewWithOriginSize(Point2f const *origin, Size2f const *size); 122 DENG_PUBLIC Rectf *Rectf_NewFromRaw(RectRawf const *rawRect); 123 124 DENG_PUBLIC void Rectf_Delete(Rectf *rect); 125 126 DENG_PUBLIC void Rectf_Copy(Rectf *rect, Rectf const *other); 127 DENG_PUBLIC Rectf *Rectf_CopyRaw(Rectf *r, RectRawf const *rawRect); 128 129 DENG_PUBLIC RectRawf *Rectf_Raw(Rectf const *rect, RectRawf *rawRect); 130 131 DENG_PUBLIC dd_bool Rectf_IsNull(Rectf const *rect); 132 133 DENG_PUBLIC Point2f const *Rectf_Origin(Rectf const *rect); 134 DENG_PUBLIC double Rectf_X(Rectf const *rect); 135 DENG_PUBLIC double Rectf_Y(Rectf const *rect); 136 137 DENG_PUBLIC void Rectf_SetOrigin(Rectf *rect, Point2f const *origin); 138 DENG_PUBLIC void Rectf_SetX(Rectf *rect, double x); 139 DENG_PUBLIC void Rectf_SetY(Rectf *rect, double y); 140 DENG_PUBLIC void Rectf_SetXY(Rectf *rect, double x, double y); 141 142 DENG_PUBLIC void Rectf_TranslateX(Rectf *rect, double x); 143 DENG_PUBLIC void Rectf_TranslateY(Rectf *rect, double y); 144 DENG_PUBLIC void Rectf_TranslateXY(Rectf *rect, double x, double y); 145 146 DENG_PUBLIC Size2f const *Rectf_Size(Rectf const *rect); 147 DENG_PUBLIC double Rectf_Width(Rectf const *rect); 148 DENG_PUBLIC double Rectf_Height(Rectf const *rect); 149 150 DENG_PUBLIC void Rectf_SetSize(Rectf *rect, Size2f const *size); 151 DENG_PUBLIC void Rectf_SetWidth(Rectf *rect, double width); 152 DENG_PUBLIC void Rectf_SetHeight(Rectf *rect, double height); 153 154 DENG_PUBLIC void Rectf_SetWidthHeight(Rectf *rect, double width, double height); 155 156 DENG_PUBLIC Point2Rawf *Rectf_TopLeft(Rectf const *rect, Point2Rawf *point); 157 DENG_PUBLIC Point2Rawf *Rectf_TopRight(Rectf const *rect, Point2Rawf *point); 158 DENG_PUBLIC Point2Rawf *Rectf_BottomLeft(Rectf const *rect, Point2Rawf *point); 159 DENG_PUBLIC Point2Rawf *Rectf_BottomRight(Rectf const *rect, Point2Rawf *point); 160 161 DENG_PUBLIC Rectf *Rectf_Normalize(Rectf *rect); 162 DENG_PUBLIC Rectf *Rectf_Unite(Rectf *rect, Rectf const *other); 163 DENG_PUBLIC Rectf *Rectf_UniteRaw(Rectf *rect, RectRawf const *other); 164 165 DENG_PUBLIC dd_bool Rectf_Equality(Rectf const *rect, Rectf const *other); 166 167 /** 168 * Static non-members: 169 */ 170 DENG_PUBLIC RectRawf *Rectf_Normalized(Rectf const *rect, RectRawf *normalized); 171 DENG_PUBLIC RectRawf *Rectf_United(Rectf const *rect, Rectf const *other, RectRawf *united); 172 173 /// @} 174 175 #ifdef __cplusplus 176 } // extern "C" 177 #endif 178 179 #endif /* LIBDENG_DATA_RECT_H */ 180