Flutter Engine
The Flutter Engine
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 3818 of file SkPath.cpp.

Member Enumeration Documentation

◆ Result [1/2]

Enumerator
kAllNegative 
kAllPositive 
kMixed 
kAllNegative 
kAllPositive 
kMixed 

Definition at line 3854 of file SkPath.cpp.

3854 {
3857 kMixed
3858 };

◆ 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 3821 of file SkPath.cpp.

3821 {
3822 return fA * x + fB * y + fC;
3823 }
double y
double x
SkScalar fC
Definition: SkPath.cpp:3819
SkScalar fB
Definition: SkPath.cpp:3819
SkScalar fA
Definition: SkPath.cpp:3819

◆ 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 3826 of file SkPath.cpp.

3826 {
3827 double a = fA;
3828 double b = fB;
3829 double c = fC;
3830 double dmag = sqrt(a * a + b * b);
3831 // length of initial plane normal is zero
3832 if (dmag == 0) {
3833 fA = fB = 0;
3834 fC = SK_Scalar1;
3835 return true;
3836 }
3837 double dscale = sk_ieee_double_divide(1.0, dmag);
3838 a *= dscale;
3839 b *= dscale;
3840 c *= dscale;
3841 // check if we're not finite, or normal is zero-length
3842 if (!SkIsFinite(a, b, c) ||
3843 (a == 0 && b == 0)) {
3844 fA = fB = 0;
3845 fC = SK_Scalar1;
3846 return false;
3847 }
3848 fA = a;
3849 fB = b;
3850 fC = c;
3851 return true;
3852 }
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 3824 of file SkPath.cpp.

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

◆ 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 3859 of file SkPath.cpp.

3859 {
3860 // check whether the diagonal aligned with the normal crosses the plane
3861 SkPoint diagMin, diagMax;
3862 if (fA >= 0) {
3863 diagMin.fX = bounds.fLeft;
3864 diagMax.fX = bounds.fRight;
3865 } else {
3866 diagMin.fX = bounds.fRight;
3867 diagMax.fX = bounds.fLeft;
3868 }
3869 if (fB >= 0) {
3870 diagMin.fY = bounds.fTop;
3871 diagMax.fY = bounds.fBottom;
3872 } else {
3873 diagMin.fY = bounds.fBottom;
3874 diagMax.fY = bounds.fTop;
3875 }
3876 SkScalar test = this->eval(diagMin.fX, diagMin.fY);
3877 SkScalar sign = test*this->eval(diagMax.fX, diagMax.fY);
3878 if (sign > 0) {
3879 // the path is either all on one side of the half-plane or the other
3880 if (test < 0) {
3881 return kAllNegative;
3882 } else {
3883 return kAllPositive;
3884 }
3885 }
3886 return kMixed;
3887 }
static int sign(SkScalar x)
Definition: SkPath.cpp:2205
float SkScalar
Definition: extension.cpp:12
Optional< SkRect > bounds
Definition: SkRecords.h:189
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ 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 3819 of file SkPath.cpp.

◆ fB

SkScalar SkHalfPlane::fB

Definition at line 3819 of file SkPath.cpp.

◆ fC

SkScalar SkHalfPlane::fC

Definition at line 3819 of file SkPath.cpp.


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