9 #include <boost/test/unit_test.hpp>
33 #include <nlohmann/json.hpp>
41 BOOST_AUTO_TEST_SUITE(SurfaceJsonConversion)
45 auto cone = std::make_shared<ConeBounds>(0.123, 10., 100.);
46 auto coneRef = Surface::makeShared<ConeSurface>(trf, cone);
51 out.open(
"ConeSurface.json");
52 out << coneOut.dump(2);
55 auto in = std::ifstream(
"ConeSurface.json",
57 BOOST_CHECK(
in.good());
58 nlohmann::json coneIn;
64 BOOST_CHECK(coneTest->transform(
gctx).isApprox(coneRef->transform(
gctx)));
65 BOOST_CHECK(coneTest->geometryId() == coneRef->geometryId());
66 BOOST_CHECK(coneTest->bounds() == coneRef->bounds());
71 auto ring = std::make_shared<RadialBounds>(0., 4.);
72 auto ringDiscRef = Surface::makeShared<DiscSurface>(trf, ring);
77 out.open(
"DiscSurface.json");
78 out << discOut.dump(2);
81 auto in = std::ifstream(
"DiscSurface.json",
83 BOOST_CHECK(
in.good());
84 nlohmann::json discIn;
91 ringDiscTest->transform(
gctx).isApprox(ringDiscRef->transform(
gctx)));
92 BOOST_CHECK(ringDiscTest->geometryId() == ringDiscRef->geometryId());
93 BOOST_CHECK(ringDiscTest->bounds() == ringDiscRef->bounds());
98 auto tube = std::make_shared<CylinderBounds>(5., 20.);
99 auto cylinderRef = Surface::makeShared<CylinderSurface>(trf, tube);
104 out.open(
"CylinderSurface.json");
105 out << cylinderOut.dump(2);
108 auto in = std::ifstream(
"CylinderSurface.json",
110 BOOST_CHECK(
in.good());
111 nlohmann::json cylinderIn;
118 cylinderTest->transform(
gctx).isApprox(cylinderRef->transform(
gctx)));
119 BOOST_CHECK(cylinderTest->geometryId() == cylinderRef->geometryId());
120 BOOST_CHECK(cylinderTest->bounds() == cylinderRef->bounds());
125 auto trapezoid = std::make_shared<TrapezoidBounds>(2., 3., 4.);
126 auto trapezoidPlaneRef = Surface::makeShared<PlaneSurface>(trf, trapezoid);
130 nlohmann::json planeOut =
132 to_json(planeOut, *trapezoidPlaneRef);
133 out.open(
"PlaneSurface.json");
134 out << planeOut.dump(2);
137 auto in = std::ifstream(
"PlaneSurface.json",
139 BOOST_CHECK(
in.good());
140 nlohmann::json planeIn;
146 BOOST_CHECK(trapezoidPlaneTest->transform(
gctx).isApprox(
147 trapezoidPlaneRef->transform(
gctx)));
148 BOOST_CHECK(trapezoidPlaneTest->geometryId() ==
149 trapezoidPlaneRef->geometryId());
150 BOOST_CHECK(trapezoidPlaneTest->bounds() == trapezoidPlaneRef->bounds());
155 auto straw = std::make_shared<LineBounds>(1., 100.);
156 auto strawRef = Surface::makeShared<StrawSurface>(trf, straw);
161 out.open(
"StrawSurface.json");
162 out << strawOut.dump(2);
165 auto in = std::ifstream(
"StrawSurface.json",
167 BOOST_CHECK(
in.good());
168 nlohmann::json strawIn;
174 BOOST_CHECK(strawTest->transform(
gctx).isApprox(strawRef->transform(
gctx)));
175 BOOST_CHECK(strawTest->geometryId() == strawRef->geometryId());
176 BOOST_CHECK(strawTest->bounds() == strawRef->bounds());
181 auto perigeeRef = Surface::makeShared<PerigeeSurface>(trf);
186 out.open(
"PerigeeSurface.json");
187 out << perigeeOut.dump(2);
190 auto in = std::ifstream(
"PerigeeSurface.json",
192 BOOST_CHECK(
in.good());
193 nlohmann::json perigeeIn;
200 perigeeTest->transform(
gctx).isApprox(perigeeRef->transform(
gctx)));
201 BOOST_CHECK(perigeeTest->geometryId() == perigeeRef->geometryId());
206 auto trapezoid = std::make_shared<TrapezoidBounds>(2., 3., 4.);
207 auto trapezoidPlaneRef = Surface::makeShared<PlaneSurface>(trf, trapezoid);
211 nlohmann::json trapOut =
213 out.open(
"Surfaces-detray.json");
214 out << trapOut.dump(2);
218 BOOST_AUTO_TEST_SUITE_END()