File indexing completed on 2025-10-31 08:17:36
0001 
0002 
0003 
0004 
0005 
0006 
0007 
0008 
0009 #include "ActsPlugins/Json/ExtentJsonConverter.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Utilities/BinningType.hpp"
0013 #include "Acts/Utilities/Enumerate.hpp"
0014 #include "Acts/Utilities/RangeXD.hpp"
0015 #include "ActsPlugins/Json/UtilitiesJsonConverter.hpp"
0016 
0017 #include <array>
0018 #include <iterator>
0019 #include <vector>
0020 
0021 void Acts::to_json(nlohmann::json& j, const Acts::Extent& e) {
0022   {
0023     nlohmann::json jrange;
0024     const auto& xrange = e.range();
0025     for (auto ibv : allAxisDirections()) {
0026       if (e.constrains(ibv)) {
0027         jrange[axisDirectionName(ibv)] = xrange[toUnderlying(ibv)];
0028       }
0029     }
0030     j["range"] = jrange;
0031   }
0032 
0033   {
0034     nlohmann::json jenvelope;
0035     const auto& envelope = e.envelope();
0036     for (auto ibv : allAxisDirections()) {
0037       if (envelope[ibv] != zeroEnvelope) {
0038         jenvelope[axisDirectionName(ibv)] =
0039             Range1D<double>(envelope[ibv][0], envelope[ibv][1]);
0040       }
0041     }
0042     if (!jenvelope.empty()) {
0043       j["envelope"] = jenvelope;
0044     }
0045   }
0046 }
0047 
0048 void Acts::from_json(const nlohmann::json& j, Acts::Extent& e) {
0049   const auto& jrange = j["range"];
0050 
0051   for (const auto& [key, value] : jrange.items()) {
0052     AxisDirection bval = axisDirectionFromName(key);
0053     e.set(bval, value["min"], value["max"]);
0054   }
0055 
0056   if (j.contains("envelope")) {
0057     const auto& jenvelope = j["envelope"];
0058     ExtentEnvelope envelope;
0059 
0060     for (const auto& [key, value] : jenvelope.items()) {
0061       AxisDirection bval = axisDirectionFromName(key);
0062       envelope[bval] = {value["min"], value["max"]};
0063     }
0064 
0065     e.setEnvelope(envelope);
0066   }
0067 }