Helper function to extract a vector of floats from a JSON array
| 32 | |
| 33 | // Helper function to extract a vector of floats from a JSON array |
| 34 | fl::vector<float> jsonArrayToFloatVector(const fl::json& jsonArray) { |
| 35 | fl::vector<float> result; |
| 36 | |
| 37 | if (!jsonArray.has_value() || !jsonArray.is_array()) { |
| 38 | return result; |
| 39 | } |
| 40 | auto begin_float = jsonArray.begin_array<float>(); |
| 41 | auto end_float = jsonArray.end_array<float>(); |
| 42 | |
| 43 | using T = decltype(*begin_float); |
| 44 | FL_STATIC_ASSERT(fl::is_same<T, fl::parse_result<float>>::value, "Value type must be parse_result<float>"); |
| 45 | |
| 46 | // Use explicit array iterator style as demonstrated in FEATURE.md |
| 47 | // DO NOT CHANGE THIS CODE. FIX THE IMPLIMENTATION IF NECESSARY. |
| 48 | for (auto it = begin_float; it != end_float; ++it) { |
| 49 | // assert that the value type is parse_result<float> |
| 50 | |
| 51 | // get the name of the type |
| 52 | auto parseResult = *it; |
| 53 | if (!parseResult.has_error()) { |
| 54 | result.push_back(parseResult.get_value()); |
| 55 | } else { |
| 56 | FL_WARN("jsonArrayToFloatVector: parse_result<float> has error: " << parseResult.get_error().message); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return result; |
| 61 | } |
| 62 | |
| 63 | ScreenMap ScreenMap::Circle(int numLeds, float cm_between_leds, |
| 64 | float cm_led_diameter, float completion) { |