Flutter Engine
The Flutter Engine
third_party
skia
src
pathops
SkDCubicToQuads.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2015 Google Inc.
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
/*
9
http://stackoverflow.com/questions/2009160/how-do-i-convert-the-2-control-points-of-a-cubic-curve-to-the-single-control-poi
10
*/
11
12
/*
13
Let's call the control points of the cubic Q0..Q3 and the control points of the quadratic P0..P2.
14
Then for degree elevation, the equations are:
15
16
Q0 = P0
17
Q1 = 1/3 P0 + 2/3 P1
18
Q2 = 2/3 P1 + 1/3 P2
19
Q3 = P2
20
In your case you have Q0..Q3 and you're solving for P0..P2. There are two ways to compute P1 from
21
the equations above:
22
23
P1 = 3/2 Q1 - 1/2 Q0
24
P1 = 3/2 Q2 - 1/2 Q3
25
If this is a degree-elevated cubic, then both equations will give the same answer for P1. Since
26
it's likely not, your best bet is to average them. So,
27
28
P1 = -1/4 Q0 + 3/4 Q1 + 3/4 Q2 - 1/4 Q3
29
*/
30
31
#include "
src/pathops/SkPathOpsCubic.h
"
32
#include "
src/pathops/SkPathOpsPoint.h
"
33
#include "
src/pathops/SkPathOpsQuad.h
"
34
35
// used for testing only
36
SkDQuad
SkDCubic::toQuad
()
const
{
37
SkDQuad
quad;
38
quad[0] =
fPts
[0];
39
const
SkDPoint
fromC1 = {(3 *
fPts
[1].
fX
-
fPts
[0].
fX
) / 2, (3 *
fPts
[1].fY -
fPts
[0].fY) / 2};
40
const
SkDPoint
fromC2 = {(3 *
fPts
[2].
fX
-
fPts
[3].
fX
) / 2, (3 *
fPts
[2].fY -
fPts
[3].fY) / 2};
41
quad[1].fX = (fromC1.
fX
+ fromC2.
fX
) / 2;
42
quad[1].fY = (fromC1.
fY
+ fromC2.
fY
) / 2;
43
quad[2] =
fPts
[3];
44
return
quad;
45
}
SkPathOpsCubic.h
SkPathOpsPoint.h
SkPathOpsQuad.h
SkDCubic::fPts
SkDPoint fPts[kPointCount]
Definition:
SkPathOpsCubic.h:152
SkDCubic::toQuad
SkDQuad toQuad() const
Definition:
SkDCubicToQuads.cpp:36
SkDPoint
Definition:
SkPathOpsPoint.h:102
SkDPoint::fY
double fY
Definition:
SkPathOpsPoint.h:104
SkDPoint::fX
double fX
Definition:
SkPathOpsPoint.h:103
SkDQuad
Definition:
SkPathOpsQuad.h:34
Generated on Sun Jun 23 2024 21:56:29 for Flutter Engine by
1.9.4