Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Classes | Public Types | Public Member Functions | Friends | List of all members
SkContourMeasure Class Reference

#include <SkContourMeasure.h>

Inheritance diagram for SkContourMeasure:
SkRefCnt SkRefCntBase

Public Types

enum  MatrixFlags { kGetPosition_MatrixFlag = 0x01 , kGetTangent_MatrixFlag = 0x02 , kGetPosAndTan_MatrixFlag = kGetPosition_MatrixFlag | kGetTangent_MatrixFlag }
 

Public Member Functions

SkScalar length () const
 
bool getPosTan (SkScalar distance, SkPoint *position, SkVector *tangent) const
 
bool getMatrix (SkScalar distance, SkMatrix *matrix, MatrixFlags flags=kGetPosAndTan_MatrixFlag) const
 
bool getSegment (SkScalar startD, SkScalar stopD, SkPath *dst, bool startWithMoveTo) const
 
bool isClosed () const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Friends

class SkContourMeasureIter
 
class SkPathMeasurePriv
 

Detailed Description

Definition at line 22 of file SkContourMeasure.h.

Member Enumeration Documentation

◆ MatrixFlags

Enumerator
kGetPosition_MatrixFlag 
kGetTangent_MatrixFlag 
kGetPosAndTan_MatrixFlag 

Definition at line 33 of file SkContourMeasure.h.

Member Function Documentation

◆ getMatrix()

bool SkContourMeasure::getMatrix ( SkScalar  distance,
SkMatrix matrix,
MatrixFlags  flags = kGetPosAndTan_MatrixFlag 
) const

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.

Definition at line 633 of file SkContourMeasure.cpp.

633 {
634 SkPoint position;
635 SkVector tangent;
636
637 if (this->getPosTan(distance, &position, &tangent)) {
638 if (matrix) {
640 matrix->setSinCos(tangent.fY, tangent.fX, 0, 0);
641 } else {
642 matrix->reset();
643 }
645 matrix->postTranslate(position.fX, position.fY);
646 }
647 }
648 return true;
649 }
650 return false;
651}
bool getPosTan(SkScalar distance, SkPoint *position, SkVector *tangent) const
FlutterSemanticsFlag flags
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ getPosTan()

bool SkContourMeasure::getPosTan ( SkScalar  distance,
SkPoint position,
SkVector tangent 
) const

Pins distance to 0 <= distance <= length(), and then computes the corresponding position and tangent.

Definition at line 607 of file SkContourMeasure.cpp.

607 {
608 if (SkIsNaN(distance)) {
609 return false;
610 }
611
612 const SkScalar length = this->length();
613 SkASSERT(length > 0 && !fSegments.empty());
614
615 // pin the distance to a legal range
616 if (distance < 0) {
617 distance = 0;
618 } else if (distance > length) {
620 }
621
622 SkScalar t;
623 const Segment* seg = this->distanceToSegment(distance, &t);
624 if (SkIsNaN(t)) {
625 return false;
626 }
627
628 SkASSERT((unsigned)seg->fPtIndex < (unsigned)fPts.size());
629 compute_pos_tan(&fPts[seg->fPtIndex], seg->fType, t, pos, tangent);
630 return true;
631}
SkPoint pos
#define SkASSERT(cond)
Definition: SkAssert.h:116
static void compute_pos_tan(const SkPoint pts[], unsigned segType, SkScalar t, SkPoint *pos, SkVector *tangent)
static constexpr bool SkIsNaN(T x)
SkScalar length() const
int size() const
Definition: SkTDArray.h:138
float SkScalar
Definition: extension.cpp:12

◆ getSegment()

bool SkContourMeasure::getSegment ( SkScalar  startD,
SkScalar  stopD,
SkPath dst,
bool  startWithMoveTo 
) const

Given a start and stop distance, return in dst the intervening segment(s). If the segment is zero-length, return false, else return true. startD and stopD are pinned to legal values (0..getLength()). If startD > stopD then return false (and leave dst untouched). Begin the segment with a moveTo if startWithMoveTo is true

Definition at line 653 of file SkContourMeasure.cpp.

654 {
655 SkASSERT(dst);
656
657 SkScalar length = this->length(); // ensure we have built our segments
658
659 if (startD < 0) {
660 startD = 0;
661 }
662 if (stopD > length) {
663 stopD = length;
664 }
665 if (!(startD <= stopD)) { // catch NaN values as well
666 return false;
667 }
668 if (fSegments.empty()) {
669 return false;
670 }
671
672 SkPoint p;
673 SkScalar startT, stopT;
674 const Segment* seg = this->distanceToSegment(startD, &startT);
675 if (!SkIsFinite(startT)) {
676 return false;
677 }
678 const Segment* stopSeg = this->distanceToSegment(stopD, &stopT);
679 if (!SkIsFinite(stopT)) {
680 return false;
681 }
682 SkASSERT(seg <= stopSeg);
683 if (startWithMoveTo) {
684 compute_pos_tan(&fPts[seg->fPtIndex], seg->fType, startT, &p, nullptr);
685 dst->moveTo(p);
686 }
687
688 if (seg->fPtIndex == stopSeg->fPtIndex) {
689 SkContourMeasure_segTo(&fPts[seg->fPtIndex], seg->fType, startT, stopT, dst);
690 } else {
691 do {
692 SkContourMeasure_segTo(&fPts[seg->fPtIndex], seg->fType, startT, SK_Scalar1, dst);
693 seg = SkContourMeasure::Segment::Next(seg);
694 startT = 0;
695 } while (seg->fPtIndex < stopSeg->fPtIndex);
696 SkContourMeasure_segTo(&fPts[seg->fPtIndex], seg->fType, 0, stopT, dst);
697 }
698
699 return true;
700}
void SkContourMeasure_segTo(const SkPoint pts[], unsigned segType, SkScalar startT, SkScalar stopT, SkPath *dst)
static bool SkIsFinite(T x, Pack... values)
#define SK_Scalar1
Definition: SkScalar.h:18
dst
Definition: cp.py:12

◆ isClosed()

bool SkContourMeasure::isClosed ( ) const
inline

Return true if the contour is closed()

Definition at line 58 of file SkContourMeasure.h.

58{ return fIsClosed; }

◆ length()

SkScalar SkContourMeasure::length ( ) const
inline

Return the length of the contour.

Definition at line 26 of file SkContourMeasure.h.

26{ return fLength; }

Friends And Related Function Documentation

◆ SkContourMeasureIter

friend class SkContourMeasureIter
friend

Definition at line 92 of file SkContourMeasure.h.

◆ SkPathMeasurePriv

friend class SkPathMeasurePriv
friend

Definition at line 93 of file SkContourMeasure.h.


The documentation for this class was generated from the following files: