Read a JSON array of exactly 3 numbers into `out`. Returns nullopt on OK, or a diagnostic fragment (appended by the caller to the field name) on failure.
| 683 | // Read a JSON array of exactly 3 numbers into `out`. Returns nullopt on OK, |
| 684 | // or a diagnostic fragment (appended by the caller to the field name) on failure. |
| 685 | std::optional<std::string> ReadPoint3D(const nlohmann::json& arr, mitk::Point3D& out) |
| 686 | { |
| 687 | if (!arr.is_array()) |
| 688 | return "must be an array of 3 numbers"; |
| 689 | if (arr.size() != 3) |
| 690 | return "must have exactly 3 elements, got " + std::to_string(arr.size()); |
| 691 | for (std::size_t i = 0; i < 3; ++i) |
| 692 | { |
| 693 | if (!arr[i].is_number()) |
| 694 | return "element " + std::to_string(i) + " is not a number"; |
| 695 | out[i] = arr[i].get<double>(); |
| 696 | } |
| 697 | return std::nullopt; |
| 698 | } |
| 699 | |
| 700 | std::optional<std::string> ReadVector3D(const nlohmann::json& arr, mitk::Vector3D& out) |
| 701 | { |
no test coverage detected