本文整理汇总了C++中SkDQuad类的典型用法代码示例。如果您正苦于以下问题:C++ SkDQuad类的具体用法?C++ SkDQuad怎么用?C++ SkDQuad使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SkDQuad类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_intercept
// returns false if there's more than one intercept or the intercept doesn't match the point
// returns true if the intercept was successfully added or if the
// original quads need to be subdivided
static bool add_intercept(const SkDQuad& q1, const SkDQuad& q2, double tMin, double tMax,
SkIntersections* i, bool* subDivide) {
double tMid = (tMin + tMax) / 2;
SkDPoint mid = q2.ptAtT(tMid);
SkDLine line;
line[0] = line[1] = mid;
SkDVector dxdy = q2.dxdyAtT(tMid);
line[0] -= dxdy;
line[1] += dxdy;
SkIntersections rootTs;
rootTs.allowNear(false);
int roots = rootTs.intersect(q1, line);
if (roots == 0) {
if (subDivide) {
*subDivide = true;
}
return true;
}
if (roots == 2) {
return false;
}
SkDPoint pt2 = q1.ptAtT(rootTs[0][0]);
if (!pt2.approximatelyEqualHalf(mid)) {
return false;
}
i->insertSwap(rootTs[0][0], tMid, pt2);
return true;
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_skia_src,代码行数:31,代码来源:SkDQuadIntersection.cpp
示例2: checkParallel
static bool checkParallel(skiatest::Reporter* reporter, const SkDQuad& quad1, const SkDQuad& quad2) {
SkDVector sweep[2], tweep[2];
setQuadHullSweep(quad1, sweep);
setQuadHullSweep(quad2, tweep);
// if the ctrl tangents are not nearly parallel, use them
// solve for opposite direction displacement scale factor == m
// initial dir = v1.cross(v2) == v2.x * v1.y - v2.y * v1.x
// displacement of q1[1] : dq1 = { -m * v1.y, m * v1.x } + q1[1]
// straight angle when : v2.x * (dq1.y - q1[0].y) == v2.y * (dq1.x - q1[0].x)
// v2.x * (m * v1.x + v1.y) == v2.y * (-m * v1.y + v1.x)
// - m * (v2.x * v1.x + v2.y * v1.y) == v2.x * v1.y - v2.y * v1.x
// m = (v2.y * v1.x - v2.x * v1.y) / (v2.x * v1.x + v2.y * v1.y)
// m = v1.cross(v2) / v1.dot(v2)
double s0dt0 = sweep[0].dot(tweep[0]);
REPORTER_ASSERT(reporter, s0dt0 != 0);
double s0xt0 = sweep[0].crossCheck(tweep[0]);
double m = s0xt0 / s0dt0;
double sDist = sweep[0].length() * m;
double tDist = tweep[0].length() * m;
bool useS = fabs(sDist) < fabs(tDist);
double mFactor = fabs(useS ? distEndRatio(sDist, quad1) : distEndRatio(tDist, quad2));
if (mFactor < 5000) { // empirically found limit
return s0xt0 < 0;
}
SkDVector m0 = quad1.ptAtT(0.5) - quad1[0];
SkDVector m1 = quad2.ptAtT(0.5) - quad2[0];
return m0.crossCheck(m1) < 0;
}
示例3: oneOffTest
static void oneOffTest(skiatest::Reporter* reporter) {
for (size_t index = 0; index < testSetCount; ++index) {
const QuadPts& q = testSet[index];
SkDQuad quad;
quad.debugSet(q.fPts);
SkReduceOrder reducer;
SkDEBUGCODE(int result = ) reducer.reduce(quad);
SkASSERT(result == 3);
}
}
示例4: AddQuad
void SkGlyphCache::AddQuad(const SkPoint pts[2], SkScalar axis, bool yAxis,
SkGlyph::Intercept* intercept) {
SkDQuad quad;
quad.set(pts);
double roots[2];
int count = yAxis ? quad.verticalIntersect(axis, roots)
: quad.horizontalIntersect(axis, roots);
while (--count >= 0) {
SkPoint pt = quad.ptAtT(roots[count]).asSkPoint();
AddInterval(*(&pt.fX + yAxis), intercept);
}
}
示例5: Quad
SkPath::Verb SkReduceOrder::Quad(const SkPoint a[3], SkPoint* reducePts) {
SkDQuad quad;
quad.set(a);
SkReduceOrder reducer;
int order = reducer.reduce(quad);
if (order == 2) { // quad became line
for (int index = 0; index < order; ++index) {
*reducePts++ = reducer.fLine[index].asSkPoint();
}
}
return SkPathOpsPointsToVerb(order - 1);
}
示例6: testLineIntersect
static void testLineIntersect(skiatest::Reporter* reporter, const SkDQuad& quad,
const SkDLine& line, const double x, const double y) {
char pathStr[1024];
sk_bzero(pathStr, sizeof(pathStr));
char* str = pathStr;
str += sprintf(str, " path.moveTo(%1.9g, %1.9g);\n", quad[0].fX, quad[0].fY);
str += sprintf(str, " path.quadTo(%1.9g, %1.9g, %1.9g, %1.9g);\n", quad[1].fX,
quad[1].fY, quad[2].fX, quad[2].fY);
str += sprintf(str, " path.moveTo(%1.9g, %1.9g);\n", line[0].fX, line[0].fY);
str += sprintf(str, " path.lineTo(%1.9g, %1.9g);\n", line[1].fX, line[1].fY);
SkIntersections intersections;
bool flipped = false;
int result = doIntersect(intersections, quad, line, flipped);
bool found = false;
for (int index = 0; index < result; ++index) {
double quadT = intersections[0][index];
SkDPoint quadXY = quad.ptAtT(quadT);
double lineT = intersections[1][index];
SkDPoint lineXY = line.ptAtT(lineT);
if (quadXY.approximatelyEqual(lineXY)) {
found = true;
}
}
REPORTER_ASSERT(reporter, found);
}
示例7: quadHullsOverlap
/* returns
-1 if overlaps
0 if no overlap cw
1 if no overlap ccw
*/
static int quadHullsOverlap(skiatest::Reporter* reporter, const SkDQuad& quad1,
const SkDQuad& quad2) {
SkDVector sweep[2], tweep[2];
setQuadHullSweep(quad1, sweep);
setQuadHullSweep(quad2, tweep);
double s0xs1 = sweep[0].crossCheck(sweep[1]);
double s0xt0 = sweep[0].crossCheck(tweep[0]);
double s1xt0 = sweep[1].crossCheck(tweep[0]);
bool tBetweenS = s0xs1 > 0 ? s0xt0 > 0 && s1xt0 < 0 : s0xt0 < 0 && s1xt0 > 0;
double s0xt1 = sweep[0].crossCheck(tweep[1]);
double s1xt1 = sweep[1].crossCheck(tweep[1]);
tBetweenS |= s0xs1 > 0 ? s0xt1 > 0 && s1xt1 < 0 : s0xt1 < 0 && s1xt1 > 0;
double t0xt1 = tweep[0].crossCheck(tweep[1]);
if (tBetweenS) {
return -1;
}
if ((s0xt0 == 0 && s1xt1 == 0) || (s1xt0 == 0 && s0xt1 == 0)) { // s0 to s1 equals t0 to t1
return -1;
}
bool sBetweenT = t0xt1 > 0 ? s0xt0 < 0 && s0xt1 > 0 : s0xt0 > 0 && s0xt1 < 0;
sBetweenT |= t0xt1 > 0 ? s1xt0 < 0 && s1xt1 > 0 : s1xt0 > 0 && s1xt1 < 0;
if (sBetweenT) {
return -1;
}
// if all of the sweeps are in the same half plane, then the order of any pair is enough
if (s0xt0 >= 0 && s0xt1 >= 0 && s1xt0 >= 0 && s1xt1 >= 0) {
return 0;
}
if (s0xt0 <= 0 && s0xt1 <= 0 && s1xt0 <= 0 && s1xt1 <= 0) {
return 1;
}
// if the outside sweeps are greater than 180 degress:
// first assume the inital tangents are the ordering
// if the midpoint direction matches the inital order, that is enough
SkDVector m0 = quad1.ptAtT(0.5) - quad1[0];
SkDVector m1 = quad2.ptAtT(0.5) - quad2[0];
double m0xm1 = m0.crossCheck(m1);
if (s0xt0 > 0 && m0xm1 > 0) {
return 0;
}
if (s0xt0 < 0 && m0xm1 < 0) {
return 1;
}
REPORTER_ASSERT(reporter, s0xt0 != 0);
return checkParallel(reporter, quad1, quad2);
}
示例8: pointFinder
static void pointFinder(const SkDQuad& q1, const SkDQuad& q2) {
for (int index = 0; index < 3; ++index) {
double t = q1.nearestT(q2[index]);
SkDPoint onQuad = q1.ptAtT(t);
SkDebugf("%s t=%1.9g (%1.9g,%1.9g) dist=%1.9g\n", __FUNCTION__, t, onQuad.fX, onQuad.fY,
onQuad.distance(q2[index]));
double left[3];
left[0] = ((const SkDLine&) q1[0]).isLeft(q2[index]);
left[1] = ((const SkDLine&) q1[1]).isLeft(q2[index]);
SkDLine diag = {{q1[0], q1[2]}};
left[2] = diag.isLeft(q2[index]);
SkDebugf("%s left=(%d, %d, %d) inHull=%s\n", __FUNCTION__, floatSign(left[0]),
floatSign(left[1]), floatSign(left[2]),
q1.pointInHull(q2[index]) ? "true" : "false");
}
SkDebugf("\n");
}
示例9: check_linear
static int check_linear(const SkDQuad& quad,
int minX, int maxX, int minY, int maxY, SkDQuad& reduction) {
if (!quad.isLinear(0, 2)) {
return 0;
}
// four are colinear: return line formed by outside
reduction[0] = quad[0];
reduction[1] = quad[2];
return reductionLineCount(reduction);
}
示例10: testQuadLineIntersectMain
// find a point on a quad by choosing a t from 0 to 1
// create a vertical span above and below the point
// verify that intersecting the vertical span and the quad returns t
// verify that a vertical span starting at quad[0] intersects at t=0
// verify that a vertical span starting at quad[2] intersects at t=1
static void testQuadLineIntersectMain(PathOpsThreadState* data)
{
PathOpsThreadState& state = *data;
REPORTER_ASSERT(state.fReporter, data);
int ax = state.fA & 0x03;
int ay = state.fA >> 2;
int bx = state.fB & 0x03;
int by = state.fB >> 2;
int cx = state.fC & 0x03;
int cy = state.fC >> 2;
SkDQuad quad = {{{(double) ax, (double) ay}, {(double) bx, (double) by},
{(double) cx, (double) cy}
}
};
SkReduceOrder reducer;
int order = reducer.reduce(quad);
if (order < 3) {
return;
}
for (int tIndex = 0; tIndex <= 4; ++tIndex) {
SkDPoint xy = quad.ptAtT(tIndex / 4.0);
for (int h = -2; h <= 2; ++h) {
for (int v = -2; v <= 2; ++v) {
if (h == v && abs(h) != 1) {
continue;
}
double x = xy.fX;
double y = xy.fY;
SkDLine line = {{{x - h, y - v}, {x, y}}};
testLineIntersect(state.fReporter, quad, line, x, y);
state.fReporter->bumpTestCount();
SkDLine line2 = {{{x, y}, {x + h, y + v}}};
testLineIntersect(state.fReporter, quad, line2, x, y);
state.fReporter->bumpTestCount();
SkDLine line3 = {{{x - h, y - v}, {x + h, y + v}}};
testLineIntersect(state.fReporter, quad, line3, x, y);
state.fReporter->bumpTestCount();
}
}
}
}
示例11: standardTestCases
static void standardTestCases(skiatest::Reporter* reporter) {
size_t index;
SkReduceOrder reducer;
int order;
enum {
RunAll,
RunQuadraticLines,
RunQuadraticModLines,
RunNone
} run = RunAll;
int firstTestIndex = 0;
#if 0
run = RunQuadraticLines;
firstTestIndex = 1;
#endif
int firstQuadraticLineTest = run == RunAll ? 0 : run == RunQuadraticLines ? firstTestIndex
: SK_MaxS32;
int firstQuadraticModLineTest = run == RunAll ? 0 : run == RunQuadraticModLines ? firstTestIndex
: SK_MaxS32;
for (index = firstQuadraticLineTest; index < quadraticLines_count; ++index) {
const QuadPts& q = quadraticLines[index];
SkDQuad quad;
quad.debugSet(q.fPts);
order = reducer.reduce(quad);
if (order != 2) {
SkDebugf("[%d] line quad order=%d\n", (int) index, order);
}
}
for (index = firstQuadraticModLineTest; index < quadraticModEpsilonLines_count; ++index) {
const QuadPts& q = quadraticModEpsilonLines[index];
SkDQuad quad;
quad.debugSet(q.fPts);
order = reducer.reduce(quad);
if (order != 2 && order != 3) { // FIXME: data probably is not good
SkDebugf("[%d] line mod quad order=%d\n", (int) index, order);
}
}
}
示例12: set
void SkDRect::setBounds(const SkDQuad& quad) {
set(quad[0]);
add(quad[2]);
double tValues[2];
int roots = 0;
if (!between(quad[0].fX, quad[1].fX, quad[2].fX)) {
roots = SkDQuad::FindExtrema(quad[0].fX, quad[1].fX, quad[2].fX, tValues);
}
if (!between(quad[0].fY, quad[1].fY, quad[2].fY)) {
roots += SkDQuad::FindExtrema(quad[0].fY, quad[1].fY, quad[2].fY, &tValues[roots]);
}
for (int x = 0; x < roots; ++x) {
add(quad.ptAtT(tValues[x]));
}
}
示例13: check_linear
static int check_linear(const SkDQuad& quad,
int minX, int maxX, int minY, int maxY, SkDQuad& reduction) {
int startIndex = 0;
int endIndex = 2;
while (quad[startIndex].approximatelyEqual(quad[endIndex])) {
--endIndex;
if (endIndex == 0) {
SkDebugf("%s shouldn't get here if all four points are about equal", __FUNCTION__);
SkASSERT(0);
}
}
if (!quad.isLinear(startIndex, endIndex)) {
return 0;
}
// four are colinear: return line formed by outside
reduction[0] = quad[0];
reduction[1] = quad[2];
return reductionLineCount(reduction);
}
示例14: findRoots
static int findRoots(const SkDQuadImplicit& i, const SkDQuad& quad, double roots[4],
bool oneHint, bool flip, int firstCubicRoot) {
SkDQuad flipped;
const SkDQuad& q = flip ? (flipped = quad.flip()) : quad;
double a, b, c;
SkDQuad::SetABC(&q[0].fX, &a, &b, &c);
double d, e, f;
SkDQuad::SetABC(&q[0].fY, &d, &e, &f);
const double t4 = i.x2() * a * a
+ i.xy() * a * d
+ i.y2() * d * d;
const double t3 = 2 * i.x2() * a * b
+ i.xy() * (a * e + b * d)
+ 2 * i.y2() * d * e;
const double t2 = i.x2() * (b * b + 2 * a * c)
+ i.xy() * (c * d + b * e + a * f)
+ i.y2() * (e * e + 2 * d * f)
+ i.x() * a
+ i.y() * d;
const double t1 = 2 * i.x2() * b * c
+ i.xy() * (c * e + b * f)
+ 2 * i.y2() * e * f
+ i.x() * b
+ i.y() * e;
const double t0 = i.x2() * c * c
+ i.xy() * c * f
+ i.y2() * f * f
+ i.x() * c
+ i.y() * f
+ i.c();
int rootCount = SkReducedQuarticRoots(t4, t3, t2, t1, t0, oneHint, roots);
if (rootCount < 0) {
rootCount = SkQuarticRootsReal(firstCubicRoot, t4, t3, t2, t1, t0, roots);
}
if (flip) {
for (int index = 0; index < rootCount; ++index) {
roots[index] = 1 - roots[index];
}
}
return rootCount;
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_skia_src,代码行数:41,代码来源:SkDQuadIntersection.cpp
示例15: intersect
// Up promote the quad to a cubic.
// OPTIMIZATION If this is a common use case, optimize by duplicating
// the intersect 3 loop to avoid the promotion / demotion code
int SkIntersections::intersect(const SkDCubic& cubic, const SkDQuad& quad) {
SkDCubic up = quad.toCubic();
(void) intersect(cubic, up);
return used();
}