Bridges-C++  3.4.5-dev1-6-g935685a
Bridges(C++ API)
Rectangle.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 RECTANGLE_H
8 
9 #define RECTANGLE_H
10 
11 namespace bridges {
12  namespace datastructure {
21  class Rectangle : public Symbol {
22  private:
23  // Rectangle specification: lower left corner and dimensions
24  double ll_x = 0., ll_y = 0., width = 1.0, height = 1.0;
25 
31  virtual string getShapeType() const override {
32  return "rect";
33  }
34 
35  public:
41  setRectangle(0., 0., 1., 1.);
42  }
43 
49  Rectangle (double w, double h) {
50  setRectangle (0., 0., w, h);
51  }
52 
61  Rectangle (double llx, double lly, double w, double h) {
62  setRectangle (llx, lly, w, h);
63  }
64 
70  float getWidth() {
71  return width;
72  }
78  void setWidth(double w) {
79  if (w <= 0.) {
80  throw "Illegal Size Value! Please enter a value in the range(0-300)";
81  }
82  width = w;
83  }
84 
90  float getHeight() {
91  return height;
92  }
98  void setHeight(double h) {
99  if (h <= 0.) {
100  throw "Illegal Size Value! Please enter a value in the range(0-300)";
101  }
102  height = h;
103  }
104 
105  /*
106  * @brief This method sets the location and size of the rectangle
107  *
108  * @pram locx x coordinate of location
109  * @pram locy y coordinate of location
110  * @param w width of rectangle
111  * @param h height of rectangle
112  *
113  * @return none
114  */
115  void setRectangle(double llx, double lly, double w, double h) {
116  setLL(llx, lly);
117  setWidth(w);
118  setHeight(h);
119  }
120  void setLL(double llx, double lly) {
121  ll_x = llx;
122  ll_y = lly;
123  }
124 
125  double getLLX () const {
126  return ll_x;
127  }
128 
129  double getLLY () const {
130  return ll_y;
131  }
132 
138  virtual const string getSymbolRepresentation() const override {
139 
140  string shape_json = getSymbolAttributeRepresentation();
141 
142  // set up width and height of rectangles
143  shape_json +=
144  QUOTE + "lowerleftcorner" + QUOTE + COLON +
145  OPEN_BOX +
146  to_string(ll_x) + COMMA + to_string(ll_y) +
147  CLOSE_BOX + COMMA +
148  QUOTE + "width" + QUOTE + COLON + to_string(width) + COMMA +
149  QUOTE + "height" + QUOTE + COLON + to_string(height) +
150  CLOSE_CURLY;
151 
152  return shape_json;
153 
154  }
155  };
156  }
157 } // namespace bridges
158 
159 #endif
This class defines a rectangle and is part of the symbol collection. A rectangle has height and width...
Definition: Rectangle.h:21
void setRectangle(double llx, double lly, double w, double h)
Definition: Rectangle.h:115
Rectangle(double w, double h)
create rectangle with width w and height h
Definition: Rectangle.h:49
double getLLX() const
Definition: Rectangle.h:125
virtual const string getSymbolRepresentation() const override
This method returns the JSON representation of the shape.
Definition: Rectangle.h:138
void setWidth(double w)
This method sets the shape width.
Definition: Rectangle.h:78
float getWidth()
This method gets the rectangle width.
Definition: Rectangle.h:70
void setLL(double llx, double lly)
Definition: Rectangle.h:120
Rectangle(double llx, double lly, double w, double h)
create rectangle with width w and height h and located at given position
Definition: Rectangle.h:61
Rectangle()
default constructor - rectangle with lower left at origin and unit length sides
Definition: Rectangle.h:40
float getHeight()
This method gets the rectangle height.
Definition: Rectangle.h:90
void setHeight(double h)
This method sets the shape height.
Definition: Rectangle.h:98
double getLLY() const
Definition: Rectangle.h:129
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