Bridges-C++  3.2.0
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 
8 #ifndef CIRCLE_H
9 
10 #define CIRCLE_H
11 
12 namespace bridges {
13  namespace datastructure {
22  class Circle : public Symbol {
23  private:
24 
25  int radius = 1.;
26 
27  public:
28 
32  Circle () {
33  setCircle(0., 0., 1.);
34  }
35 
40  Circle (int r) {
41  setCircle (0., 0., r);
42  }
43 
49  Circle (int locx, int locy, int r) {
50  setLocation ((float)locx, (float)locy);
51  if (r < 0)
52  throw "Illegal value for radius. Must be positive";
53  radius = r;
54  }
55 
60  string getDataStructType() {
61  return "circle";
62  }
63 
69  string getName() const {
70  return "circle";
71  }
72 
78  void setRadius(int r) {
79  if (r < 0)
80  throw "Illegal value for radius. Must be positive";
81  radius = r;
82  }
83 
91  void setCircle (int locx, int locy, int r) {
92  setLocation (locx, locy);
93  if (r < 0)
94  throw "Illegal value for radius. Must be positive";
95  radius = r;
96  setShapeType("circle");
97  }
98 
104  void translate(float tx, float ty) {
105  const float *center = getLocation();
106  float ncenter[2];
107  ncenter[0] = center[0];
108  ncenter[1] = center[1];
109  translatePoint (ncenter, tx, ty);
110  setLocation(ncenter[0], ncenter[1]);
111  }
118  void scale(float scale) {
119  // scale only the radius,
120  // center stays the same
121  radius *= scale;
122  }
129  vector<float> getDimensions() const {
130 
131  vector<float> dims(4);
132  const float *location = getLocation();
133 
134  dims[0] = location[0] - radius;
135  dims[1] = location[0] + radius;
136  dims[2] = location[1] - radius;
137  dims[3] = location[1] + radius;
138 
139  return dims;
140  }
141 
147  const string getSymbolRepresentation() const {
148 
149  string shape_json = getSymbolAttributeRepresentation();
150  string shape = getShapeType();
151 
152  shape_json +=
153  QUOTE + "name" + QUOTE + COLON + QUOTE + getLabel() + QUOTE + COMMA +
154  QUOTE + "shape" + QUOTE + COLON + QUOTE + shape + QUOTE + COMMA;
155 
156  if (shape == "circle")
157  shape_json += QUOTE + "r" + QUOTE + COLON + to_string(radius)
158  + CLOSE_CURLY;
159 
160  return shape_json;
161 
162  }
163  };
164  }
165 } // namespace bridges
166 
167 #endif
Circle(int r)
Definition: Circle.h:40
const string COLON
Definition: DataStructure.h:51
STL namespace.
string getDataStructType()
Definition: Circle.h:60
const string CLOSE_CURLY
Definition: DataStructure.h:53
This is an abstract class for deriving a number of Symbol shape objects, for use in a SymbolCollectio...
Definition: Symbol.h:33
This class defines a circle and is part of the symbol collection. A circle has a radius.
Definition: Circle.h:22
vector< float > getDimensions() const
Definition: Circle.h:129
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
Circle()
Definition: Circle.h:32
string getName() const
Definition: Circle.h:69
Circle(int locx, int locy, int r)
Definition: Circle.h:49
void setCircle(int locx, int locy, int r)
This method sets the circle dimensions.
Definition: Circle.h:91
const string getSymbolRepresentation() const
Definition: Circle.h:147
void scale(float scale)
Definition: Circle.h:118
const string COMMA
Definition: DataStructure.h:50
void setRadius(int r)
This method sets the radius of the circle.
Definition: Circle.h:78
const string QUOTE
Definition: DataStructure.h:49
void translate(float tx, float ty)
Translate the circle along X and Y dimensions.
Definition: Circle.h:104