Bridges-C++  3.4.5-dev1-6-g935685a
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 namespace bridges {
12  namespace datastructure {
21  class Circle : public Symbol {
22  private:
23 
24  double center_x, center_y;
25  double radius = 1.;
26 
32  virtual string getShapeType() const override {
33  return "circle";
34  }
35 
36  public:
37 
41  Circle () {
42  setCircle(0., 0., 1.);
43  }
44 
49  Circle (double r) {
50  setCircle (0., 0., r);
51  }
52 
58  Circle (double cx, double cy, double r) {
59  center_x = cx;
60  center_y = cy;
61  if (r < 0.)
62  throw "Illegal value for radius. Must be positive";
63  radius = r;
64  }
65 
71  double getRadius() {
72  return radius;
73  }
79  void setRadius(double r) {
80  if (r < 0.)
81  throw "Illegal value for radius. Must be positive";
82  radius = r;
83  }
84 
92  void setCircle (double cx, double cy, double r) {
93  setCenter(cx, cy);
94  if (r < 0.)
95  throw "Illegal value for radius. Must be positive";
96  radius = r;
97  }
98  void setCenter (double cx, double cy) {
99  center_x = cx;
100  center_y = cy;
101  }
102 
103  double getCenterX() const {
104  return center_x;
105  }
106  double getCenterY() const {
107  return center_y;
108  }
109 
115  const string getSymbolRepresentation() const override {
116 
117  string shape_json = getSymbolAttributeRepresentation();
118 
119  shape_json +=
120  QUOTE + "center" + QUOTE + COLON +
121  OPEN_BOX +
122  to_string(center_x) + COMMA + to_string(center_y) +
123  CLOSE_BOX + COMMA +
124  QUOTE + "r" + QUOTE + COLON + to_string(radius) + CLOSE_CURLY;
125 
126  return shape_json;
127 
128  }
129  };
130  }
131 } // namespace bridges
132 
133 #endif
This class defines a circle and is part of the symbol collection. A circle has a radius.
Definition: Circle.h:21
Circle()
Definition: Circle.h:41
void setRadius(double r)
This method sets the radius of the circle.
Definition: Circle.h:79
double getRadius()
This method returns the radius of the circle.
Definition: Circle.h:71
void setCircle(double cx, double cy, double r)
This method sets the circle dimensions.
Definition: Circle.h:92
double getCenterX() const
Definition: Circle.h:103
const string getSymbolRepresentation() const override
Definition: Circle.h:115
void setCenter(double cx, double cy)
Definition: Circle.h:98
Circle(double r)
Definition: Circle.h:49
Circle(double cx, double cy, double r)
Definition: Circle.h:58
double getCenterY() const
Definition: Circle.h:106
This is an abstract class for deriving a number of Symbol shape objects, for use in a SymbolCollectio...
Definition: Symbol.h:31
Support for drawing Bar charts.
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:52
const string OPEN_BOX
Definition: DataStructure.h:55
const string COMMA
Definition: DataStructure.h:51
const string CLOSE_BOX
Definition: DataStructure.h:56
const string CLOSE_CURLY
Definition: DataStructure.h:54
const string QUOTE
Definition: DataStructure.h:50