! * \brief ptaConvertToBox() * * \param[in] pta * \return box minimum containing all points in the pta, or NULL on error * * * Notes: * (1) For 2 corners, the order of the 2 points is UL, LR. * For 4 corners, the order of points is UL, UR, LL, LR. * */
| 902 | * </pre> |
| 903 | */ |
| 904 | BOX * |
| 905 | ptaConvertToBox(PTA *pta) |
| 906 | { |
| 907 | l_int32 n, x1, y1, x2, y2, x3, y3, x4, y4, x, y, xmax, ymax; |
| 908 | |
| 909 | PROCNAME("ptaConvertToBox"); |
| 910 | |
| 911 | if (!pta) |
| 912 | return (BOX *)ERROR_PTR("pta not defined", procName, NULL); |
| 913 | n = ptaGetCount(pta); |
| 914 | ptaGetIPt(pta, 0, &x1, &y1); |
| 915 | ptaGetIPt(pta, 1, &x2, &y2); |
| 916 | if (n == 2) |
| 917 | return boxCreate(x1, y1, x2 - x1 + 1, y2 - y1 + 1); |
| 918 | |
| 919 | /* 4 corners */ |
| 920 | ptaGetIPt(pta, 2, &x3, &y3); |
| 921 | ptaGetIPt(pta, 3, &x4, &y4); |
| 922 | x = L_MIN(x1, x3); |
| 923 | y = L_MIN(y1, y2); |
| 924 | xmax = L_MAX(x2, x4); |
| 925 | ymax = L_MAX(y3, y4); |
| 926 | return boxCreate(x, y, xmax - x + 1, ymax - y + 1); |
| 927 | } |
| 928 | |
| 929 | |
| 930 | /*---------------------------------------------------------------------* |
no test coverage detected