| 133 | } |
| 134 | |
| 135 | RectD jsonToRectD(Json const& v) { |
| 136 | if (v.type() != Json::Type::Array) |
| 137 | throw JsonException("Json not an array in jsonToRectD"); |
| 138 | |
| 139 | if (v.size() != 4 && v.size() != 2) |
| 140 | throw JsonException("Json not an array of proper size in jsonToRectD"); |
| 141 | |
| 142 | if (v.size() == 4) |
| 143 | return RectD(v.getDouble(0), v.getDouble(1), v.getDouble(2), v.getDouble(3)); |
| 144 | |
| 145 | try { |
| 146 | auto lowerLeft = jsonToVec2D(v.get(0)); |
| 147 | auto upperRight = jsonToVec2D(v.get(1)); |
| 148 | return RectD(lowerLeft, upperRight); |
| 149 | } catch (JsonException const& e) { |
| 150 | throw JsonException(strf("Inner position not well formed in jsonToRectD: {}", outputException(e, true))); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | Json jsonFromRectD(RectD const& rect) { |
| 155 | return JsonArray{rect.xMin(), rect.yMin(), rect.xMax(), rect.yMax()}; |
no test coverage detected