Mobile API Reference  MicroStrategy 2019
BezierCurve.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : BezierCurve.h
3 // AUTHOR : Liang Liu
4 // CREATION : 2009-01-04
5 // Copyright (C) MicroStrategy Incorporated 2009
6 // All Rights Reserved
7 //==============================================================================================
8 
9 #ifndef MsiChart_BezierCurve_h
10 #define MsiChart_BezierCurve_h
11 
12 #include "Rect2D.h"
13 #include "Synch/Defines/SmartPtr.h"
14 
15 struct _cairo;
16 typedef struct _cairo cairo_t;
17 
18 namespace MsiChart
19 {
20 #ifdef _VE_CE
21  class ChartContext;
22 #endif
23 
30  {
31  public:
41  BezierCurve(const FPoint2D& irP0, float iP1, float iP2, const FPoint2D& irP3,
42  bool iIsVertical, bool iIsXAlwaysIndependent = false);
43 
49  virtual void GetApproximatePolygon(Int32 iLineWidth, std::vector<Point2D>& orPolygon) const;
50 
56  void GetApproximatePolyline(std::vector<Point2D>& orPolyline) const;
57 
61  void Reverse();
62 
63 #ifdef _VE_CE
64 
72  void MoveToStart(ChartContext* ipContext, bool iTuning = false) const;
81  void CurveToEnd(ChartContext* ipContext, bool iTuning = false) const;
90  void LineToStart(ChartContext* ipContext, bool iTuning = false) const;
91 #else
92 
100  void MoveToStart(CGPath* ipCGPath, bool iTuning = false) const;
109  void CurveToEnd(CGPath* ipCGPath, bool iTuning = false) const;
118  void LineToStart(CGPath* ipCGPath, bool iTuning = false) const;
119 #endif
120 
125  FPoint2D GetStartPoint() const;
126 
131  FPoint2D GetEndPoint() const;
132 
138  double Evaluate(double iIndependentValue) const;
144  double EvaluateDerivative(double iIndependentValue) const;
145 
151  double Evaluate2ndDerivative(double iIndependentValue) const;
152 
157  double Evaluate3rdDerivative() const;
158 
163  float GetStartIndependent() const;
168  float GetEndIndependent() const;
169 
175  void GetMinMax(Int32& orMinY, Int32& orMaxY) const;
176 
181  float GetMinX() const;
186  float GetMaxX() const;
187 
192  BezierCurve::Ptr Clone() const;
193 
198  BezierCurve::Ptr CloneReverseShift(const Point2D& irOffset) const;
199 
204  bool IsVertical() const;
205 
213  bool IsBefore(const Point2D& irOffset, BezierCurve::Ptr iBezierCurvePtr) const;
221  void SplitAtTangentPoints(const Point2D& irOffset, std::vector<BezierCurve::Ptr>& orSplitCurves);
229  void SplitAtIntersections(BezierCurve::Ptr iBezierCurvePtr, std::vector<BezierCurve::Ptr>& orSplitCurves);
230 
231  protected:
235  BezierCurve(const FPoint2D& irP0, const FPoint2D& irP1, const FPoint2D& irP2, const FPoint2D& irP3);
236 
241  private:
247  BezierCurve::Ptr hSplit(double iTao);
248 
254  void hSolveQuadraticEquation(double iA, double iB, double iC, std::vector<double>& orPositiveRoots) const;
255 
261  void hSolveCubicEquation(double iA, double iB, double iC, double iD, std::vector<double>& orPositiveRoots) const;
262 
268  double hEvaluate(double iS) const;
269 
275  double hEvaluateDerivative(double iS) const;
276 
282  void hGetTangentPositions(double iSlope, std::vector<double>& orPositions) const;
283 
291  void hSplitAtPositions(std::vector<double>& iorPositions, std::vector<BezierCurve::Ptr>& orSplitCurves);
292 
298  void hGetIntersections(const BezierCurve* ipBezierCurve, std::vector<double>& orIntersections) const;
299 
306  BezierCurve::Ptr hGetSubCurve(float iValueX, bool iIsRightPart) const;
307 
313  void hMakeXAscending();
314 
320  float hGetTaoFromX(float iValueX) const;
321 
327  void hMakeDeltaBezier(BezierCurve::Ptr iBezierCurvePtr);
328 
334  void hGetXRoots(std::vector<double>& orXRoots) const;
335 
342  bool hHasIntersection(const FPoint2D& irStart, const FPoint2D& irEnd) const;
343 
349  double hCubicRoot(double iValue) const;
350 
355  bool hHaveSameY() const;
356 
357  bool mIsVertical;
358  };
359 
361  {
362  return mIsVertical ? mP0 : FPoint2D(mP0.y, mP0.x);
363  }
364 
366  {
367  return mIsVertical ? mP3 : FPoint2D(mP3.y, mP3.x);
368  }
369 
370  inline bool BezierCurve::IsVertical() const
371  {
372  return mIsVertical;
373  }
374 
375  inline float BezierCurve::GetMinX() const
376  {
377  return mP0.x < mP3.x ? mP0.x : mP3.x;
378  }
379 
380  inline float BezierCurve::GetMaxX() const
381  {
382  return mP0.x < mP3.x ? mP3.x : mP0.x;
383  }
384  inline float BezierCurve::hGetTaoFromX(float iValueX) const
385  {
386  return (iValueX - mP0.x) / (mP3.x - mP0.x);
387  }
388 
389  inline float BezierCurve::GetStartIndependent() const
390  {
391  return mP0.x;
392  }
393 
394  inline float BezierCurve::GetEndIndependent() const
395  {
396  return mP3.x;
397  }
398 
399  inline bool BezierCurve::hHaveSameY() const
400  {
401  return mP0.y == mP1.y && mP1.y == mP2.y && mP2.y == mP3.y;
402  }
403 }
404 
405 #endif
float GetEndIndependent() const
Definition: BezierCurve.h:394
void SplitAtIntersections(BezierCurve::Ptr iBezierCurvePtr, std::vector< BezierCurve::Ptr > &orSplitCurves)
Point< float > FPoint2D
Definition: Point2D.h:403
void GetMinMax(Int32 &orMinY, Int32 &orMaxY) const
double Evaluate2ndDerivative(double iIndependentValue) const
double EvaluateDerivative(double iIndependentValue) const
FPoint2D GetEndPoint() const
Definition: BezierCurve.h:365
BezierCurve::Ptr CloneReverseShift(const Point2D &irOffset) const
void MoveToStart(CGPath *ipCGPath, bool iTuning=false) const
T y
Y-coordinate of current point.
Definition: Point2D.h:175
bool IsBefore(const Point2D &irOffset, BezierCurve::Ptr iBezierCurvePtr) const
void LineToStart(CGPath *ipCGPath, bool iTuning=false) const
struct _cairo cairo_t
Definition: BezierCurve.h:16
void CurveToEnd(CGPath *ipCGPath, bool iTuning=false) const
#define Int32
Definition: BasicTypes.h:20
float GetStartIndependent() const
Definition: BezierCurve.h:389
T x
X-coordinate of current point.
Definition: Point2D.h:174
BezierCurve(const FPoint2D &irP0, float iP1, float iP2, const FPoint2D &irP3, bool iIsVertical, bool iIsXAlwaysIndependent=false)
void GetApproximatePolyline(std::vector< Point2D > &orPolyline) const
double Evaluate(double iIndependentValue) const
FPoint2D GetStartPoint() const
Definition: BezierCurve.h:360
Definition: SmartPtr.h:38
BezierCurve::Ptr Clone() const
FPoint2D mP2
Definition: BezierCurve.h:239
Definition: ChartContext.h:542
float GetMaxX() const
Definition: BezierCurve.h:380
FPoint2D mP3
Definition: BezierCurve.h:240
double Evaluate3rdDerivative() const
Definition: ABLPlot.h:21
void SplitAtTangentPoints(const Point2D &irOffset, std::vector< BezierCurve::Ptr > &orSplitCurves)
Definition: BezierCurve.h:29
FPoint2D mP1
Definition: BezierCurve.h:238
float GetMinX() const
Definition: BezierCurve.h:375
FPoint2D mP0
Definition: BezierCurve.h:237
MSynch::SmartPtr< BezierCurve > Ptr
Definition: BezierCurve.h:32
bool IsVertical() const
Definition: BezierCurve.h:370
virtual void GetApproximatePolygon(Int32 iLineWidth, std::vector< Point2D > &orPolygon) const