TBTK
Need a break? Support the development by playing Polarity Puzzles
Path.h
1 /* Copyright 2017 Kristofer Björnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
17 
24 #ifndef COM_DAFER45_TBTK_PLOT_PATH
25 #define COM_DAFER45_TBTK_PLOT_PATH
26 
27 #include "TBTK/Plot/PlotCanvas.h"
28 #include "TBTK/Plot/Coordinate.h"
29 #include "TBTK/Plot/Decoration.h"
30 #include "TBTK/Plot/Drawable.h"
31 
32 #include <vector>
33 
34 #include <opencv2/core/core.hpp>
35 
36 namespace TBTK{
37 namespace Plot{
38 
39 class Path : public Drawable{
40 public:
42  Path();
43 
45  Path(const std::vector<Coordinate> &coordinates, Decoration &decoration);
46 
48  virtual ~Path();
49 
51  void add(const Coordinate &coordinate);
52 
54  void setDecoration(const Decoration &decoration);
55 
57  virtual void draw(PlotCanvas &canvas);
58 
60  virtual double getMinX() const;
61 
63  virtual double getMaxX() const;
64 
66  virtual double getMinY() const;
67 
69  virtual double getMaxY() const;
70 private:
72  std::vector<Coordinate> coordinates;
73 
75  Decoration decoration;
76 };
77 
78 inline Path::Path(){
79 }
80 
81 inline Path::Path(
82  const std::vector<Coordinate> &coordinates,
83  Decoration &decoration
84 ){
85  this->coordinates = coordinates;
86  this->decoration = decoration;
87 }
88 
89 inline Path::~Path(){
90 }
91 
92 inline void Path::add(const Coordinate &coordinate){
93  coordinates.push_back(coordinate);
94 }
95 
96 inline void Path::setDecoration(const Decoration &decoration){
97  this->decoration = decoration;
98 }
99 
100 inline double Path::getMinX() const{
101  if(coordinates.size() == 0)
102  return 0.;
103 
104  double min = coordinates[0].x;
105  for(unsigned int n = 0; n < coordinates.size(); n++)
106  if(coordinates[n].x < min)
107  min = coordinates[n].x;
108 
109  return min;
110 }
111 
112 inline double Path::getMaxX() const{
113  if(coordinates.size() == 0)
114  return 0.;
115 
116  double max = coordinates[0].x;
117  for(unsigned int n = 0; n < coordinates.size(); n++)
118  if(coordinates[n].x > max)
119  max = coordinates[n].x;
120 
121  return max;
122 }
123 
124 inline double Path::getMinY() const{
125  if(coordinates.size() == 0)
126  return 0.;
127 
128  double min = coordinates[0].y;
129  for(unsigned int n = 0; n < coordinates.size(); n++)
130  if(coordinates[n].y < min)
131  min = coordinates[n].y;
132 
133  return min;
134 }
135 
136 inline double Path::getMaxY() const{
137  if(coordinates.size() == 0)
138  return 0.;
139 
140  double max = coordinates[0].y;
141  for(unsigned int n = 0; n < coordinates.size(); n++)
142  if(coordinates[n].y > max)
143  max = coordinates[n].y;
144 
145  return max;
146 }
147 
148 }; //End namespace Plot
149 }; //End namespace TBTK
150 
151 #endif
152 
DataType max(const Array< DataType > &array)
Definition: ArrayAlgorithms.h:841
DataType min(const Array< DataType > &array)
Definition: ArrayAlgorithms.h:851
Definition: Boolean.h:32