Flutter Engine
The Flutter Engine
Public Types | Static Public Member Functions | List of all members
SkPointPriv Class Reference

#include <SkPointPriv.h>

Public Types

enum  Side { kLeft_Side = -1 , kOn_Side = 0 , kRight_Side = 1 }
 

Static Public Member Functions

static bool AreFinite (const SkPoint array[], int count)
 
static const SkScalarAsScalars (const SkPoint &pt)
 
static bool CanNormalize (SkScalar dx, SkScalar dy)
 
static SkScalar DistanceToLineBetweenSqd (const SkPoint &pt, const SkPoint &a, const SkPoint &b, Side *side=nullptr)
 
static SkScalar DistanceToLineBetween (const SkPoint &pt, const SkPoint &a, const SkPoint &b, Side *side=nullptr)
 
static SkScalar DistanceToLineSegmentBetweenSqd (const SkPoint &pt, const SkPoint &a, const SkPoint &b)
 
static SkScalar DistanceToLineSegmentBetween (const SkPoint &pt, const SkPoint &a, const SkPoint &b)
 
static SkScalar DistanceToSqd (const SkPoint &pt, const SkPoint &a)
 
static bool EqualsWithinTolerance (const SkPoint &p1, const SkPoint &p2)
 
static bool EqualsWithinTolerance (const SkPoint &pt, const SkPoint &p, SkScalar tol)
 
static SkScalar LengthSqd (const SkPoint &pt)
 
static void Negate (SkIPoint &pt)
 
static void RotateCCW (const SkPoint &src, SkPoint *dst)
 
static void RotateCCW (SkPoint *pt)
 
static void RotateCW (const SkPoint &src, SkPoint *dst)
 
static void RotateCW (SkPoint *pt)
 
static bool SetLengthFast (SkPoint *pt, float length)
 
static SkPoint MakeOrthog (const SkPoint &vec, Side side=kLeft_Side)
 
static void SetRectFan (SkPoint v[], SkScalar l, SkScalar t, SkScalar r, SkScalar b, size_t stride)
 
static void SetRectTriStrip (SkPoint v[], SkScalar l, SkScalar t, SkScalar r, SkScalar b, size_t stride)
 
static void SetRectTriStrip (SkPoint v[], const SkRect &rect, size_t stride)
 

Detailed Description

Definition at line 14 of file SkPointPriv.h.

Member Enumeration Documentation

◆ Side

Enumerator
kLeft_Side 
kOn_Side 
kRight_Side 

Definition at line 16 of file SkPointPriv.h.

16 {
17 kLeft_Side = -1,
18 kOn_Side = 0,
19 kRight_Side = 1,
20 };

Member Function Documentation

◆ AreFinite()

static bool SkPointPriv::AreFinite ( const SkPoint  array[],
int  count 
)
inlinestatic

Definition at line 22 of file SkPointPriv.h.

22 {
23 return SkIsFinite(&array[0].fX, count << 1);
24 }
int count
Definition: FontMgrTest.cpp:50
static bool SkIsFinite(T x, Pack... values)

◆ AsScalars()

static const SkScalar * SkPointPriv::AsScalars ( const SkPoint pt)
inlinestatic

Definition at line 26 of file SkPointPriv.h.

26{ return &pt.fX; }
float fX
x-axis value
Definition: SkPoint_impl.h:164

◆ CanNormalize()

static bool SkPointPriv::CanNormalize ( SkScalar  dx,
SkScalar  dy 
)
inlinestatic

Definition at line 28 of file SkPointPriv.h.

28 {
29 return SkIsFinite(dx, dy) && (dx || dy);
30 }
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208

◆ DistanceToLineBetween()

static SkScalar SkPointPriv::DistanceToLineBetween ( const SkPoint pt,
const SkPoint a,
const SkPoint b,
Side side = nullptr 
)
inlinestatic

Definition at line 35 of file SkPointPriv.h.

36 {
38 }
static int side(double x)
#define SkScalarSqrt(x)
Definition: SkScalar.h:42
static SkScalar DistanceToLineBetweenSqd(const SkPoint &pt, const SkPoint &a, const SkPoint &b, Side *side=nullptr)
Definition: SkPoint.cpp:101
static bool b
struct MyStruct a[10]

◆ DistanceToLineBetweenSqd()

float SkPointPriv::DistanceToLineBetweenSqd ( const SkPoint pt,
const SkPoint a,
const SkPoint b,
Side side = nullptr 
)
static

Definition at line 101 of file SkPoint.cpp.

