Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
SkBezierQuad Class Reference

#include <SkBezierCurves.h>

Static Public Member Functions

static SkSpan< const float > IntersectWithHorizontalLine (SkSpan< const SkPoint > controlPoints, float yIntercept, float intersectionStorage[2])
 
static SkSpan< const float > Intersect (double AX, double BX, double CX, double AY, double BY, double CY, double yIntercept, float intersectionStorage[2])
 

Detailed Description

Definition at line 76 of file SkBezierCurves.h.

Member Function Documentation

◆ Intersect()

SkSpan< const float > SkBezierQuad::Intersect ( double  AX,
double  BX,
double  CX,
double  AY,
double  BY,
double  CY,
double  yIntercept,
float  intersectionStorage[2] 
)
static

Given AY*t^2 -2*BY*t + CY = 0 and AX*t^2 - 2*BX*t + CX = 0,

Find the t where AY*t^2 - 2*BY*t + CY - y = 0, then return AX*t^2 + - 2*BX*t + CX where t is on [0, 1].

  • y - is the height of the line which intersects the quadratic.
  • intersectionStorage - is the array to hold the return data pointed to in the span.

Returns a span with the intersections of yIntercept, and the quadratic formed by A, B, and C.

Definition at line 207 of file SkBezierCurves.cpp.

209 {
210 auto [discriminant, r0, r1] = SkQuads::Roots(AY, BY, CY - yIntercept);
211
212 int intersectionCount = 0;
213 // Round the roots to the nearest float to generate the values t. Valid t's are on the
214 // domain [0, 1].
215 const double t0 = pinTRange(r0);
216 if (0 <= t0 && t0 <= 1) {
217 intersectionStorage[intersectionCount++] = SkQuads::EvalAt(AX, -2 * BX, CX, t0);
218 }
219
220 const double t1 = pinTRange(r1);
221 if (0 <= t1 && t1 <= 1 && t1 != t0) {
222 intersectionStorage[intersectionCount++] = SkQuads::EvalAt(AX, -2 * BX, CX, t1);
223 }
224
225 return SkSpan{intersectionStorage, intersectionCount};
226}
#define CX
#define CY
#define AX(width, name,...)
static RootResult Roots(double A, double B, double C)
Definition SkQuads.cpp:98
static double EvalAt(double A, double B, double C, double t)
Definition SkQuads.cpp:164

◆ IntersectWithHorizontalLine()

SkSpan< const float > SkBezierQuad::IntersectWithHorizontalLine ( SkSpan< const SkPoint controlPoints,
float  yIntercept,
float  intersectionStorage[2] 
)
static

Definition at line 189 of file SkBezierCurves.cpp.

190 {
191 SkASSERT(controlPoints.size() >= 3);
192 const DPoint p0 = controlPoints[0],
193 p1 = controlPoints[1],
194 p2 = controlPoints[2];
195
196 // Calculate A, B, C using doubles to reduce round-off error.
197 const DPoint A = p0 - 2 * p1 + p2,
198 // Remember we are generating the polynomial in the form A*t^2 -2*B*t + C, so the factor
199 // of 2 is not needed and the term is negated. This term for a Bézier curve is usually
200 // 2(p1-p0).
201 B = p0 - p1,
202 C = p0;
203
204 return Intersect(A.x, B.x, C.x, A.y, B.y, C.y, yIntercept, intersectionStorage);
205}
#define SkASSERT(cond)
Definition SkAssert.h:116
static SkSpan< const float > Intersect(double AX, double BX, double CX, double AY, double BY, double CY, double yIntercept, float intersectionStorage[2])
constexpr size_t size() const
Definition SkSpan_impl.h:95

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