CUGL
Cornell University Game Library
CUPathOutliner.h
1 //
2 // CUPathOutliner.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module is a factory for outlining the boundary of a polygon. While
6 // this code is very straight-forward, previous semesters have shown that it
7 // is best to factor this functionality out of Poly2.
8 //
9 // Because math objects are intended to be on the stack, we do not provide
10 // any shared pointer support in this class.
11 //
12 // CUGL zlib License:
13 // This software is provided 'as-is', without any express or implied
14 // warranty. In no event will the authors be held liable for any damages
15 // arising from the use of this software.
16 //
17 // Permission is granted to anyone to use this software for any purpose,
18 // including commercial applications, and to alter it and redistribute it
19 // freely, subject to the following restrictions:
20 //
21 // 1. The origin of this software must not be misrepresented; you must not
22 // claim that you wrote the original software. If you use this software
23 // in a product, an acknowledgment in the product documentation would be
24 // appreciated but is not required.
25 //
26 // 2. Altered source versions must be plainly marked as such, and must not
27 // be misrepresented as being the original software.
28 //
29 // 3. This notice may not be removed or altered from any source distribution.
30 //
31 // Author: Walker White
32 // Version: 6/22/16
33 
34 #ifndef __CU_PATH_OUTLINER_H__
35 #define __CU_PATH_OUTLINER_H__
36 
37 #include "../CUPoly2.h"
38 #include "../CUVec2.h"
39 #include "CUSimpleTriangulator.h"
40 #include <vector>
41 
42 namespace cugl {
43 
49 enum class PathTraversal : int {
51  NONE = 0,
53  OPEN = 1,
55  CLOSED = 2,
57  INTERIOR = 3
58 };
59 
78 class PathOutliner {
79 #pragma mark Values
80 private:
82  std::vector<Vec2> _input;
84  std::vector<unsigned short> _output;
86  bool _calculated;
87 
89  SimpleTriangulator _triangulator;
90 
91 #pragma mark -
92 #pragma mark Constructors
93 public:
98 
107  PathOutliner(const std::vector<Vec2>& points) : _calculated(false) { _input = points; }
108 
120  PathOutliner(const Poly2& poly) : _calculated(false) { _input = poly._vertices; }
121 
126 
127 #pragma mark -
128 #pragma mark Initialization
129 
143  void set(const Poly2& poly) {
144  reset();
145  _input = poly._vertices;
146  }
147 
159  void set(const std::vector<Vec2>& points) {
160  reset();
161  _input = points;
162  }
166  void reset() {
167  _calculated = false;
168  _output.clear();
169  }
170 
177  void clear() {
178  _calculated = false;
179  _input.clear(); _output.clear();
180  }
181 
182 #pragma mark -
183 #pragma mark Calculation
184 
192  void calculate(PathTraversal traversal);
193 
194 #pragma mark -
195 #pragma mark Materialization
196 
210  std::vector<unsigned short> getPath();
211 
225  size_t getPath(std::vector<unsigned short>& buffer);
226 
239  Poly2 getPolygon();
240 
255  Poly2* getPolygon(Poly2* buffer);
256 };
257 }
258 
259 #endif /* __CU_PATH_OUTLINER_H__ */
void reset()
Definition: CUPathOutliner.h:166
~PathOutliner()
Definition: CUPathOutliner.h:125
void clear()
Definition: CUPathOutliner.h:177
Definition: CUSimpleTriangulator.h:66
Definition: CUPoly2.h:115
void set(const Poly2 &poly)
Definition: CUPathOutliner.h:143
void set(const std::vector< Vec2 > &points)
Definition: CUPathOutliner.h:159
PathOutliner()
Definition: CUPathOutliner.h:97
PathOutliner(const std::vector< Vec2 > &points)
Definition: CUPathOutliner.h:107
std::vector< unsigned short > getPath()
void calculate(PathTraversal traversal)
PathOutliner(const Poly2 &poly)
Definition: CUPathOutliner.h:120
PathTraversal
Definition: CUPathOutliner.h:49
Definition: CUPathOutliner.h:78
Definition: CUAnimationNode.h:52