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