Skia
2D Graphics Library
SkContourMeasure.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Google Inc.
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 SkContourMeasure_DEFINED
9 #define SkContourMeasure_DEFINED
10 
11 #include "include/core/SkPath.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/private/SkTDArray.h"
14 
15 struct SkConic;
16 
18 public:
21  SkScalar length() const { return fLength; }
22 
26  bool SK_WARN_UNUSED_RESULT getPosTan(SkScalar distance, SkPoint* position,
27  SkVector* tangent) const;
28 
29  enum MatrixFlags {
30  kGetPosition_MatrixFlag = 0x01,
31  kGetTangent_MatrixFlag = 0x02,
32  kGetPosAndTan_MatrixFlag = kGetPosition_MatrixFlag | kGetTangent_MatrixFlag
33  };
34 
41  MatrixFlags flags = kGetPosAndTan_MatrixFlag) const;
42 
50  bool startWithMoveTo) const;
51 
54  bool isClosed() const { return fIsClosed; }
55 
56 private:
57  struct Segment {
58  SkScalar fDistance; // total distance up to this point
59  unsigned fPtIndex; // index into the fPts array
60  unsigned fTValue : 30;
61  unsigned fType : 2; // actually the enum SkSegType
62  // See SkPathMeasurePriv.h
63 
64  SkScalar getScalarT() const;
65 
66  static const Segment* Next(const Segment* seg) {
67  unsigned ptIndex = seg->fPtIndex;
68  do {
69  ++seg;
70  } while (seg->fPtIndex == ptIndex);
71  return seg;
72  }
73 
74  };
75 
76  const SkTDArray<Segment> fSegments;
77  const SkTDArray<SkPoint> fPts; // Points used to define the segments
78 
79  const SkScalar fLength;
80  const bool fIsClosed;
81 
82  SkContourMeasure(SkTDArray<Segment>&& segs, SkTDArray<SkPoint>&& pts,
83  SkScalar length, bool isClosed);
84  ~SkContourMeasure() override {}
85 
86  const Segment* distanceToSegment(SkScalar distance, SkScalar* t) const;
87 
88  friend class SkContourMeasureIter;
89 };
90 
92 public:
102  SkContourMeasureIter(const SkPath& path, bool forceClosed, SkScalar resScale = 1);
104 
110  void reset(const SkPath& path, bool forceClosed, SkScalar resScale = 1);
111 
124 
125 private:
126  class Impl;
127 
128  std::unique_ptr<Impl> fImpl;
129 };
130 
131 #endif
SkContourMeasure::length
SkScalar length() const
Return the length of the contour.
Definition: SkContourMeasure.h:21
SkPath
Definition: SkPath.h:44
SkRefCnt
Definition: SkRefCnt.h:118
SkContourMeasureIter::SkContourMeasureIter
SkContourMeasureIter()
SkRefCnt.h
SkContourMeasureIter::SkContourMeasureIter
SkContourMeasureIter(const SkPath &path, bool forceClosed, SkScalar resScale=1)
Initialize the Iter with a path.
sk_sp< SkContourMeasure >
SkContourMeasure::getPosTan
bool SK_WARN_UNUSED_RESULT getPosTan(SkScalar distance, SkPoint *position, SkVector *tangent) const
Pins distance to 0 <= distance <= length(), and then computes the corresponding position and tangent.
SkPoint
Definition: SkPoint.h:160
SK_API
#define SK_API
Definition: SkTypes.h:181
SkContourMeasure::getSegment
bool SK_WARN_UNUSED_RESULT getSegment(SkScalar startD, SkScalar stopD, SkPath *dst, bool startWithMoveTo) const
Given a start and stop distance, return in dst the intervening segment(s).
SkContourMeasure
Definition: SkContourMeasure.h:17
SkContourMeasureIter::next
sk_sp< SkContourMeasure > next()
Iterates through contours in path, returning a contour-measure object for each contour in the path.
SkContourMeasureIter::~SkContourMeasureIter
~SkContourMeasureIter()
SkScalar
float SkScalar
Definition: SkScalar.h:16
SkPath.h
SkMatrix
Definition: SkMatrix.h:48
SK_WARN_UNUSED_RESULT
#define SK_WARN_UNUSED_RESULT
Definition: SkTypes.h:60
SkContourMeasure::getMatrix
bool SK_WARN_UNUSED_RESULT getMatrix(SkScalar distance, SkMatrix *matrix, MatrixFlags flags=kGetPosAndTan_MatrixFlag) const
Pins distance to 0 <= distance <= getLength(), and then computes the corresponding matrix (by calling...
SkContourMeasureIter
Definition: SkContourMeasure.h:91
SkContourMeasure::isClosed
bool isClosed() const
Return true if the contour is closed()
Definition: SkContourMeasure.h:54
SkContourMeasureIter::reset
void reset(const SkPath &path, bool forceClosed, SkScalar resScale=1)
Reset the Iter with a path.
SkContourMeasure::MatrixFlags
MatrixFlags
Definition: SkContourMeasure.h:29