103 {
104
105 SkVector u = b - a;
106 SkVector v = pt - a;
107
108 float uLengthSqd = LengthSqd(u);
109 float det = u.cross(v);
110 if (side) {
111 SkASSERT(-1 == kLeft_Side &&
112 0 == kOn_Side &&
113 1 == kRight_Side);
114 *side = (Side)sk_float_sgn(det);
115 }
116 float temp = sk_ieee_float_divide(det, uLengthSqd);
117 temp *= det;
118 // It's possible we have a degenerate line vector, or we're so far away it looks degenerate
119 // In this case, return squared distance to point A.
120 if (!SkIsFinite(temp)) {
121 return LengthSqd(v);
122 }
123 return temp;
124}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static constexpr int sk_float_sgn(float x)
static constexpr float sk_ieee_float_divide(float numer, float denom)
static SkScalar LengthSqd(const SkPoint &pt)
Definition: SkPointPriv.h:63
float cross(const SkVector &vec) const
Definition: SkPoint_impl.h:545

◆ DistanceToLineSegmentBetween()

static SkScalar SkPointPriv::DistanceToLineSegmentBetween ( const SkPoint pt,
const SkPoint a,
const SkPoint b 
)
inlinestatic

Definition at line 43 of file SkPointPriv.h.

44 {
46 }
static SkScalar DistanceToLineSegmentBetweenSqd(const SkPoint &pt, const SkPoint &a, const SkPoint &b)
Definition: SkPoint.cpp:126

◆ DistanceToLineSegmentBetweenSqd()

float SkPointPriv::DistanceToLineSegmentBetweenSqd ( const SkPoint pt,
const SkPoint a,
const SkPoint b 
)
static

Definition at line 126 of file SkPoint.cpp.

127 {
128 // See comments to distanceToLineBetweenSqd. If the projection of c onto
129 // u is between a and b then this returns the same result as that
130 // function. Otherwise, it returns the distance to the closest of a and
131 // b. Let the projection of v onto u be v'. There are three cases:
132 // 1. v' points opposite to u. c is not between a and b and is closer
133 // to a than b.
134 // 2. v' points along u and has magnitude less than y. c is between
135 // a and b and the distance to the segment is the same as distance
136 // to the line ab.
137 // 3. v' points along u and has greater magnitude than u. c is not
138 // between a and b and is closer to b than a.
139 // v' = (u dot v) * u / |u|. So if (u dot v)/|u| is less than zero we're
140 // in case 1. If (u dot v)/|u| is > |u| we are in case 3. Otherwise,
141 // we're in case 2. We actually compare (u dot v) to 0 and |u|^2 to
142 // avoid a sqrt to compute |u|.
143
144 SkVector u = b - a;
145 SkVector v = pt - a;
146
147 float uLengthSqd = LengthSqd(u);
148 float uDotV = SkPoint::DotProduct(u, v);
149
150 // closest point is point A
151 if (uDotV <= 0) {
152 return LengthSqd(v);
153 // closest point is point B
154 } else if (uDotV > uLengthSqd) {
155 return DistanceToSqd(b, pt);
156 // closest point is inside segment
157 } else {
158 float det = u.cross(v);
159 float temp = sk_ieee_float_divide(det, uLengthSqd);
160 temp *= det;
161 // It's possible we have a degenerate segment, or we're so far away it looks degenerate
162 // In this case, return squared distance to point A.
163 if (!SkIsFinite(temp)) {
164 return LengthSqd(v);
165 }
166 return temp;
167 }
168}
static SkScalar DistanceToSqd(const SkPoint &pt, const SkPoint &a)
Definition: SkPointPriv.h:48
static float DotProduct(const SkVector &a, const SkVector &b)
Definition: SkPoint_impl.h:518

◆ DistanceToSqd()

static SkScalar SkPointPriv::DistanceToSqd ( const SkPoint pt,
const SkPoint a 
)
inlinestatic

Definition at line 48 of file SkPointPriv.h.

48 {
49 SkScalar dx = pt.fX - a.fX;
50 SkScalar dy = pt.fY - a.fY;
51 return dx * dx + dy * dy;
52 }
float SkScalar
Definition: extension.cpp:12
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ EqualsWithinTolerance() [1/2]

static bool SkPointPriv::EqualsWithinTolerance ( const SkPoint p1,
const SkPoint p2 
)
inlinestatic

Definition at line 54 of file SkPointPriv.h.

54 {
55 return !CanNormalize(p1.fX - p2.fX, p1.fY - p2.fY);
56 }
static bool CanNormalize(SkScalar dx, SkScalar dy)
Definition: SkPointPriv.h:28

◆ EqualsWithinTolerance() [2/2]

static bool SkPointPriv::EqualsWithinTolerance ( const SkPoint pt,
const SkPoint p,
SkScalar  tol 
)
inlinestatic

Definition at line 58 of file SkPointPriv.h.

58 {
59 return SkScalarNearlyZero(pt.fX - p.fX, tol)
60 && SkScalarNearlyZero(pt.fY - p.fY, tol);
61 }
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:101

