Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | List of all members
SkHalfPlane Struct Reference

Public Types

enum  Result {
  kAllNegative , kAllPositive , kMixed , kAllNegative ,
  kAllPositive , kMixed
}
 
enum  Result {
  kAllNegative , kAllPositive , kMixed , kAllNegative ,
  kAllPositive , kMixed
}
 

Public Member Functions

SkScalar eval (SkScalar x, SkScalar y) const
 
SkScalar operator() (SkScalar x, SkScalar y) const
 
bool normalize ()
 
Result test (const SkRect &bounds) const
 
SkScalar eval (SkScalar x, SkScalar y) const
 
SkScalar operator() (SkScalar x, SkScalar y) const
 
bool twoPts (SkPoint pts[2]) const
 
Result test (const SkRect &bounds) const
 

Public Attributes

SkScalar fA
 
SkScalar fB
 
SkScalar fC
 

Detailed Description

Definition at line 3750 of file SkPath.cpp.

Member Enumeration Documentation

◆ Result [1/2]

Enumerator
kAllNegative 
kAllPositive 
kMixed 
kAllNegative 
kAllPositive 
kMixed 

Definition at line 3786 of file SkPath.cpp.

3786 {
3789 kMixed
3790 };

◆ Result [2/2]

Enumerator
kAllNegative 
kAllPositive 
kMixed 
kAllNegative 
kAllPositive 
kMixed 

Definition at line 179 of file ClipSlide.cpp.

179 {
182 kMixed
183 };

Member Function Documentation

◆ eval() [1/2]

SkScalar SkHalfPlane::eval ( SkScalar  x,
SkScalar  y 
) const
inline

Definition at line 3753 of file SkPath.cpp.

3753 {
3754 return fA * x + fB * y + fC;
3755 }
double y
double x
SkScalar fC
Definition SkPath.cpp:3751
SkScalar fB
Definition SkPath.cpp:3751
SkScalar fA
Definition SkPath.cpp:3751

◆ eval() [2/2]

SkScalar SkHalfPlane::eval ( SkScalar  x,
SkScalar  y 
) const
inline

Definition at line 146 of file ClipSlide.cpp.

146 {
147 return fA * x + fB * y + fC;
148 }

◆ normalize()

bool SkHalfPlane::normalize ( )
inline

Definition at line 3758 of file SkPath.cpp.

3758 {
3759 double a = fA;
3760 double b = fB;
3761 double c = fC;
3762 double dmag = sqrt(a * a + b * b);
3763 // length of initial plane normal is zero
3764 if (dmag == 0) {
3765 fA = fB = 0;
3766 fC = SK_Scalar1;
3767 return true;
3768 }
3769 double dscale = sk_ieee_double_divide(1.0, dmag);
3770 a *= dscale;
3771 b *= dscale;
3772 c *= dscale;
3773 // check if we're not finite, or normal is zero-length
3774 if (!SkIsFinite(a, b, c) ||
3775 (a == 0 && b == 0)) {
3776 fA = fB = 0;
3777 fC = SK_Scalar1;
3778 return false;
3779 }
3780 fA = a;
3781 fB = b;
3782 fC = c;
3783 return true;
3784 }
static bool SkIsFinite(T x, Pack... values)
static constexpr double sk_ieee_double_divide(double numer, double denom)
#define SK_Scalar1
Definition SkScalar.h:18
static bool b
struct MyStruct a[10]
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition SkVx.h:706

◆ operator()() [1/2]

SkScalar SkHalfPlane::operator() ( SkScalar  x,
SkScalar  y 
) const
inline

Definition at line 3756 of file SkPath.cpp.

3756{ return this->eval(x, y); }
SkScalar eval(SkScalar x, SkScalar y) const
Definition SkPath.cpp:3753

◆ operator()() [2/2]

SkScalar SkHalfPlane::operator() ( SkScalar  x,
SkScalar  y 
) const
inline

Definition at line 149 of file ClipSlide.cpp.

149{ return this->eval(x, y); }

◆ test() [1/2]

Result SkHalfPlane::test ( const SkRect bounds) const
inline

