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

Public Types

enum  { kLine = 0 , kQuad = 1 }
 

Public Member Functions

void init ()
 
int countPoints ()
 
const SkPointendPt () const
 

Public Attributes

enum PathSegment:: { ... }  fType
 
SkPoint fPts [3]
 
DPoint fP0T
 
DPoint fP2T
 
DAffineMatrix fXformMatrix
 
double fScalingFactor
 
double fScalingFactorSqd
 
double fNearlyZeroScaled
 
double fTangentTolScaledSqd
 
SkRect fBoundingBox
 

Detailed Description

Definition at line 198 of file GrDistanceFieldGenFromVector.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
kLine 
kQuad 

Definition at line 200 of file GrDistanceFieldGenFromVector.cpp.

200 {
201 // These enum values are assumed in member functions below.
202 kLine = 0,
203 kQuad = 1,
204 } fType;
enum PathSegment::@376 fType

Member Function Documentation

◆ countPoints()

int PathSegment::countPoints ( )
inline

Definition at line 219 of file GrDistanceFieldGenFromVector.cpp.

219 {
220 static_assert(0 == kLine && 1 == kQuad);
221 return fType + 2;
222 }

◆ endPt()

const SkPoint & PathSegment::endPt ( ) const
inline

Definition at line 224 of file GrDistanceFieldGenFromVector.cpp.

224 {
225 static_assert(0 == kLine && 1 == kQuad);
226 return fPts[fType + 1];
227 }

◆ init()

void PathSegment::init ( )

Definition at line 232 of file GrDistanceFieldGenFromVector.cpp.