◆ LengthSqd()

static SkScalar SkPointPriv::LengthSqd ( const SkPoint pt)
inlinestatic

Definition at line 63 of file SkPointPriv.h.

63 {
64 return SkPoint::DotProduct(pt, pt);
65 }

◆ MakeOrthog()

static SkPoint SkPointPriv::MakeOrthog ( const SkPoint vec,
Side  side = kLeft_Side 
)
inlinestatic

Definition at line 96 of file SkPointPriv.h.

96 {
98 return (side == kRight_Side) ? SkPoint{-vec.fY, vec.fX} : SkPoint{vec.fY, -vec.fX};
99 }

◆ Negate()

static void SkPointPriv::Negate ( SkIPoint pt)
inlinestatic

Definition at line 67 of file SkPointPriv.h.

67 {
68 pt.fX = -pt.fX;
69 pt.fY = -pt.fY;
70 }
int32_t fX
x-axis value
Definition: SkPoint_impl.h:29
int32_t fY
y-axis value
Definition: SkPoint_impl.h:30

◆ RotateCCW() [1/2]

static void SkPointPriv::RotateCCW ( const SkPoint src,
SkPoint dst 
)
inlinestatic

Definition at line 72 of file SkPointPriv.h.

72 {
73 // use a tmp in case src == dst
74 SkScalar tmp = src.fX;
75 dst->fX = src.fY;
76 dst->fY = -tmp;
77 }
dst
Definition: cp.py:12

◆ RotateCCW() [2/2]

static void SkPointPriv::RotateCCW ( SkPoint pt)
inlinestatic

Definition at line 79 of file SkPointPriv.h.

79 {
80 RotateCCW(*pt, pt);
81 }
static void RotateCCW(const SkPoint &src, SkPoint *dst)
Definition: SkPointPriv.h:72

◆ RotateCW() [1/2]

static void SkPointPriv::RotateCW ( const SkPoint src,
SkPoint dst 
)
inlinestatic

Definition at line 83 of file SkPointPriv.h.

83 {
84 // use a tmp in case src == dst
85 SkScalar tmp = src.fX;
86 dst->fX = -src.fY;
87 dst->fY = tmp;
88 }

◆ RotateCW() [2/2]

static void SkPointPriv::RotateCW ( SkPoint pt)
inlinestatic

Definition at line 90 of file SkPointPriv.h.

90 {
91 RotateCW(*pt, pt);
92 }
static void RotateCW(const SkPoint &src, SkPoint *dst)
Definition: SkPointPriv.h:83

◆ SetLengthFast()

bool SkPointPriv::SetLengthFast ( SkPoint pt,
float  length 
)
static

Definition at line 94 of file SkPoint.cpp.

94 {
95 return set_point_length<true>(pt, pt->fX, pt->fY, length);
96}
size_t length

◆ SetRectFan()

static void SkPointPriv::SetRectFan ( SkPoint  v[],
SkScalar  l,
SkScalar  t,
SkScalar  r,
SkScalar  b,
size_t  stride 
)
inlinestatic

Definition at line 102 of file SkPointPriv.h.

103 {
104 SkASSERT(stride >= sizeof(SkPoint));
105
106 ((SkPoint*)((intptr_t)v + 0 * stride))->set(l, t);
107 ((SkPoint*)((intptr_t)v + 1 * stride))->set(l, b);
108 ((SkPoint*)((intptr_t)v + 2 * stride))->set(r, b);
109 ((SkPoint*)((intptr_t)v + 3 * stride))->set(r, t);
110 }

◆ SetRectTriStrip() [1/2]

static void SkPointPriv::SetRectTriStrip ( SkPoint  v[],
const SkRect rect,
size_t  stride 
)
inlinestatic

Definition at line 122 of file SkPointPriv.h.

122 {
123 SetRectTriStrip(v, rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, stride);
124 }
static void SetRectTriStrip(SkPoint v[], SkScalar l, SkScalar t, SkScalar r, SkScalar b, size_t stride)
Definition: SkPointPriv.h:113
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350

◆ SetRectTriStrip() [2/2]

static void SkPointPriv::SetRectTriStrip ( SkPoint  v[],
SkScalar  l,
SkScalar  t,
SkScalar  r,
SkScalar  b,
size_t  stride 
)
inlinestatic

Definition at line 113 of file SkPointPriv.h.

114 {
115 SkASSERT(stride >= sizeof(SkPoint));
116
117 ((SkPoint*)((intptr_t)v + 0 * stride))->set(l, t);
118 ((SkPoint*)((intptr_t)v + 1 * stride))->set(l, b);
119 ((SkPoint*)((intptr_t)v + 2 * stride))->set(r, t);
120 ((SkPoint*)((intptr_t)v + 3 * stride))->set(r, b);
121 }

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