GeoJSON position is an array of two or three components, representing [longitude, latitude, (height)]
| 64 | // GeoJSON position is an array of two or three components, representing |
| 65 | // [longitude, latitude, (height)] |
| 66 | Result<glm::dvec3> parsePosition(const rapidjson::Value& pos) { |
| 67 | if (!pos.IsArray()) { |
| 68 | return Result<glm::dvec3>( |
| 69 | ErrorList::error("Position value must be an array.")); |
| 70 | } |
| 71 | |
| 72 | const rapidjson::Value::ConstArray& arr = pos.GetArray(); |
| 73 | |
| 74 | const int32_t size = static_cast<int32_t>(pos.GetArray().Size()); |
| 75 | if (size < 2 || size > 3) { |
| 76 | return Result<glm::dvec3>(ErrorList::error( |
| 77 | "Position value must be an array with two or three members.")); |
| 78 | } |
| 79 | |
| 80 | if (!arr[0].IsNumber() || !arr[1].IsNumber() || |
| 81 | (size > 2 && !arr[2].IsNumber())) { |
| 82 | return ErrorList::error("Position value must be an array of only numbers."); |
| 83 | } |
| 84 | |
| 85 | return glm::dvec3( |
| 86 | arr[0].GetDouble(), |
| 87 | arr[1].GetDouble(), |
| 88 | size == 3 ? arr[2].GetDouble() : 0); |
| 89 | } |
| 90 | |
| 91 | Result<std::vector<glm::dvec3>> |
| 92 | parsePositionArray(const rapidjson::Value::ConstArray& arr) { |
no outgoing calls
no test coverage detected