2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkPathMeasure_DEFINED
|
|
|
|
#define SkPathMeasure_DEFINED
|
|
|
|
|
2016-02-18 16:53:33 +00:00
|
|
|
#include "../private/SkTDArray.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
|
2014-12-17 16:21:04 +00:00
|
|
|
struct SkConic;
|
|
|
|
|
2013-05-08 13:25:02 +00:00
|
|
|
class SK_API SkPathMeasure : SkNoncopyable {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
|
|
|
SkPathMeasure();
|
|
|
|
/** Initialize the pathmeasure with the specified path. The path must remain valid
|
|
|
|
for the lifetime of the measure object, or until setPath() is called with
|
|
|
|
a different path (or null), since the measure object keeps a pointer to the
|
|
|
|
path object (does not copy its data).
|
2016-01-21 15:07:02 +00:00
|
|
|
|
|
|
|
resScale controls the precision of the measure. values > 1 increase the
|
|
|
|
precision (and possible slow down the computation).
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2016-01-21 15:07:02 +00:00
|
|
|
SkPathMeasure(const SkPath& path, bool forceClosed, SkScalar resScale = 1);
|
2008-12-17 15:59:43 +00:00
|
|
|
~SkPathMeasure();
|
|
|
|
|
|
|
|
/** Reset the pathmeasure with the specified path. The path must remain valid
|
|
|
|
for the lifetime of the measure object, or until setPath() is called with
|
|
|
|
a different path (or null), since the measure object keeps a pointer to the
|
|
|
|
path object (does not copy its data).
|
|
|
|
*/
|
2012-04-12 19:44:38 +00:00
|
|
|
void setPath(const SkPath*, bool forceClosed);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Return the total length of the current contour, or 0 if no path
|
|
|
|
is associated (e.g. resetPath(null))
|
|
|
|
*/
|
|
|
|
SkScalar getLength();
|
|
|
|
|
|
|
|
/** Pins distance to 0 <= distance <= getLength(), and then computes
|
|
|
|
the corresponding position and tangent.
|
|
|
|
Returns false if there is no path, or a zero-length path was specified, in which case
|
|
|
|
position and tangent are unchanged.
|
|
|
|
*/
|
2012-08-23 18:09:54 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT getPosTan(SkScalar distance, SkPoint* position,
|
2012-04-12 19:44:38 +00:00
|
|
|
SkVector* tangent);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
enum MatrixFlags {
|
|
|
|
kGetPosition_MatrixFlag = 0x01,
|
|
|
|
kGetTangent_MatrixFlag = 0x02,
|
|
|
|
kGetPosAndTan_MatrixFlag = kGetPosition_MatrixFlag | kGetTangent_MatrixFlag
|
|
|
|
};
|
2012-04-12 19:44:38 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Pins distance to 0 <= distance <= getLength(), and then computes
|
|
|
|
the corresponding matrix (by calling getPosTan).
|
|
|
|
Returns false if there is no path, or a zero-length path was specified, in which case
|
|
|
|
matrix is unchanged.
|
|
|
|
*/
|
2012-08-23 18:09:54 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT getMatrix(SkScalar distance, SkMatrix* matrix,
|
2012-04-12 19:44:38 +00:00
|
|
|
MatrixFlags flags = kGetPosAndTan_MatrixFlag);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Given a start and stop distance, return in dst the intervening segment(s).
|
|
|
|
If the segment is zero-length, return false, else return true.
|
2016-03-23 18:15:57 +00:00
|
|
|
startD and stopD are pinned to legal values (0..getLength()). If startD > stopD
|
2008-12-17 15:59:43 +00:00
|
|
|
then return false (and leave dst untouched).
|
|
|
|
Begin the segment with a moveTo if startWithMoveTo is true
|
|
|
|
*/
|
|
|
|
bool getSegment(SkScalar startD, SkScalar stopD, SkPath* dst, bool startWithMoveTo);
|
|
|
|
|
|
|
|
/** Return true if the current contour is closed()
|
|
|
|
*/
|
|
|
|
bool isClosed();
|
|
|
|
|
|
|
|
/** Move to the next contour in the path. Return true if one exists, or false if
|
|
|
|
we're done with the path.
|
|
|
|
*/
|
|
|
|
bool nextContour();
|
|
|
|
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
void dump();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkPath::Iter fIter;
|
|
|
|
const SkPath* fPath;
|
2016-01-21 15:07:02 +00:00
|
|
|
SkScalar fTolerance;
|
2008-12-17 15:59:43 +00:00
|
|
|
SkScalar fLength; // relative to the current contour
|
|
|
|
int fFirstPtIndex; // relative to the current contour
|
|
|
|
bool fIsClosed; // relative to the current contour
|
|
|
|
bool fForceClosed;
|
|
|
|
|
|
|
|
struct Segment {
|
|
|
|
SkScalar fDistance; // total distance up to this point
|
2015-12-18 15:03:13 +00:00
|
|
|
unsigned fPtIndex; // index into the fPts array
|
|
|
|
unsigned fTValue : 30;
|
2008-12-17 15:59:43 +00:00
|
|
|
unsigned fType : 2;
|
|
|
|
|
|
|
|
SkScalar getScalarT() const;
|
|
|
|
};
|
|
|
|
SkTDArray<Segment> fSegments;
|
2012-01-18 18:06:10 +00:00
|
|
|
SkTDArray<SkPoint> fPts; // Points used to define the segments
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
static const Segment* NextSegment(const Segment*);
|
|
|
|
|
|
|
|
void buildSegments();
|
|
|
|
SkScalar compute_quad_segs(const SkPoint pts[3], SkScalar distance,
|
|
|
|
int mint, int maxt, int ptIndex);
|
2016-01-19 16:07:49 +00:00
|
|
|
SkScalar compute_conic_segs(const SkConic&, SkScalar distance,
|
|
|
|
int mint, const SkPoint& minPt,
|
|
|
|
int maxt, const SkPoint& maxPt, int ptIndex);
|
2008-12-17 15:59:43 +00:00
|
|
|
SkScalar compute_cubic_segs(const SkPoint pts[3], SkScalar distance,
|
|
|
|
int mint, int maxt, int ptIndex);
|
|
|
|
const Segment* distanceToSegment(SkScalar distance, SkScalar* t);
|
2016-01-21 15:07:02 +00:00
|
|
|
bool quad_too_curvy(const SkPoint pts[3]);
|
|
|
|
bool conic_too_curvy(const SkPoint& firstPt, const SkPoint& midTPt,const SkPoint& lastPt);
|
|
|
|
bool cheap_dist_exceeds_limit(const SkPoint& pt, SkScalar x, SkScalar y);
|
|
|
|
bool cubic_too_curvy(const SkPoint pts[4]);
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|