Bridges-C++  3.4.2
Bridges(C++ API)
Circle.h
Go to the documentation of this file.
1 #include "DataStructure.h"
2 #include "Symbol.h"
3 #include <vector>
4 
5 using namespace std;
6 
7 #ifndef CIRCLE_H
8 
9 #define CIRCLE_H
10 
11 
12 namespace bridges {
13  namespace datastructure {
22  class Circle : public Symbol {
23  private:
24 
25  double center_x, center_y;
26  double radius = 1.;
27 
33  virtual string getShapeType() const override {
34  return "circle";
35  }
36 
37 
38  public:
39 
43  Circle () {
44  setCircle(0., 0., 1.);
45  }
46 
51  Circle (double r) {
52  setCircle (0., 0., r);
53  }
54 
60  Circle (double cx, double cy, double r) {
61  center_x = cx; center_y = cy;
62  if (r < 0.)
63  throw "Illegal value for radius. Must be positive";
64  radius = r;
65  }
66 
72  double getRadius() {
73  return radius;
74  }
80  void setRadius(double r) {
81  if (r < 0.)
82  throw "Illegal value for radius. Must be positive";
83  radius = r;
84  }
85 
93  void setCircle (double cx, double cy, double r) {
94  setCenter(cx,cy);
95  if (r < 0.)
96  throw "Illegal value for radius. Must be positive";
97  radius = r;
98  }
99  void setCenter (double cx, double cy) {
100  center_x = cx;
101  center_y = cy;
102  }
103 
104 
105  double getCenterX() const {
106  return center_x;
107  }
108  double getCenterY() const {
109  return center_y;
110  }
111 
117  const string getSymbolRepresentation() const override {
118 
119  string shape_json = getSymbolAttributeRepresentation();
120 
121  shape_json +=
122  QUOTE + "center" + QUOTE + COLON +
123  OPEN_BOX +
124  to_string(center_x) + COMMA + to_string(center_y) +
125  CLOSE_BOX + COMMA +
126  QUOTE + "r" + QUOTE + COLON + to_string(radius) + CLOSE_CURLY;
127 
128  return shape_json;
129 
130  }
131  };
132  }
133 } // namespace bridges
134 
135 #endif
This class defines a circle and is part of the symbol collection. A circle has a radius.
Definition: Circle.h:22
Circle()
Definition: Circle.h:43
void setRadius(double r)
This method sets the radius of the circle.
Definition: Circle.h:80
double getRadius()
This method returns the radius of the circle.
Definition: Circle.h:72
void setCircle(double cx, double cy, double r)
This method sets the circle dimensions.
Definition: Circle.h:93
double getCenterX() const
Definition: Circle.h:105
const string getSymbolRepresentation() const override
Definition: Circle.h:117
void setCenter(double cx, double cy)
Definition: Circle.h:99
Circle(double r)
Definition: Circle.h:51
Circle(double cx, double cy, double r)
Definition: Circle.h:60
double getCenterY() const
Definition: Circle.h:108
This is an abstract class for deriving a number of Symbol shape objects, for use in a SymbolCollectio...
Definition: Symbol.h:32
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:51
const string OPEN_BOX
Definition: DataStructure.h:54
const string COMMA
Definition: DataStructure.h:50
const string CLOSE_BOX
Definition: DataStructure.h:55
const string CLOSE_CURLY
Definition: DataStructure.h:53
const string QUOTE
Definition: DataStructure.h:49