Wildmeshing Toolkit
TriangleFanOptions.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <array>
3 #include <iostream>
4 #include <nlohmann/json.hpp>
5 #include <optional>
6 #include <string>
7 
10 {
11 public:
12  constexpr static auto name() -> std::string_view { return "triangle_fan"; }
13  int64_t size;
14  struct Coordinates
15  {
16  std::string name;
17  std::array<double, 2> center;
18  double radius;
19  std::array<double, 2> degrees; // in degrees
20 
21  friend void to_json(nlohmann::json& nlohmann_json_j, const Coordinates& nlohmann_json_t)
22  {
23  NLOHMANN_JSON_EXPAND(
24  NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, name, radius, center, degrees));
25  }
26  friend void from_json(const nlohmann::json& nlohmann_json_j, Coordinates& nlohmann_json_t)
27  {
28  NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, name, radius, center));
29  assert(nlohmann_json_j.contains("degrees"));
30  if (const auto& deg = nlohmann_json_j["degrees"]; deg.is_number()) {
31  nlohmann_json_t.degrees = std::array<double, 2>{{0.0, double(deg)}};
32  } else {
33  nlohmann_json_t.degrees = deg.get<std::array<double, 2>>();
34  }
35  }
36  };
37  std::optional<Coordinates> coordinates;
38 
39  std::optional<std::string> get_coordinate_name() const
40  {
41  if (coordinates.has_value()) {
42  return coordinates.value().name;
43  } else {
44  return {};
45  }
46  }
47  friend void to_json(nlohmann::json& nlohmann_json_j, const TriangleFanOptions& nlohmann_json_t)
48  {
49  nlohmann_json_j["size"] = nlohmann_json_t.size;
50  if (nlohmann_json_t.coordinates.has_value()) {
51  nlohmann_json_j["coordinates"] = *nlohmann_json_t.coordinates;
52  }
53  }
54  friend void from_json(
55  const nlohmann::json& nlohmann_json_j,
56  TriangleFanOptions& nlohmann_json_t)
57  {
58  nlohmann_json_t.size = nlohmann_json_j["size"];
59  if (const auto& coords = nlohmann_json_j["coordinates"]; !coords.is_null()) {
60  nlohmann_json_t.coordinates = coords.get<Coordinates>();
61  }
62  }
63 };
64 } // namespace wmtk::components::procedural
constexpr static auto name() -> std::string_view
friend void from_json(const nlohmann::json &nlohmann_json_j, TriangleFanOptions &nlohmann_json_t)
friend void to_json(nlohmann::json &nlohmann_json_j, const TriangleFanOptions &nlohmann_json_t)
std::optional< std::string > get_coordinate_name() const
friend void to_json(nlohmann::json &nlohmann_json_j, const Coordinates &nlohmann_json_t)
friend void from_json(const nlohmann::json &nlohmann_json_j, Coordinates &nlohmann_json_t)
nlohmann::json json
Definition: input.cpp:9