Sound support + better cursor input handling
[numtypysics.git] / Path.h
blob5aa1c27c7245a540a45bda57448e41ada42899c5
1 /*
2 * This file is part of NumptyPhysics
3 * Copyright (C) 2008 Tim Edmonds
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
17 #ifndef PATH_H
18 #define PATH_H
20 #include "Common.h"
21 #include "Array.h"
24 class Segment
26 public:
27 Segment( const Vec2& p1, const Vec2& p2 )
28 : m_p1(p1), m_p2(p2) {}
29 float32 distanceTo( const Vec2& p );
30 private:
31 Vec2 m_p1, m_p2;
35 class Path : public Array<Vec2>
37 public:
38 Path();
39 Path( int n, Vec2* p );
40 Path( const char *ptlist );
42 void makeRelative();
43 Path& translate(const Vec2& xlate);
44 Path& rotate(const b2Mat22& rot);
45 Path& scale(float32 factor);
47 inline Vec2& origin() { return at(0); }
49 inline Path& operator&(const Vec2& other)
51 append(other);
52 return *this;
55 inline Path& operator&(const b2Vec2& other)
57 append(Vec2(other));
58 return *this;
61 inline Path operator+(const Vec2& p) const
63 Path r( *this );
64 return r.translate( p );
67 inline Path operator-(const Vec2& p) const
69 Path r( *this );
70 Vec2 n( -p.x, -p.y );
71 return r.translate( n );
74 inline Path operator*(const b2Mat22& m) const
76 Path r( *this );
77 return r.rotate( m );
80 inline Path& operator+=(const Vec2& p)
82 return translate( p );
85 inline Path& operator-=(const Vec2& p)
87 Vec2 n( -p.x, -p.y );
88 return translate( n );
91 inline int numPoints() const { return size(); }
92 inline const Vec2& point(int i) const { return at(i); }
93 inline Vec2& point(int i) { return at(i); }
94 inline Vec2& first() { return at(0); }
95 inline Vec2& last() { return at(size()-1); }
97 void simplify( float32 threshold );
98 Rect bbox() const;
100 private:
101 void simplifySub( int first, int last, float32 threshold, bool* keepflags );
104 #endif //PATH_H