Wildmeshing Toolkit
Loading...
Searching...
No Matches
DiskOptions.hpp
Go to the documentation of this file.
1#pragma once
2#include <array>
3#include <nlohmann/json.hpp>
4#include <optional>
5#include <string>
7
9{
10public:
11 constexpr static auto name() -> std::string_view { return "disk"; }
12 int64_t size;
14 {
15 std::string name;
16 std::array<double, 2> center;
17 double radius;
18 double degree_offset; // in degrees
20 };
21 std::optional<Coordinates> coordinates;
22 std::optional<std::string> get_coordinate_name() const
23 {
24 if (coordinates.has_value()) {
25 return coordinates.value().name;
26 } else {
27 return {};
28 }
29 }
30 friend void to_json(nlohmann::json& nlohmann_json_j, const DiskOptions& nlohmann_json_t)
31 {
32 nlohmann_json_j["size"] = nlohmann_json_t.size;
33 if (nlohmann_json_t.coordinates.has_value()) {
34 nlohmann_json_j["coordinates"] = *nlohmann_json_t.coordinates;
35 }
36 }
37 friend void from_json(const nlohmann::json& nlohmann_json_j, DiskOptions& nlohmann_json_t)
38 {
39 nlohmann_json_t.size = nlohmann_json_j["size"];
40 if (const auto& coords = nlohmann_json_j["coordinates"]; !coords.is_null()) {
41 nlohmann_json_t.coordinates = coords.get<Coordinates>();
42 }
43 }
44};
45} // namespace wmtk::components::procedural
friend void to_json(nlohmann::json &nlohmann_json_j, const DiskOptions &nlohmann_json_t)
std::optional< std::string > get_coordinate_name() const
static constexpr auto name() -> std::string_view
friend void from_json(const nlohmann::json &nlohmann_json_j, DiskOptions &nlohmann_json_t)
std::optional< Coordinates > coordinates
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Coordinates, name, center, radius, degree_offset)