Bridges-C++  3.4.1
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 
27  public:
33  setRectangle(0., 0., 1., 1.);
34  }
35 
41  Rectangle (double w, double h) {
42  setRectangle (0., 0., w, h);
43  }
44 
53  Rectangle (double llx, double lly, double w, double h) {
54  setRectangle (llx, lly, w, h);
55  }
56 
62  virtual string getShapeType() const override {
63  return "rect";
64  }
65 
71  float getWidth() {
72  return width;
73  }
79  void setWidth(double w) {
80  if (w <= 0.) {
81  throw "Illegal Size Value! Please enter a value in the range(0-300)";
82  }
83  width = w;
84  }
85 
91  float getHeight() {
92  return height;
93  }
99  void setHeight(double h) {
100  if (h <= 0.) {
101  throw "Illegal Size Value! Please enter a value in the range(0-300)";
102  }
103  height = h;
104  }
105 
106  /*
107  * @brief This method sets the location and size of the rectangle
108  *
109  * @pram locx x coordinate of location
110  * @pram locy y coordinate of location
111  * @param w width of rectangle
112  * @param h height of rectangle
113  *
114  * @return none
115  */
116  void setRectangle(double llx, double lly, double w, double h) {
117  setLL(llx, lly);
118  setWidth(w);
119  setHeight(h);
120  }
121  void setLL(double llx, double lly) {
122  ll_x = llx;
123  ll_y = lly;
124  }
125 
126  double getLLX () const {
127  return ll_x;
128  }
129 
130  double getLLY () const {
131  return ll_y;
132  }
133 
139  virtual const string getSymbolRepresentation() const override {
140 
141  string shape_json = getSymbolAttributeRepresentation();
142 
143  // set up width and height of rectangles
144  shape_json +=
145  QUOTE + "lowerleftcorner" + QUOTE + COLON +
146  OPEN_BOX +
147  to_string(ll_x) + COMMA + to_string(ll_y) +
148  CLOSE_BOX + COMMA +
149  QUOTE + "width" + QUOTE + COLON + to_string(width) + COMMA +
150  QUOTE + "height" + QUOTE + COLON + to_string(height) +
151  CLOSE_CURLY;
152 
153  return shape_json;
154 
155  }
156  };
157  }
158 } // namespace bridges
159 
160 #endif
double getLLY() const
Definition: Rectangle.h:130
const string COLON
Definition: DataStructure.h:51
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:53
void setRectangle(double llx, double lly, double w, double h)
Definition: Rectangle.h:116
double getLLX() const
Definition: Rectangle.h:126
const string OPEN_BOX
Definition: DataStructure.h:54
const string CLOSE_CURLY
Definition: DataStructure.h:53
void setWidth(double w)
This method sets the shape width.
Definition: Rectangle.h:79
This is an abstract class for deriving a number of Symbol shape objects, for use in a SymbolCollectio...
Definition: Symbol.h:32
void setLL(double llx, double lly)
Definition: Rectangle.h:121
float getHeight()
This method gets the rectangle height.
Definition: Rectangle.h:91
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
float getWidth()
This method gets the rectangle width.
Definition: Rectangle.h:71
const string CLOSE_BOX
Definition: DataStructure.h:55
Rectangle()
default constructor - rectangle with lower left at origin and unit length sides
Definition: Rectangle.h:32
virtual const string getSymbolRepresentation() const override
This method returns the JSON representation of the shape.
Definition: Rectangle.h:139
Rectangle(double w, double h)
create rectangle with width w and height h
Definition: Rectangle.h:41
virtual string getShapeType() const override
This method gets the shape type name.
Definition: Rectangle.h:62
const string COMMA
Definition: DataStructure.h:50
const string QUOTE
Definition: DataStructure.h:49
void setHeight(double h)
This method sets the shape height.
Definition: Rectangle.h:99
This class defines a rectangle and is part of the symbol collection. A rectangle has height and width...
Definition: Rectangle.h:22