Bridges-C++ 3.5.0-dev1
Bridges(C++ API)
Loading...
Searching...
No Matches
Polyline.h
Go to the documentation of this file.
1#include "DataStructure.h"
2#include "Symbol.h"
3#include <vector>
4
5using namespace std;
6
7#ifndef POLYLINE_H
8
9#define POLYLINE_H
10
11namespace bridges {
12 namespace datastructure {
23 class Polyline : public Symbol {
24
25 private:
26
32 virtual string getShapeType() const override {
33 return "polyline";
34 }
35
36 protected:
37 // points of the polyline
38 vector<float> points;
39
40 public:
45 points.clear();
46 }
47
52 Polyline (vector<float> pts) {
53 setPolyline(pts);
54 }
55
61 void addPoint(float x, float y) {
62 if ((x > -INFINITY) && (x < INFINITY) &&
63 (y > -INFINITY) && (y < INFINITY)) {
64 points.push_back(x);
65 points.push_back(y);
66 }
67 else {
68 throw "Invalid points for polyline!";
69 }
70 }
76 vector<float> getPoints() {
77 return points;
78 }
79
84 void setPolyline (vector<float> pts) {
85 points = pts;
86 }
87
92 void getCenter(float *center) {
93 float bbox[4];
94 bbox[0] = bbox[1] = INFINITY;
95 bbox[2] = bbox[3] = -INFINITY;
96 for (int k = 0; k < points.size(); k += 2) {
97 if (points[k] < bbox[0])
98 bbox[0] = points[k];
99 if (points[k] > bbox[2])
100 bbox[2] = points[k];
101 if (points[k + 1] < bbox[1])
102 bbox[1] = points[k + 1];
103 if (points[k + 1] > bbox[3])
104 bbox[3] = points[k + 1];
105 }
106 center[0] = bbox[0] + (bbox[2] - bbox[0]) / 2.;
107 center[1] = bbox[1] + (bbox[3] - bbox[1]) / 2.;
108 }
109
115 const string getSymbolRepresentation() const override {
116
117 string shape_json = getSymbolAttributeRepresentation();
118 string shape = getShapeType();
119
120 // add point list to polygons
121 shape_json += QUOTE + "points" + QUOTE + COLON + OPEN_BOX;
122 vector<float>::iterator it;
123 for (int k = 0; k < points.size(); k++) {
124 shape_json += to_string(points[k]) + COMMA;
125 }
126
127 // remove last comma
128 if (points.size())
129 shape_json.erase(shape_json.size() - 1);
130 shape_json += CLOSE_BOX + CLOSE_CURLY;
131
132 return shape_json;
133 }
134 };
135 }
136} // namespace bridges
137
138#endif
This class defines a polyline and is part of the symbol collection. A polyline has a set of vertices ...
Definition Polyline.h:23
void addPoint(float x, float y)
This method adds a point to the polyline.
Definition Polyline.h:61
vector< float > points
Definition Polyline.h:38
vector< float > getPoints()
This method returns the point list of the polyline.
Definition Polyline.h:76
Polyline()
default constructor
Definition Polyline.h:44
void setPolyline(vector< float > pts)
Construct a polyline from sequence of points.
Definition Polyline.h:84
const string getSymbolRepresentation() const override
This method returns the JSON representation of the shape.
Definition Polyline.h:115
Polyline(vector< float > pts)
Construct a polyline from sequence of points.
Definition Polyline.h:52
void getCenter(float *center)
Get center of polyline - use its bounding box.
Definition Polyline.h:92
This is an abstract class for deriving a number of Symbol shape objects, for use in a SymbolCollectio...
Definition Symbol.h:31
const string getSymbolAttributeRepresentation() const
Get the JSON of the symbol representation.
Definition Symbol.h:602
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