| 164 | } |
| 165 | |
| 166 | RectI jsonToRectI(Json const& v) { |
| 167 | if (v.type() != Json::Type::Array) |
| 168 | throw JsonException("Json not an array in jsonToRectI"); |
| 169 | |
| 170 | if (v.size() != 4 && v.size() != 2) |
| 171 | throw JsonException("Json not an array of proper size in jsonToRectI"); |
| 172 | |
| 173 | if (v.size() == 4) |
| 174 | return RectI(v.getInt(0), v.getInt(1), v.getInt(2), v.getInt(3)); |
| 175 | |
| 176 | try { |
| 177 | auto lowerLeft = jsonToVec2I(v.get(0)); |
| 178 | auto upperRight = jsonToVec2I(v.get(1)); |
| 179 | return RectI(lowerLeft, upperRight); |
| 180 | } catch (JsonException const& e) { |
| 181 | throw JsonException(strf("Inner position not well formed in jsonToRectI: {}", outputException(e, true))); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | Json jsonFromRectI(RectI const& rect) { |
| 186 | return JsonArray{rect.xMin(), rect.yMin(), rect.xMax(), rect.yMax()}; |
no test coverage detected