Definition at line 3791 of file SkPath.cpp.

3791 {
3792 // check whether the diagonal aligned with the normal crosses the plane
3793 SkPoint diagMin, diagMax;
3794 if (fA >= 0) {
3795 diagMin.fX = bounds.fLeft;
3796 diagMax.fX = bounds.fRight;
3797 } else {
3798 diagMin.fX = bounds.fRight;
3799 diagMax.fX = bounds.fLeft;
3800 }
3801 if (fB >= 0) {
3802 diagMin.fY = bounds.fTop;
3803 diagMax.fY = bounds.fBottom;
3804 } else {
3805 diagMin.fY = bounds.fBottom;
3806 diagMax.fY = bounds.fTop;
3807 }
3808 SkScalar test = this->eval(diagMin.fX, diagMin.fY);
3809 SkScalar sign = test*this->eval(diagMax.fX, diagMax.fY);
3810 if (sign > 0) {
3811 // the path is either all on one side of the half-plane or the other
3812 if (test < 0) {
3813 return kAllNegative;
3814 } else {
3815 return kAllPositive;
3816 }
3817 }
3818 return kMixed;
3819 }
static int sign(SkScalar x)
Definition SkPath.cpp:2141
float SkScalar
Definition extension.cpp:12
Optional< SkRect > bounds
Definition SkRecords.h:189
float fX
x-axis value
float fY
y-axis value

◆ test() [2/2]

Result SkHalfPlane::test ( const SkRect bounds) const
inline

Definition at line 184 of file ClipSlide.cpp.

184 {
185 SkPoint diagMin, diagMax;
186 if (fA >= 0) {
187 diagMin.fX = bounds.fLeft;
188 diagMax.fX = bounds.fRight;
189 } else {
190 diagMin.fX = bounds.fRight;
191 diagMax.fX = bounds.fLeft;
192 }
193 if (fB >= 0) {
194 diagMin.fY = bounds.fTop;
195 diagMax.fY = bounds.fBottom;
196 } else {
197 diagMin.fY = bounds.fBottom;
198 diagMax.fY = bounds.fTop;
199 }
200 SkScalar test = this->eval(diagMin.fX, diagMin.fY);
201 SkScalar sign = test*this->eval(diagMax.fX, diagMin.fY);
202 if (sign > 0) {
203 // the path is either all on one side of the half-plane or the other
204 if (test < 0) {
205 return kAllNegative;
206 } else {
207 return kAllPositive;
208 }
209 }
210 return kMixed;
211 }

◆ twoPts()

bool SkHalfPlane::twoPts ( SkPoint  pts[2]) const
inline

Definition at line 151 of file ClipSlide.cpp.

151 {
152 // normalize plane to help with the perpendicular step, below
154 if (!len) {
155 return false;
156 }
157 SkScalar denom = SkScalarInvert(len);
158 SkScalar a = fA * denom;
159 SkScalar b = fB * denom;
160 SkScalar c = fC * denom;
161
162 // We compute p0 on the half-plane by setting one of the components to 0
163 // We compute p1 by stepping from p0 along a perpendicular to the normal
164 if (b) {
165 pts[0] = { 0, -c / b };
166 pts[1] = { b, pts[0].fY - a};
167 } else if (a) {
168 pts[0] = { -c / a, 0 };
169 pts[1] = { pts[0].fX + b, -a };
170 } else {
171 return false;
172 }
173
174 SkASSERT(SkScalarNearlyZero(this->operator()(pts[0].fX, pts[0].fY)));
175 SkASSERT(SkScalarNearlyZero(this->operator()(pts[1].fX, pts[1].fY)));
176 return true;
177 }
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkScalarInvert(x)
Definition SkScalar.h:73
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:101
#define SkScalarSqrt(x)
Definition SkScalar.h:42

Member Data Documentation

◆ fA

SkScalar SkHalfPlane::fA

Definition at line 3751 of file SkPath.cpp.

◆ fB

SkScalar SkHalfPlane::fB

Definition at line 3751 of file SkPath.cpp.

◆ fC

SkScalar SkHalfPlane::fC

Definition at line 3751 of file SkPath.cpp.


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