Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkPathMeasure.h
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkPathMeasure_DEFINED
9 #define SkPathMeasure_DEFINED
10 
11 #include "../private/SkTDArray.h"
12 #include "SkPath.h"
13 
14 struct SkConic;
15 
16 class SK_API SkPathMeasure : SkNoncopyable {
17 public:
18  SkPathMeasure();
27  SkPathMeasure(const SkPath& path, bool forceClosed, SkScalar resScale = 1);
28  ~SkPathMeasure();
29 
35  void setPath(const SkPath*, bool forceClosed);
36 
40  SkScalar getLength();
41 
47  bool SK_WARN_UNUSED_RESULT getPosTan(SkScalar distance, SkPoint* position,
48  SkVector* tangent);
49 
50  enum MatrixFlags {
51  kGetPosition_MatrixFlag = 0x01,
52  kGetTangent_MatrixFlag = 0x02,
53  kGetPosAndTan_MatrixFlag = kGetPosition_MatrixFlag | kGetTangent_MatrixFlag
54  };
55 
61  bool SK_WARN_UNUSED_RESULT getMatrix(SkScalar distance, SkMatrix* matrix,
62  MatrixFlags flags = kGetPosAndTan_MatrixFlag);
63 
70  bool getSegment(SkScalar startD, SkScalar stopD, SkPath* dst, bool startWithMoveTo);
71 
74  bool isClosed();
75 
79  bool nextContour();
80 
81 #ifdef SK_DEBUG
82  void dump();
83 #endif
84 
85 private:
86  SkPath::Iter fIter;
87  const SkPath* fPath;
88  SkScalar fTolerance;
89  SkScalar fLength; // relative to the current contour
90  int fFirstPtIndex; // relative to the current contour
91  bool fIsClosed; // relative to the current contour
92  bool fForceClosed;
93 
94  struct Segment {
95  SkScalar fDistance; // total distance up to this point
96  unsigned fPtIndex; // index into the fPts array
97  unsigned fTValue : 30;
98  unsigned fType : 2; // actually the enum SkSegType
99  // See SkPathMeasurePriv.h
100 
101  SkScalar getScalarT() const;
102  };
103  SkTDArray<Segment> fSegments;
104  SkTDArray<SkPoint> fPts; // Points used to define the segments
105 
106  static const Segment* NextSegment(const Segment*);
107 
108  void buildSegments();
109  SkScalar compute_quad_segs(const SkPoint pts[3], SkScalar distance,
110  int mint, int maxt, int ptIndex);
111  SkScalar compute_conic_segs(const SkConic&, SkScalar distance,
112  int mint, const SkPoint& minPt,
113  int maxt, const SkPoint& maxPt, int ptIndex);
114  SkScalar compute_cubic_segs(const SkPoint pts[3], SkScalar distance,
115  int mint, int maxt, int ptIndex);
116  const Segment* distanceToSegment(SkScalar distance, SkScalar* t);
117  bool quad_too_curvy(const SkPoint pts[3]);
118  bool conic_too_curvy(const SkPoint& firstPt, const SkPoint& midTPt,const SkPoint& lastPt);
119  bool cheap_dist_exceeds_limit(const SkPoint& pt, SkScalar x, SkScalar y);
120  bool cubic_too_curvy(const SkPoint pts[4]);
121 };
122 
123 #endif
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:25
Definition: SkPoint.h:156
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:28
Definition: SkPathMeasure.h:94
Iterate through all of the segments (lines, quadratics, cubics) of each contours in a path...
Definition: SkPath.h:972
Definition: SkPathMeasure.h:16