---------------------------------------------------------------------* * Box creation, destruction and copy * *---------------------------------------------------------------------*/ ! * \brief boxCreate() * * \param[in] x, y, w, h * \return box, or NULL on error * * * Notes: * (1) This clips the box to the +quad. If no part of the *
| 162 | * </pre> |
| 163 | */ |
| 164 | BOX * |
| 165 | boxCreate(l_int32 x, |
| 166 | l_int32 y, |
| 167 | l_int32 w, |
| 168 | l_int32 h) |
| 169 | { |
| 170 | BOX *box; |
| 171 | |
| 172 | PROCNAME("boxCreate"); |
| 173 | |
| 174 | if (w < 0 || h < 0) |
| 175 | return (BOX *)ERROR_PTR("w and h not both >= 0", procName, NULL); |
| 176 | if (x < 0) { /* take part in +quad */ |
| 177 | w = w + x; |
| 178 | x = 0; |
| 179 | if (w <= 0) |
| 180 | return (BOX *)ERROR_PTR("x < 0 and box off +quad", procName, NULL); |
| 181 | } |
| 182 | if (y < 0) { /* take part in +quad */ |
| 183 | h = h + y; |
| 184 | y = 0; |
| 185 | if (h <= 0) |
| 186 | return (BOX *)ERROR_PTR("y < 0 and box off +quad", procName, NULL); |
| 187 | } |
| 188 | |
| 189 | if ((box = (BOX *)LEPT_CALLOC(1, sizeof(BOX))) == NULL) |
| 190 | return (BOX *)ERROR_PTR("box not made", procName, NULL); |
| 191 | boxSetGeometry(box, x, y, w, h); |
| 192 | box->refcount = 1; |
| 193 | |
| 194 | return box; |
| 195 | } |
| 196 | |
| 197 | |
| 198 | /*! |
no test coverage detected