Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #pragma once
00024
00025 #include "cinder/Vector.h"
00026 #include <vector>
00027
00028 namespace cinder {
00029
00030 template<typename T>
00031 class PolyLine {
00032 public:
00033 PolyLine() : mClosed( false ) {}
00034 PolyLine( const std::vector<T> &aPoints ) : mPoints( aPoints ), mClosed( false ) {}
00035
00036 const std::vector<T>& getPoints() const { return mPoints; }
00037 std::vector<T>& getPoints() { return mPoints; }
00038
00039
00040 typedef typename std::vector<T>::const_iterator const_iterator;
00041 typedef typename std::vector<T>::iterator iterator;
00042
00043 size_t size() const { return mPoints.size(); }
00044
00045 void push_back( const T &v ) { mPoints.push_back( v ); }
00046 iterator begin() { return mPoints.begin(); }
00047 const_iterator begin() const { return mPoints.begin(); }
00048 iterator end() { return mPoints.end(); }
00049 const_iterator end() const { return mPoints.end(); }
00050
00051 void setClosed( bool aClosed = true ) { mClosed = aClosed; }
00052 bool isClosed() const { return mClosed; }
00053
00054 T getPosition( float t ) const;
00055 T getDerivative( float t ) const;
00056
00057 void scale( const T &scaleFactor, T scaleCenter = T::zero() );
00058 void offset( const T &offsetBy );
00059
00061 bool contains( const Vec2f &pt ) const;
00062
00064 static std::vector<PolyLine> calcUnion( const std::vector<PolyLine> &a, std::vector<PolyLine> &b );
00066 static std::vector<PolyLine> calcIntersection( const std::vector<PolyLine> &a, std::vector<PolyLine> &b );
00068 static std::vector<PolyLine> calcXor( const std::vector<PolyLine> &a, std::vector<PolyLine> &b );
00070 static std::vector<PolyLine> calcDifference( const std::vector<PolyLine> &a, std::vector<PolyLine> &b );
00071
00072 private:
00073 std::vector<T> mPoints;
00074 bool mClosed;
00075 };
00076
00077 typedef PolyLine<Vec2f> PolyLine2f;
00078 typedef PolyLine<Vec2d> PolyLine2d;
00079
00080 }