InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PMBezierCurve.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: jargast
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __PMBezierCurve__
25 #define __PMBezierCurve__
26 
27 #include "PMPoint.h"
28 
29 class IPMStream;
30 class PMRect;
31 class PMBezierCurve;
32 class PMMatrix;
33 class PMPathPoint;
34 
36 
37 
41 {
42 public:
43  typedef base_type data_type;
46  PMBezierCurve();
47 
54  PMBezierCurve (const PMPoint& p0, const PMPoint& p1, const PMPoint& p2, const PMPoint& p3);
55 
60  PMBezierCurve (const PMPoint& p0p1, const PMPoint& p2p3);
61 
65  PMBezierCurve (const PMPoint& p);
66 
67  // Quick accesors
70  const PMPoint& GetP0() const { return fP0; }
73  const PMPoint& GetP1() const { return fP1; }
76  const PMPoint& GetP2() const { return fP2; }
79  const PMPoint& GetP3() const { return fP3; }
80 
84  const PMPoint& GetNthPoint (int32 n) const;
85 
86  // Quick ways to set the points.
90  void SetP0 (const PMPoint& p) { fP0 = p; }
94  void SetP1 (const PMPoint& p) { fP1 = p; }
98  void SetP2 (const PMPoint& p) { fP2 = p; }
102  void SetP3 (const PMPoint& p) { fP3 = p; }
103 
104  // Use index
109  void SetNthPoint (int32 n, const PMPoint& p);
110 
115  PMRect GetCtrlPtBounds() const;
116 
120  PMRect GetPathBounds() const;
121 
125  void TransformPoints (const PMMatrix& xForm);
126 
134  bool16 FindParameter (const PMPoint& p, const PMReal& hitzone, PMReal* retU) const;
135 
139  PMPoint Evaluate (const PMReal& u) const;
140 
144  PMPoint EvaluateSlope (const PMReal& u) const;
145 
148  void EvaluatePointAndSlope (const PMReal& u, PMPoint* outP, PMPoint* outSlope) const;
149 
153  int32 GetStepSize (const PMReal& flatness) const;
154 
159  void FlattenCurve (PMPoint* pts, int32 stepSize);
160 
167  int32 FindMinMax (PMReal* uResult) const;
168 
174  void SubDivide (const PMReal& u, PMBezierCurve* bezLeft, PMBezierCurve* bezRight) const;
175 
181  void SubSegment (const PMReal& begU, const PMReal& endU, PMBezierCurve* subSegment) const;
182 
186  (
187  const PMReal u,
188  PMPathPoint* ptBefore,
189  PMPathPoint* ptAt,
190  PMPathPoint* ptAfter
191  );
192 
193  // persistance
197  void ReadWrite (IPMStream* iPMStream);
198 
199  // Math Operators
200  friend PMBezierCurve operator *(const PMReal& c, const PMBezierCurve& pt);
201  friend PMBezierCurve operator /(const PMBezierCurve& numer, const PMReal& denom);
202 
203  // Assignment Operators
204  void operator *=(const PMReal& a);
205  void operator /=(const PMReal& a);
206  PMBezierCurve& operator=(const PMBezierCurve& rhs);
207 
208  // Comparison Operators
214  friend bool16 operator ==(const PMBezierCurve& a, const PMBezierCurve& b);
220  friend bool16 operator !=(const PMBezierCurve& a, const PMBezierCurve& b);
221 
222  // Utility methods
223 
227  static void Reduce (PMPoint* P, const PMPoint& A, const PMPoint& B, const PMReal& u);
228 
229 public:
230  PMReal PrivateFindParameter
231  (
232  const PMReal& startP,
233  const PMReal& endP,
234  const PMReal& coord,
235  bool16 isXCoord,
236  bool16* oneCrossing
237  ) const ;
238 
239  PMReal FindParameterByAverage
240  (
241  PMReal t0,
242  PMReal t1,
243  const PMPoint& p
244  ) const ;
245 
250  bool16 HitTest( const PMRect& r ) const ;
251 
254  int16 AdjustToPassThroughPoint( const PMPoint& p, const PMReal& t ) ;
255 
258  enum {
259  kBezierAdjustReflectedp1 = 1,
263  } ;
264 
267  bool16 PreAdjustCurve(
268  const PMReal& t, // input
269  PMPoint& t0, PMPoint& t3, // output
270  PMPoint& c, // output
271  PMPoint& d, PMPoint& e ) const ; // output
274  int16 DoAdjustCurve(
275  const PMPoint& m,
276  const PMReal& t,
277  const PMPoint& t0, const PMPoint& t3,
278  const PMPoint& c, const PMPoint& d, const PMPoint& e,
279  bool16 parallel ) ;
280 
281 protected:
282  PMPoint fP0;
283  PMPoint fP1;
284  PMPoint fP2;
285  PMPoint fP3;
286 };
287 
288 
289 
290 #endif