Horizon
Loading...
Searching...
No Matches
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
9namespace horizon {
10using json = nlohmann::json;
11
12
14public:
15 virtual UUID get_uuid() const = 0;
16 virtual ObjectType get_type() const = 0;
17 template <typename T> bool is_type() const
18 {
19 return dynamic_cast<const T *>(this);
20 }
21 virtual ~PolygonUsage(){};
22};
23
28class Polygon {
29public:
30 class Vertex {
31 public:
32 enum class Type { LINE, ARC };
33
34 Vertex(const json &j);
35 Vertex(const Coordi &c);
36 Vertex()
37 {
38 }
39 json serialize() const;
40 bool remove = false;
41
42 Type type = Type::LINE;
43 Coordi position;
44 Coordi arc_center;
49 bool arc_reverse = false;
50 };
51
52
53 Polygon(const UUID &uu, const json &j);
54 Polygon(const UUID &uu);
55 UUID get_uuid() const;
56
57 Vertex *append_vertex(const Coordi &pos = Coordi());
58 std::pair<unsigned int, unsigned int> get_vertices_for_edge(unsigned int edge);
59 const Vertex &get_vertex(int edge) const;
60 Vertex &get_vertex(int edge);
66 Polygon remove_arcs(unsigned int precision = 16) const;
67
71 bool has_arcs() const;
72 bool is_valid() const;
73 std::pair<Coordi, Coordi> get_bbox() const;
74
75 bool is_cw() const;
76 bool is_ccw() const;
77
78 void reverse();
79
80 bool is_rect() const;
81
82 UUID uuid;
83 std::vector<Vertex> vertices;
84 int layer = 0;
85 std::string parameter_class;
86
88 json serialize() const;
89};
90} // namespace horizon
Definition polygon.hpp:13
Definition polygon.hpp:30
bool arc_reverse
false: counter clockwise true: clockwise
Definition polygon.hpp:49
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
basic_json<> json
default JSON class
Definition json_fwd.hpp:62