]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: geometry.h | |
3 | // Purpose: interface of geometry classes | |
4 | // Author: wxWidgets team | |
5 | // Licence: wxWindows licence | |
6 | ///////////////////////////////////////////////////////////////////////////// | |
7 | ||
8 | ||
9 | enum wxOutCode | |
10 | { | |
11 | wxInside = 0x00 , | |
12 | wxOutLeft = 0x01 , | |
13 | wxOutRight = 0x02 , | |
14 | wxOutTop = 0x08 , | |
15 | wxOutBottom = 0x04 | |
16 | }; | |
17 | ||
18 | ||
19 | class wxPoint2DInt | |
20 | { | |
21 | public : | |
22 | wxPoint2DInt(); | |
23 | wxPoint2DInt( wxInt32 x , wxInt32 y ); | |
24 | wxPoint2DInt( const wxPoint2DInt &pt ); | |
25 | wxPoint2DInt( const wxPoint &pt ); | |
26 | ||
27 | // noops for this class, just return the coords | |
28 | void GetFloor( wxInt32 *x , wxInt32 *y ) const; | |
29 | void GetRounded( wxInt32 *x , wxInt32 *y ) const; | |
30 | ||
31 | wxDouble GetVectorLength() const; | |
32 | wxDouble GetVectorAngle() const; | |
33 | void SetVectorLength( wxDouble length ); | |
34 | void SetVectorAngle( wxDouble degrees ); | |
35 | void SetPolarCoordinates( wxInt32 angle , wxInt32 length ); | |
36 | // set the vector length to 1.0, preserving the angle | |
37 | void Normalize(); | |
38 | ||
39 | wxDouble GetDistance( const wxPoint2DInt &pt ) const; | |
40 | wxDouble GetDistanceSquare( const wxPoint2DInt &pt ) const; | |
41 | wxInt32 GetDotProduct( const wxPoint2DInt &vec ) const; | |
42 | wxInt32 GetCrossProduct( const wxPoint2DInt &vec ) const; | |
43 | ||
44 | // the reflection of this point | |
45 | wxPoint2DInt operator-(); | |
46 | ||
47 | wxPoint2DInt& operator=(const wxPoint2DInt& pt); | |
48 | wxPoint2DInt& operator+=(const wxPoint2DInt& pt); | |
49 | wxPoint2DInt& operator-=(const wxPoint2DInt& pt); | |
50 | wxPoint2DInt& operator*=(const wxPoint2DInt& pt); | |
51 | wxPoint2DInt& operator*=(wxDouble n); | |
52 | wxPoint2DInt& operator*=(wxInt32 n); | |
53 | wxPoint2DInt& operator/=(const wxPoint2DInt& pt); | |
54 | wxPoint2DInt& operator/=(wxDouble n); | |
55 | wxPoint2DInt& operator/=(wxInt32 n); | |
56 | operator wxPoint() const; | |
57 | bool operator==(const wxPoint2DInt& pt) const; | |
58 | bool operator!=(const wxPoint2DInt& pt) const; | |
59 | ||
60 | wxInt32 m_x; | |
61 | wxInt32 m_y; | |
62 | }; | |
63 | ||
64 | wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2); | |
65 | wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2); | |
66 | wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2); | |
67 | wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt); | |
68 | wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt); | |
69 | wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n); | |
70 | wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n); | |
71 | wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2); | |
72 | wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n); | |
73 | wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n); | |
74 | ||
75 | ||
76 | // wxPoint2Ds represent a point or a vector in a 2d coordinate system | |
77 | ||
78 | class wxPoint2DDouble | |
79 | { | |
80 | public : | |
81 | wxPoint2DDouble(); | |
82 | wxPoint2DDouble( wxDouble x , wxDouble y ); | |
83 | wxPoint2DDouble( const wxPoint2DDouble &pt ); | |
84 | wxPoint2DDouble( const wxPoint2DInt &pt ); | |
85 | wxPoint2DDouble( const wxPoint &pt ); | |
86 | ||
87 | // two different conversions to integers, floor and rounding | |
88 | void GetFloor( wxInt32 *x , wxInt32 *y ) const; | |
89 | void GetRounded( wxInt32 *x , wxInt32 *y ) const; | |
90 | ||
91 | wxDouble GetVectorLength() const; | |
92 | wxDouble GetVectorAngle() const ; | |
93 | void SetVectorLength( wxDouble length ); | |
94 | void SetVectorAngle( wxDouble degrees ); | |
95 | void SetPolarCoordinates( wxDouble angle , wxDouble length ); | |
96 | // set the vector length to 1.0, preserving the angle | |
97 | void Normalize(); | |
98 | ||
99 | wxDouble GetDistance( const wxPoint2DDouble &pt ) const; | |
100 | wxDouble GetDistanceSquare( const wxPoint2DDouble &pt ) const; | |
101 | wxDouble GetDotProduct( const wxPoint2DDouble &vec ) const; | |
102 | wxDouble GetCrossProduct( const wxPoint2DDouble &vec ) const; | |
103 | ||
104 | // the reflection of this point | |
105 | wxPoint2DDouble operator-(); | |
106 | ||
107 | wxPoint2DDouble& operator=(const wxPoint2DDouble& pt); | |
108 | wxPoint2DDouble& operator+=(const wxPoint2DDouble& pt); | |
109 | wxPoint2DDouble& operator-=(const wxPoint2DDouble& pt); | |
110 | wxPoint2DDouble& operator*=(const wxPoint2DDouble& pt); | |
111 | wxPoint2DDouble& operator*=(wxDouble n); | |
112 | wxPoint2DDouble& operator*=(wxInt32 n); | |
113 | wxPoint2DDouble& operator/=(const wxPoint2DDouble& pt); | |
114 | wxPoint2DDouble& operator/=(wxDouble n); | |
115 | wxPoint2DDouble& operator/=(wxInt32 n); | |
116 | ||
117 | bool operator==(const wxPoint2DDouble& pt) const; | |
118 | bool operator!=(const wxPoint2DDouble& pt) const; | |
119 | ||
120 | wxDouble m_x; | |
121 | wxDouble m_y; | |
122 | }; | |
123 | ||
124 | wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2); | |
125 | wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2); | |
126 | wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2); | |
127 | wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt); | |
128 | wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt); | |
129 | wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n); | |
130 | wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n); | |
131 | wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2); | |
132 | wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n); | |
133 | wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n); | |
134 | ||
135 | ||
136 | ||
137 | // wxRect2Ds are a axis-aligned rectangles, each side of the rect is parallel to the x- or m_y- axis. The rectangle is either defined by the | |
138 | // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if | |
139 | // left <= x < right and top <= m_y < bottom , thus it is a half open interval. | |
140 | ||
141 | class wxRect2DDouble | |
142 | { | |
143 | public: | |
144 | wxRect2DDouble(); | |
145 | wxRect2DDouble(wxDouble x, wxDouble y, wxDouble w, wxDouble h); | |
146 | ||
147 | // single attribute accessors | |
148 | ||
149 | wxPoint2DDouble GetPosition() const; | |
150 | wxSize GetSize() const; | |
151 | ||
152 | // for the edge and corner accessors there are two setters counterparts, the Set.. functions keep the other corners at their | |
153 | // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners appropriately | |
154 | ||
155 | wxDouble GetLeft() const; | |
156 | void SetLeft( wxDouble n ); | |
157 | void MoveLeftTo( wxDouble n ); | |
158 | wxDouble GetTop() const; | |
159 | void SetTop( wxDouble n ); | |
160 | void MoveTopTo( wxDouble n ); | |
161 | wxDouble GetBottom() const; | |
162 | void SetBottom( wxDouble n ); | |
163 | void MoveBottomTo( wxDouble n ); | |
164 | wxDouble GetRight() const; | |
165 | void SetRight( wxDouble n ); | |
166 | void MoveRightTo( wxDouble n ); | |
167 | ||
168 | wxPoint2DDouble GetLeftTop() const; | |
169 | void SetLeftTop( const wxPoint2DDouble &pt ); | |
170 | void MoveLeftTopTo( const wxPoint2DDouble &pt ); | |
171 | wxPoint2DDouble GetLeftBottom() const; | |
172 | void SetLeftBottom( const wxPoint2DDouble &pt ); | |
173 | void MoveLeftBottomTo( const wxPoint2DDouble &pt ); | |
174 | wxPoint2DDouble GetRightTop() const; | |
175 | void SetRightTop( const wxPoint2DDouble &pt ); | |
176 | void MoveRightTopTo( const wxPoint2DDouble &pt ); | |
177 | wxPoint2DDouble GetRightBottom() const; | |
178 | void SetRightBottom( const wxPoint2DDouble &pt ); | |
179 | void MoveRightBottomTo( const wxPoint2DDouble &pt ); | |
180 | wxPoint2DDouble GetCentre() const; | |
181 | void SetCentre( const wxPoint2DDouble &pt ); | |
182 | void MoveCentreTo( const wxPoint2DDouble &pt ); | |
183 | wxOutCode GetOutCode( const wxPoint2DDouble &pt ) const; | |
184 | wxOutCode GetOutcode(const wxPoint2DDouble &pt) const; | |
185 | bool Contains( const wxPoint2DDouble &pt ) const; | |
186 | bool Contains( const wxRect2DDouble &rect ) const; | |
187 | bool IsEmpty() const; | |
188 | bool HaveEqualSize( const wxRect2DDouble &rect ) const; | |
189 | ||
190 | void Inset( wxDouble x , wxDouble y ); | |
191 | void Inset( wxDouble left , wxDouble top ,wxDouble right , wxDouble bottom ); | |
192 | void Offset( const wxPoint2DDouble &pt ); | |
193 | ||
194 | void ConstrainTo( const wxRect2DDouble &rect ); | |
195 | ||
196 | wxPoint2DDouble Interpolate( wxInt32 widthfactor , wxInt32 heightfactor ); | |
197 | ||
198 | static void Intersect( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest ); | |
199 | void Intersect( const wxRect2DDouble &otherRect ); | |
200 | wxRect2DDouble CreateIntersection( const wxRect2DDouble &otherRect ) const; | |
201 | bool Intersects( const wxRect2DDouble &rect ) const; | |
202 | ||
203 | static void Union( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest ); | |
204 | void Union( const wxRect2DDouble &otherRect ); | |
205 | void Union( const wxPoint2DDouble &pt ); | |
206 | wxRect2DDouble CreateUnion( const wxRect2DDouble &otherRect ) const; | |
207 | ||
208 | void Scale( wxDouble f ); | |
209 | void Scale( wxInt32 num , wxInt32 denum ); | |
210 | ||
211 | wxRect2DDouble& operator = (const wxRect2DDouble& rect); | |
212 | bool operator == (const wxRect2DDouble& rect) const; | |
213 | bool operator != (const wxRect2DDouble& rect) const; | |
214 | ||
215 | wxDouble m_x; | |
216 | wxDouble m_y; | |
217 | wxDouble m_width; | |
218 | wxDouble m_height; | |
219 | }; | |
220 | ||
221 | ||
222 | ||
223 | ||
224 | // wxRect2Ds are a axis-aligned rectangles, each side of the rect is parallel to the x- or m_y- axis. The rectangle is either defined by the | |
225 | // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if | |
226 | // left <= x < right and top <= m_y < bottom , thus it is a half open interval. | |
227 | ||
228 | class wxRect2DInt | |
229 | { | |
230 | public: | |
231 | wxRect2DInt(); | |
232 | wxRect2DInt( const wxRect& r ); | |
233 | wxRect2DInt(wxInt32 x, wxInt32 y, wxInt32 w, wxInt32 h); | |
234 | wxRect2DInt(const wxPoint2DInt& topLeft, const wxPoint2DInt& bottomRight); | |
235 | wxRect2DInt(const wxPoint2DInt& pos, const wxSize& size); | |
236 | wxRect2DInt(const wxRect2DInt& rect); | |
237 | ||
238 | // single attribute accessors | |
239 | ||
240 | wxPoint2DInt GetPosition() const; | |
241 | wxSize GetSize() const; | |
242 | ||
243 | // for the edge and corner accessors there are two setters counterparts, the Set.. functions keep the other corners at their | |
244 | // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners appropriately | |
245 | ||
246 | wxInt32 GetLeft() const; | |
247 | void SetLeft( wxInt32 n ); | |
248 | void MoveLeftTo( wxInt32 n ); | |
249 | wxInt32 GetTop() const; | |
250 | void SetTop( wxInt32 n ); | |
251 | void MoveTopTo( wxInt32 n ); | |
252 | wxInt32 GetBottom() const; | |
253 | void SetBottom( wxInt32 n ); | |
254 | void MoveBottomTo( wxInt32 n ); | |
255 | wxInt32 GetRight() const; | |
256 | void SetRight( wxInt32 n ); | |
257 | void MoveRightTo( wxInt32 n ); | |
258 | ||
259 | wxPoint2DInt GetLeftTop() const; | |
260 | void SetLeftTop( const wxPoint2DInt &pt ) ; | |
261 | void MoveLeftTopTo( const wxPoint2DInt &pt ) ; | |
262 | wxPoint2DInt GetLeftBottom() const ; | |
263 | void SetLeftBottom( const wxPoint2DInt &pt ) ; | |
264 | void MoveLeftBottomTo( const wxPoint2DInt &pt ) ; | |
265 | wxPoint2DInt GetRightTop() const ; | |
266 | void SetRightTop( const wxPoint2DInt &pt ) ; | |
267 | void MoveRightTopTo( const wxPoint2DInt &pt ) ; | |
268 | wxPoint2DInt GetRightBottom() const ; | |
269 | void SetRightBottom( const wxPoint2DInt &pt ) ; | |
270 | void MoveRightBottomTo( const wxPoint2DInt &pt ) ; | |
271 | wxPoint2DInt GetCentre() const ; | |
272 | void SetCentre( const wxPoint2DInt &pt ) ; | |
273 | void MoveCentreTo( const wxPoint2DInt &pt ) ; | |
274 | wxOutCode GetOutCode( const wxPoint2DInt &pt ) const; | |
275 | wxOutCode GetOutcode( const wxPoint2DInt &pt ) const; | |
276 | bool Contains( const wxPoint2DInt &pt ) const; | |
277 | bool Contains( const wxRect2DInt &rect ) const; | |
278 | bool IsEmpty() const; | |
279 | bool HaveEqualSize( const wxRect2DInt &rect ) const; | |
280 | ||
281 | void Inset( wxInt32 x , wxInt32 y ); | |
282 | void Inset( wxInt32 left , wxInt32 top ,wxInt32 right , wxInt32 bottom ); | |
283 | void Offset( const wxPoint2DInt &pt ); | |
284 | void ConstrainTo( const wxRect2DInt &rect ); | |
285 | wxPoint2DInt Interpolate( wxInt32 widthfactor , wxInt32 heightfactor ); | |
286 | ||
287 | static void Intersect( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest ); | |
288 | void Intersect( const wxRect2DInt &otherRect ); | |
289 | wxRect2DInt CreateIntersection( const wxRect2DInt &otherRect ) const; | |
290 | bool Intersects( const wxRect2DInt &rect ) const; | |
291 | ||
292 | static void Union( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest ); | |
293 | void Union( const wxRect2DInt &otherRect ); | |
294 | void Union( const wxPoint2DInt &pt ); | |
295 | wxRect2DInt CreateUnion( const wxRect2DInt &otherRect ) const; | |
296 | ||
297 | void Scale( wxInt32 f ); | |
298 | void Scale( wxInt32 num , wxInt32 denum ); | |
299 | ||
300 | wxRect2DInt& operator = (const wxRect2DInt& rect); | |
301 | bool operator == (const wxRect2DInt& rect) const; | |
302 | bool operator != (const wxRect2DInt& rect) const; | |
303 | ||
304 | ||
305 | wxInt32 m_x; | |
306 | wxInt32 m_y; | |
307 | wxInt32 m_width; | |
308 | wxInt32 m_height; | |
309 | }; | |
310 | ||
311 | ||
312 | ||
313 | ||
314 | ||
315 | class wxTransform2D | |
316 | { | |
317 | public : | |
318 | virtual ~wxTransform2D(); | |
319 | virtual void Transform( wxPoint2DInt* pt )const = 0; | |
320 | virtual void Transform( wxRect2DInt* r ) const; | |
321 | virtual wxPoint2DInt Transform( const wxPoint2DInt &pt ) const; | |
322 | virtual wxRect2DInt Transform( const wxRect2DInt &r ) const ; | |
323 | ||
324 | virtual void InverseTransform( wxPoint2DInt* pt ) const = 0; | |
325 | virtual void InverseTransform( wxRect2DInt* r ) const ; | |
326 | virtual wxPoint2DInt InverseTransform( const wxPoint2DInt &pt ) const ; | |
327 | virtual wxRect2DInt InverseTransform( const wxRect2DInt &r ) const ; | |
328 | }; | |
329 | ||
330 |