MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / jsonToRectD

Function jsonToRectD

source/core/StarJsonExtra.cpp:135–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135RectD 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
154Json jsonFromRectD(RectD const& rect) {
155 return JsonArray{rect.xMin(), rect.yMin(), rect.xMax(), rect.yMax()};

Callers 1

jsonToRectFFunction · 0.85

Calls 7

jsonToVec2DFunction · 0.85
strfFunction · 0.85
getDoubleMethod · 0.80
outputExceptionFunction · 0.70
typeMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected