| 156 | } |
| 157 | |
| 158 | Result<std::optional<AxisAlignedBox>> |
| 159 | parseBoundingBox(const rapidjson::Value& value) { |
| 160 | if (!value.IsArray()) { |
| 161 | return Result<std::optional<AxisAlignedBox>>( |
| 162 | std::nullopt, |
| 163 | ErrorList::warning("'bbox' member must be an array.")); |
| 164 | } |
| 165 | |
| 166 | const int32_t size = static_cast<int32_t>(value.Size()); |
| 167 | if (size != 4 && size != 6) { |
| 168 | return Result<std::optional<AxisAlignedBox>>( |
| 169 | std::nullopt, |
| 170 | ErrorList::warning( |
| 171 | "'bbox' member must be of length 4 (2D) or 6 (3D).")); |
| 172 | } |
| 173 | |
| 174 | std::array<const rapidjson::Value*, 6> coordinates{ |
| 175 | &value.GetArray()[0], |
| 176 | &value.GetArray()[1], |
| 177 | size == 4 ? &value.GetArray()[2] : &value.GetArray()[3], |
| 178 | size == 4 ? &value.GetArray()[3] : &value.GetArray()[4], |
| 179 | // We only read these two if size == 6, so it's ok that they're nullptr |
| 180 | size == 4 ? nullptr : &value.GetArray()[2], |
| 181 | size == 4 ? nullptr : &value.GetArray()[5]}; |
| 182 | |
| 183 | for (size_t i = 0; i < (size_t)size; i++) { |
| 184 | if (!coordinates[i]->IsNumber()) { |
| 185 | return ErrorList::warning("'bbox' member must contain only doubles."); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | return Result<std::optional<AxisAlignedBox>>( |
| 190 | std::optional<AxisAlignedBox>{AxisAlignedBox( |
| 191 | std::min(coordinates[0]->GetDouble(), coordinates[2]->GetDouble()), |
| 192 | std::min(coordinates[1]->GetDouble(), coordinates[3]->GetDouble()), |
| 193 | size == 4 ? 0.0 |
| 194 | : std::min( |
| 195 | coordinates[4]->GetDouble(), |
| 196 | coordinates[5]->GetDouble()), |
| 197 | std::max(coordinates[0]->GetDouble(), coordinates[2]->GetDouble()), |
| 198 | std::max(coordinates[1]->GetDouble(), coordinates[3]->GetDouble()), |
| 199 | size == 4 ? 0.0 |
| 200 | : std::max( |
| 201 | coordinates[4]->GetDouble(), |
| 202 | coordinates[5]->GetDouble()))}); |
| 203 | } |
| 204 | |
| 205 | Result<GeoJsonObject> parseGeoJsonObject( |
| 206 | const rapidjson::Value::ConstObject& obj, |
no test coverage detected