232 {
233 const DPoint p0 = { fPts[0].fX, fPts[0].fY };
234 const DPoint p2 = { this->endPt().fX, this->endPt().fY };
235 const double p0x = p0.fX;
236 const double p0y = p0.fY;
237 const double p2x = p2.fX;
238 const double p2y = p2.fY;
239
240 fBoundingBox.set(fPts[0], this->endPt());
241
242 if (fType == PathSegment::kLine) {
244 double hypotenuse = p0.distance(p2);
245 if (SkTAbs(hypotenuse) < 1.0e-100) {
247 } else {
248 const double cosTheta = (p2x - p0x) / hypotenuse;
249 const double sinTheta = (p2y - p0y) / hypotenuse;
250
251 // rotates the segment to the x-axis, with p0 at the origin
253 cosTheta, sinTheta, -(cosTheta * p0x) - (sinTheta * p0y),
254 -sinTheta, cosTheta, (sinTheta * p0x) - (cosTheta * p0y)
255 );
256 }
257 } else {
259
260 // Calculate bounding box
261 const SkPoint m = fPts[0]*0.25f + fPts[1]*0.5f + fPts[2]*0.25f; // midpoint of curve
263
264 const double p1x = fPts[1].fX;
265 const double p1y = fPts[1].fY;
266
267 const double p0xSqd = p0x * p0x;
268 const double p0ySqd = p0y * p0y;
269 const double p2xSqd = p2x * p2x;
270 const double p2ySqd = p2y * p2y;
271 const double p1xSqd = p1x * p1x;
272 const double p1ySqd = p1y * p1y;
273
274 const double p01xProd = p0x * p1x;
275 const double p02xProd = p0x * p2x;
276 const double b12xProd = p1x * p2x;
277 const double p01yProd = p0y * p1y;
278 const double p02yProd = p0y * p2y;
279 const double b12yProd = p1y * p2y;
280
281 // calculate quadratic params
282 const double sqrtA = p0y - (2.0 * p1y) + p2y;
283 const double a = sqrtA * sqrtA;
284 const double h = -1.0 * (p0y - (2.0 * p1y) + p2y) * (p0x - (2.0 * p1x) + p2x);
285 const double sqrtB = p0x - (2.0 * p1x) + p2x;
286 const double b = sqrtB * sqrtB;
287 const double c = (p0xSqd * p2ySqd) - (4.0 * p01xProd * b12yProd)
288 - (2.0 * p02xProd * p02yProd) + (4.0 * p02xProd * p1ySqd)
289 + (4.0 * p1xSqd * p02yProd) - (4.0 * b12xProd * p01yProd)
290 + (p2xSqd * p0ySqd);
291 const double g = (p0x * p02yProd) - (2.0 * p0x * p1ySqd)
292 + (2.0 * p0x * b12yProd) - (p0x * p2ySqd)
293 + (2.0 * p1x * p01yProd) - (4.0 * p1x * p02yProd)
294 + (2.0 * p1x * b12yProd) - (p2x * p0ySqd)
295 + (2.0 * p2x * p01yProd) + (p2x * p02yProd)
296 - (2.0 * p2x * p1ySqd);
297 const double f = -((p0xSqd * p2y) - (2.0 * p01xProd * p1y)
298 - (2.0 * p01xProd * p2y) - (p02xProd * p0y)
299 + (4.0 * p02xProd * p1y) - (p02xProd * p2y)
300 + (2.0 * p1xSqd * p0y) + (2.0 * p1xSqd * p2y)
301 - (2.0 * b12xProd * p0y) - (2.0 * b12xProd * p1y)
302 + (p2xSqd * p0y));
303
304 const double cosTheta = sqrt(a / (a + b));
305 const double sinTheta = -1.0 * sign_of((a + b) * h) * sqrt(b / (a + b));
306
307 const double gDef = cosTheta * g - sinTheta * f;
308 const double fDef = sinTheta * g + cosTheta * f;
309
310
311 const double x0 = gDef / (a + b);
312 const double y0 = (1.0 / (2.0 * fDef)) * (c - (gDef * gDef / (a + b)));
313
314
315 const double lambda = -1.0 * ((a + b) / (2.0 * fDef));
316 fScalingFactor = fabs(1.0 / lambda);
318
319 const double lambda_cosTheta = lambda * cosTheta;
320 const double lambda_sinTheta = lambda * sinTheta;
321
322 // transforms to lie on a canonical y = x^2 parabola
324 lambda_cosTheta, -lambda_sinTheta, lambda * x0,
325 lambda_sinTheta, lambda_cosTheta, lambda * y0
326 );
327 }
328
331
334}
static double sign_of(const double &val)
static const double kNearlyZero
static const double kTangentTolerance
#define SkASSERT(cond)
Definition SkAssert.h:116
static T SkTAbs(T value)
Definition SkTemplates.h:43
DPoint mapPoint(const SkPoint &src) const
void setAffine(double m11, double m12, double m13, double m21, double m22, double m23)
const SkPoint & endPt() const
static void GrowToInclude(SkRect *r, const SkPoint &pt)
Definition SkRectPriv.h:47
static bool b
struct MyStruct a[10]
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition SkVx.h:706
SkScalar h
float fX
x-axis value
float fY
y-axis value
void set(const SkIRect &src)
Definition SkRect.h:849

Member Data Documentation

◆ fBoundingBox

SkRect PathSegment::fBoundingBox

Definition at line 215 of file GrDistanceFieldGenFromVector.cpp.

◆ fNearlyZeroScaled

double PathSegment::fNearlyZeroScaled

Definition at line 213 of file GrDistanceFieldGenFromVector.cpp.

◆ fP0T

DPoint PathSegment::fP0T

Definition at line 209 of file GrDistanceFieldGenFromVector.cpp.

◆ fP2T

DPoint PathSegment::fP2T

Definition at line 209 of file GrDistanceFieldGenFromVector.cpp.

◆ fPts

SkPoint PathSegment::fPts[3]

Definition at line 207 of file GrDistanceFieldGenFromVector.cpp.

◆ fScalingFactor

double PathSegment::fScalingFactor

Definition at line 211 of file GrDistanceFieldGenFromVector.cpp.

◆ fScalingFactorSqd

double PathSegment::fScalingFactorSqd

Definition at line 212 of file GrDistanceFieldGenFromVector.cpp.

◆ fTangentTolScaledSqd

double PathSegment::fTangentTolScaledSqd

Definition at line 214 of file GrDistanceFieldGenFromVector.cpp.

◆ []

enum { ... } PathSegment::fType

◆ fXformMatrix

DAffineMatrix PathSegment::fXformMatrix

Definition at line 210 of file GrDistanceFieldGenFromVector.cpp.


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