Horizon
polygon.hpp
1 #pragma once
2 #include "util/uuid.hpp"
3 #include "nlohmann/json_fwd.hpp"
4 #include "common.hpp"
5 #include "junction.hpp"
6 #include "util/uuid_ptr.hpp"
7 #include <deque>
8 
9 namespace horizon {
10 using json = nlohmann::json;
11 
12 
13 class PolygonUsage {
14 public:
15  enum class Type { INVALID, PLANE, KEEPOUT };
16  virtual Type get_type() const = 0;
17  virtual UUID get_uuid() const = 0;
18  virtual ~PolygonUsage(){};
19 };
20 
25 class Polygon {
26 public:
27  class Vertex {
28  public:
29  enum class Type { LINE, ARC };
30 
31  Vertex(const json &j);
32  Vertex(const Coordi &c);
33  Vertex()
34  {
35  }
36  json serialize() const;
37  bool remove = false;
38 
39  Type type = Type::LINE;
40  Coordi position;
41  Coordi arc_center;
46  bool arc_reverse = false;
47  };
48 
49 
50  Polygon(const UUID &uu, const json &j);
51  Polygon(const UUID &uu);
52  UUID get_uuid() const;
53 
54  Vertex *append_vertex(const Coordi &pos = Coordi());
55  std::pair<unsigned int, unsigned int> get_vertices_for_edge(unsigned int edge);
56  const Vertex &get_vertex(int edge) const;
57  Vertex &get_vertex(int edge);
63  Polygon remove_arcs(unsigned int precision = 16) const;
64 
68  bool has_arcs() const;
69  bool is_valid() const;
70  std::pair<Coordi, Coordi> get_bbox() const;
71 
72  bool is_cw() const;
73  bool is_ccw() const;
74 
75  void reverse();
76 
77  bool is_rect() const;
78 
79  UUID uuid;
80  std::vector<Vertex> vertices;
81  int layer = 0;
82  std::string parameter_class;
83 
85  json serialize() const;
86 };
87 } // namespace horizon
Definition: polygon.hpp:13
Definition: polygon.hpp:27
bool arc_reverse
false: counter clockwise true: clockwise
Definition: polygon.hpp:46
Polygon used in Padstack, Package and Board for specifying filled Regions.
Definition: polygon.hpp:25
Polygon remove_arcs(unsigned int precision=16) const
Definition: polygon.cpp:53
bool has_arcs() const
Definition: polygon.cpp:114
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: uuid_ptr.hpp:8
a class to store JSON values
Definition: json.hpp:177
basic_json<> json
default JSON class
Definition: json_fwd.hpp:62