Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PolyLine.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Barbarian Group
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 
23 #pragma once
24 
25 #include "cinder/Vector.h"
26 #include <vector>
27 
28 namespace cinder {
29 
30 template<typename T>
31 class PolyLine {
32  public:
33  PolyLine() : mClosed( false ) {}
34  PolyLine( const std::vector<T> &aPoints ) : mPoints( aPoints ), mClosed( false ) {}
35 
36  const std::vector<T>& getPoints() const { return mPoints; }
37  std::vector<T>& getPoints() { return mPoints; }
38 
39  // STL-like convenience functions for iterating points
40  typedef typename std::vector<T>::const_iterator const_iterator;
41  typedef typename std::vector<T>::iterator iterator;
42 
43  size_t size() const { return mPoints.size(); }
44 
45  void push_back( const T &v ) { mPoints.push_back( v ); }
46  iterator begin() { return mPoints.begin(); }
47  const_iterator begin() const { return mPoints.begin(); }
48  iterator end() { return mPoints.end(); }
49  const_iterator end() const { return mPoints.end(); }
50 
51  void setClosed( bool aClosed = true ) { mClosed = aClosed; }
52  bool isClosed() const { return mClosed; }
53 
54  T getPosition( float t ) const;
55  T getDerivative( float t ) const;
56 
57  void scale( const T &scaleFactor, T scaleCenter = T::zero() );
58  void offset( const T &offsetBy );
59 
61  bool contains( const Vec2f &pt ) const;
62 
64  static std::vector<PolyLine> calcUnion( const std::vector<PolyLine> &a, std::vector<PolyLine> &b );
66  static std::vector<PolyLine> calcIntersection( const std::vector<PolyLine> &a, std::vector<PolyLine> &b );
68  static std::vector<PolyLine> calcXor( const std::vector<PolyLine> &a, std::vector<PolyLine> &b );
70  static std::vector<PolyLine> calcDifference( const std::vector<PolyLine> &a, std::vector<PolyLine> &b );
71 
72  private:
73  std::vector<T> mPoints;
74  bool mClosed;
75 };
76 
79 
80 } // namespace cinder
T getPosition(float t) const
Definition: PolyLine.cpp:33
iterator begin()
Definition: PolyLine.h:46
PolyLine< Vec2f > PolyLine2f
Definition: PolyLine.h:77
const_iterator end() const
Definition: PolyLine.h:49
iterator end()
Definition: PolyLine.h:48
std::vector< T >::iterator iterator
Definition: PolyLine.h:41
bool isClosed() const
Definition: PolyLine.h:52
const_iterator begin() const
Definition: PolyLine.h:47
static std::vector< PolyLine > calcXor(const std::vector< PolyLine > &a, std::vector< PolyLine > &b)
Calculates the boolean XOR (symmetric difference) of a and b. Assumes the first PolyLine in the vecto...
Definition: PolyLine.cpp:196
PolyLine()
Definition: PolyLine.h:33
T getDerivative(float t) const
Definition: PolyLine.cpp:47
PolyLine< Vec2d > PolyLine2d
Definition: PolyLine.h:78
std::vector< T >::const_iterator const_iterator
Definition: PolyLine.h:40
size_t size() const
Definition: PolyLine.h:43
bool contains(const Vec2f &pt) const
Returns whether the point pt is contained within the boundaries of the PolyLine.
Definition: PolyLine.cpp:92
const GLdouble * v
Definition: GLee.h:1384
GLboolean GLboolean GLboolean b
Definition: GLee.h:2964
const std::vector< T > & getPoints() const
Definition: PolyLine.h:36
void push_back(const T &v)
Definition: PolyLine.h:45
std::vector< T > & getPoints()
Definition: PolyLine.h:37
GLboolean GLboolean GLboolean GLboolean a
Definition: GLee.h:2964
static std::vector< PolyLine > calcIntersection(const std::vector< PolyLine > &a, std::vector< PolyLine > &b)
Calculates the boolean intersection of a and b. Assumes the first PolyLine in the vector is the outer...
Definition: PolyLine.cpp:177
static std::vector< PolyLine > calcUnion(const std::vector< PolyLine > &a, std::vector< PolyLine > &b)
Calculates the boolean union of a and b. Assumes the first PolyLine in the vector is the outermost an...
Definition: PolyLine.cpp:158
void setClosed(bool aClosed=true)
Definition: PolyLine.h:51
void scale(const T &scaleFactor, T scaleCenter=T::zero())
Definition: PolyLine.cpp:60
Definition: PolyLine.h:31
void offset(const T &offsetBy)
Definition: PolyLine.cpp:67
GLdouble GLdouble t
Definition: GLee.h:1426
PolyLine(const std::vector< T > &aPoints)
Definition: PolyLine.h:34
static std::vector< PolyLine > calcDifference(const std::vector< PolyLine > &a, std::vector< PolyLine > &b)
Calculates the boolean difference of a and b. Assumes the first PolyLine in the vector is the outermo...
Definition: PolyLine.cpp:215