1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
/*
* This file is part of NumptyPhysics
* Copyright (C) 2008 Tim Edmonds
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
*/
#ifndef PATH_H
#define PATH_H
#include "Common.h"
#include "Array.h"
class Segment
{
public:
Segment( const Vec2& p1, const Vec2& p2 )
: m_p1(p1), m_p2(p2) {}
float32 distanceTo( const Vec2& p );
private:
Vec2 m_p1, m_p2;
};
class Path : public Array<Vec2>
{
public:
Path();
Path( int n, Vec2* p );
Path( const char *ptlist );
void makeRelative();
Path& translate(const Vec2& xlate);
Path& rotate(const b2Mat22& rot);
Path& scale(float32 factor);
inline Vec2& origin() { return at(0); }
inline Path& operator&(const Vec2& other)
{
append(other);
return *this;
}
inline Path& operator&(const b2Vec2& other)
{
append(Vec2(other));
return *this;
}
inline Path operator+(const Vec2& p) const
{
Path r( *this );
return r.translate( p );
}
inline Path operator-(const Vec2& p) const
{
Path r( *this );
Vec2 n( -p.x, -p.y );
return r.translate( n );
}
inline Path operator*(const b2Mat22& m) const
{
Path r( *this );
return r.rotate( m );
}
inline Path& operator+=(const Vec2& p)
{
return translate( p );
}
inline Path& operator-=(const Vec2& p)
{
Vec2 n( -p.x, -p.y );
return translate( n );
}
inline int numPoints() const { return size(); }
inline const Vec2& point(int i) const { return at(i); }
inline Vec2& point(int i) { return at(i); }
inline Vec2& first() { return at(0); }
inline Vec2& last() { return at(size()-1); }
inline Vec2& endpt(unsigned char end) { return end?last():first(); }
void simplify( float32 threshold );
Rect bbox() const;
private:
void simplifySub( int first, int last, float32 threshold, bool* keepflags );
};
#endif //PATH_H
|