本文整理汇总了C++中SkDPoint类的典型用法代码示例。如果您正苦于以下问题:C++ SkDPoint类的具体用法?C++ SkDPoint怎么用?C++ SkDPoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SkDPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DEF_TEST
DEF_TEST(PathOpsAngleFindQuadEpsilon, reporter) {
if (gDisableAngleTests) {
return;
}
SkRandom ran;
int maxEpsilon = 0;
double maxAngle = 0;
for (int index = 0; index < 100000; ++index) {
SkDLine line = {{{0, 0}, {ran.nextRangeF(0.0001f, 1000), ran.nextRangeF(0.0001f, 1000)}}};
float t = ran.nextRangeF(0.0001f, 1);
SkDPoint dPt = line.ptAtT(t);
float t2 = ran.nextRangeF(0.0001f, 1);
SkDPoint qPt = line.ptAtT(t2);
float t3 = ran.nextRangeF(0.0001f, 1);
SkDPoint qPt2 = line.ptAtT(t3);
qPt.fX += qPt2.fY;
qPt.fY -= qPt2.fX;
QuadPts q = {{line[0], dPt, qPt}};
SkDQuad quad;
quad.debugSet(q.fPts);
// binary search for maximum movement of quad[1] towards test that still has 1 intersection
double moveT = 0.5f;
double deltaT = moveT / 2;
SkDPoint last;
do {
last = quad[1];
quad[1].fX = dPt.fX - line[1].fY * moveT;
quad[1].fY = dPt.fY + line[1].fX * moveT;
SkIntersections i;
i.intersect(quad, line);
REPORTER_ASSERT(reporter, i.used() > 0);
if (i.used() == 1) {
moveT += deltaT;
} else {
moveT -= deltaT;
}
deltaT /= 2;
} while (last.asSkPoint() != quad[1].asSkPoint());
float p1 = SkDoubleToScalar(line[1].fX * last.fY);
float p2 = SkDoubleToScalar(line[1].fY * last.fX);
int p1Bits = SkFloatAs2sCompliment(p1);
int p2Bits = SkFloatAs2sCompliment(p2);
int epsilon = SkTAbs(p1Bits - p2Bits);
if (maxEpsilon < epsilon) {
SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g/%1.7g/%1.7g moveT=%1.7g"
" pt={%1.7g, %1.7g} epsilon=%d\n",
line[1].fX, line[1].fY, t, t2, t3, moveT, last.fX, last.fY, epsilon);
maxEpsilon = epsilon;
}
double a1 = atan2(line[1].fY, line[1].fX);
double a2 = atan2(last.fY, last.fX);
double angle = fabs(a1 - a2);
if (maxAngle < angle) {
SkDebugf("line={{0, 0}, {%1.7g, %1.7g}} t=%1.7g/%1.7g/%1.7g moveT=%1.7g"
" pt={%1.7g, %1.7g} angle=%1.7g\n",
line[1].fX, line[1].fY, t, t2, t3, moveT, last.fX, last.fY, angle);
maxAngle = angle;
}
}
}
示例2: SkTMin
// from http://blog.gludion.com/2009/08/distance-to-quadratic-bezier-curve.html
// (currently only used by testing)
double SkDQuad::nearestT(const SkDPoint& pt) const {
SkDVector pos = fPts[0] - pt;
// search points P of bezier curve with PM.(dP / dt) = 0
// a calculus leads to a 3d degree equation :
SkDVector A = fPts[1] - fPts[0];
SkDVector B = fPts[2] - fPts[1];
B -= A;
double a = B.dot(B);
double b = 3 * A.dot(B);
double c = 2 * A.dot(A) + pos.dot(B);
double d = pos.dot(A);
double ts[3];
int roots = SkDCubic::RootsValidT(a, b, c, d, ts);
double d0 = pt.distanceSquared(fPts[0]);
double d2 = pt.distanceSquared(fPts[2]);
double distMin = SkTMin(d0, d2);
int bestIndex = -1;
for (int index = 0; index < roots; ++index) {
SkDPoint onQuad = ptAtT(ts[index]);
double dist = pt.distanceSquared(onQuad);
if (distMin > dist) {
distMin = dist;
bestIndex = index;
}
}
if (bestIndex >= 0) {
return ts[bestIndex];
}
return d0 < d2 ? 0 : 1;
}
示例3: 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);
}
示例4: ptAtT
double SkDLine::nearPoint(const SkDPoint& xy) const {
if (!AlmostBetweenUlps(fPts[0].fX, xy.fX, fPts[1].fX)
|| !AlmostBetweenUlps(fPts[0].fY, xy.fY, fPts[1].fY)) {
return -1;
}
// project a perpendicular ray from the point to the line; find the T on the line
SkDVector len = fPts[1] - fPts[0]; // the x/y magnitudes of the line
double denom = len.fX * len.fX + len.fY * len.fY; // see DLine intersectRay
SkDVector ab0 = xy - fPts[0];
double numer = len.fX * ab0.fX + ab0.fY * len.fY;
if (!between(0, numer, denom)) {
return -1;
}
double t = numer / denom;
SkDPoint realPt = ptAtT(t);
double dist = realPt.distance(xy); // OPTIMIZATION: can we compare against distSq instead ?
// find the ordinal in the original line with the largest unsigned exponent
double tiniest = SkTMin(SkTMin(SkTMin(fPts[0].fX, fPts[0].fY), fPts[1].fX), fPts[1].fY);
double largest = SkTMax(SkTMax(SkTMax(fPts[0].fX, fPts[0].fY), fPts[1].fX), fPts[1].fY);
largest = SkTMax(largest, -tiniest);
if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS tolerance?
return -1;
}
t = SkPinT(t);
SkASSERT(between(0, t, 1));
return t;
}
示例5: SkPathOpsVerbToPoints
void SkOpSegment::dumpDPts() const {
int count = SkPathOpsVerbToPoints(fVerb);
SkDebugf("((SkOpSegment*) 0x%p) [%d] {{", this, debugID());
int index = 0;
do {
SkDPoint dPt = {fPts[index].fX, fPts[index].fY};
dPt.dump();
if (index != count) {
SkDebugf(", ");
}
} while (++index <= count);
SkDebugf("}}\n");
}
示例6: chopCompare
static void chopCompare(const SkConic chopped[2], const SkDConic dChopped[2]) {
SkASSERT(roughly_equal(chopped[0].fW, dChopped[0].fWeight));
SkASSERT(roughly_equal(chopped[1].fW, dChopped[1].fWeight));
for (int cIndex = 0; cIndex < 2; ++cIndex) {
for (int pIndex = 0; pIndex < 3; ++pIndex) {
SkDPoint up;
up.set(chopped[cIndex].fPts[pIndex]);
SkASSERT(dChopped[cIndex].fPts[pIndex].approximatelyEqual(up));
}
}
#if DEBUG_VISUALIZE_CONICS
dChopped[0].dump();
dChopped[1].dump();
#endif
}
示例7: testOneOffs
static void testOneOffs(skiatest::Reporter* reporter) {
SkIntersections intersections;
bool flipped = false;
for (size_t index = 0; index < oneOffs_count; ++index) {
const SkDQuad& quad = oneOffs[index].quad;
const SkDLine& line = oneOffs[index].line;
int result = doIntersect(intersections, quad, line, flipped);
for (int inner = 0; inner < result; ++inner) {
double quadT = intersections[0][inner];
SkDPoint quadXY = quad.xyAtT(quadT);
double lineT = intersections[1][inner];
SkDPoint lineXY = line.xyAtT(lineT);
REPORTER_ASSERT(reporter, quadXY.approximatelyEqual(lineXY));
}
}
}
示例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: insert
int SkIntersections::insert(double one, double two, const SkDPoint& pt) {
if (fIsCoincident[0] == 3 && between(fT[0][0], one, fT[0][1])) {
// For now, don't allow a mix of coincident and non-coincident intersections
return -1;
}
SkASSERT(fUsed <= 1 || fT[0][0] <= fT[0][1]);
int index;
for (index = 0; index < fUsed; ++index) {
double oldOne = fT[0][index];
double oldTwo = fT[1][index];
if (one == oldOne && two == oldTwo) {
return -1;
}
if (more_roughly_equal(oldOne, one) && more_roughly_equal(oldTwo, two)) {
if ((precisely_zero(one) && !precisely_zero(oldOne))
|| (precisely_equal(one, 1) && !precisely_equal(oldOne, 1))
|| (precisely_zero(two) && !precisely_zero(oldTwo))
|| (precisely_equal(two, 1) && !precisely_equal(oldTwo, 1))) {
SkASSERT(one >= 0 && one <= 1);
SkASSERT(two >= 0 && two <= 1);
fT[0][index] = one;
fT[1][index] = two;
fPt[index] = pt;
}
return -1;
}
#if ONE_OFF_DEBUG
if (pt.roughlyEqual(fPt[index])) {
SkDebugf("%s t=%1.9g pts roughly equal\n", __FUNCTION__, one);
}
#endif
if (fT[0][index] > one) {
break;
}
}
if (fUsed >= fMax) {
SkASSERT(0); // FIXME : this error, if it is to be handled at runtime in release, must
// be propagated all the way back down to the caller, and return failure.
fUsed = 0;
return 0;
}
int remaining = fUsed - index;
if (remaining > 0) {
memmove(&fPt[index + 1], &fPt[index], sizeof(fPt[0]) * remaining);
memmove(&fT[0][index + 1], &fT[0][index], sizeof(fT[0][0]) * remaining);
memmove(&fT[1][index + 1], &fT[1][index], sizeof(fT[1][0]) * remaining);
int clearMask = ~((1 << index) - 1);
fIsCoincident[0] += fIsCoincident[0] & clearMask;
fIsCoincident[1] += fIsCoincident[1] & clearMask;
}
fPt[index] = pt;
SkASSERT(one >= 0 && one <= 1);
SkASSERT(two >= 0 && two <= 1);
fT[0][index] = one;
fT[1][index] = two;
++fUsed;
return index;
}
示例10: DEF_TEST
DEF_TEST(PathOpsDPoint, reporter) {
for (size_t index = 0; index < tests_count; ++index) {
const SkDPoint& pt = tests[index];
SkASSERT(ValidPoint(pt));
SkDPoint p = pt;
REPORTER_ASSERT(reporter, p == pt);
REPORTER_ASSERT(reporter, !(pt != pt));
SkDVector v = p - pt;
p += v;
REPORTER_ASSERT(reporter, p == pt);
p -= v;
REPORTER_ASSERT(reporter, p == pt);
REPORTER_ASSERT(reporter, p.approximatelyEqual(pt));
SkPoint sPt = pt.asSkPoint();
p.set(sPt);
REPORTER_ASSERT(reporter, p == pt);
REPORTER_ASSERT(reporter, p.approximatelyEqual(sPt));
REPORTER_ASSERT(reporter, p.roughlyEqual(pt));
p.fX = p.fY = 0;
REPORTER_ASSERT(reporter, p.fX == 0 && p.fY == 0);
REPORTER_ASSERT(reporter, p.approximatelyZero());
REPORTER_ASSERT(reporter, pt.distanceSquared(p) == pt.fX * pt.fX + pt.fY * pt.fY);
REPORTER_ASSERT(reporter, approximately_equal(pt.distance(p),
sqrt(pt.fX * pt.fX + pt.fY * pt.fY)));
}
}
示例11: cubicInsert
void SkIntersections::cubicInsert(double one, double two, const SkDPoint& pt,
const SkDCubic& cubic1, const SkDCubic& cubic2) {
for (int index = 0; index < fUsed; ++index) {
if (fT[0][index] == one) {
double oldTwo = fT[1][index];
if (oldTwo == two) {
return;
}
SkDPoint mid = cubic2.ptAtT((oldTwo + two) / 2);
if (mid.approximatelyEqual(fPt[index])) {
return;
}
}
if (fT[1][index] == two) {
SkDPoint mid = cubic1.ptAtT((fT[0][index] + two) / 2);
if (mid.approximatelyEqual(fPt[index])) {
return;
}
}
}
insert(one, two, pt);
}
示例12: testOneOffs
static void testOneOffs(skiatest::Reporter* reporter) {
bool flipped = false;
for (size_t index = 0; index < oneOffs_count; ++index) {
const SkDConic& conic = oneOffs[index].conic;
SkASSERT(ValidConic(conic));
const SkDLine& line = oneOffs[index].line;
SkASSERT(ValidLine(line));
SkIntersections intersections;
int result = doIntersect(intersections, conic, line, flipped);
for (int inner = 0; inner < result; ++inner) {
double conicT = intersections[0][inner];
SkDPoint conicXY = conic.ptAtT(conicT);
double lineT = intersections[1][inner];
SkDPoint lineXY = line.ptAtT(lineT);
if (!conicXY.approximatelyEqual(lineXY)) {
conicXY.approximatelyEqual(lineXY);
SkDebugf("");
}
REPORTER_ASSERT(reporter, conicXY.approximatelyEqual(lineXY));
}
}
}
示例13: uniqueAnswer
bool uniqueAnswer(double cubicT, const SkDPoint& pt) {
for (int inner = 0; inner < fIntersections->used(); ++inner) {
if (fIntersections->pt(inner) != pt) {
continue;
}
double existingCubicT = (*fIntersections)[0][inner];
if (cubicT == existingCubicT) {
return false;
}
// check if midway on cubic is also same point. If so, discard this
double cubicMidT = (existingCubicT + cubicT) / 2;
SkDPoint cubicMidPt = fCubic.ptAtT(cubicMidT);
if (cubicMidPt.approximatelyEqual(pt)) {
return false;
}
}
#if ONE_OFF_DEBUG
SkDPoint cPt = fCubic.ptAtT(cubicT);
SkDebugf("%s pt=(%1.9g,%1.9g) cPt=(%1.9g,%1.9g)\n", __FUNCTION__, pt.fX, pt.fY,
cPt.fX, cPt.fY);
#endif
return true;
}
示例14: testOneOffs
static void testOneOffs(skiatest::Reporter* reporter) {
bool flipped = false;
for (size_t index = 0; index < oneOffs_count; ++index) {
const QuadPts& q = oneOffs[index].quad;
SkDQuad quad;
quad.debugSet(q.fPts);
SkASSERT(ValidQuad(quad));
const SkDLine& line = oneOffs[index].line;
SkASSERT(ValidLine(line));
SkIntersections intersections;
int result = doIntersect(intersections, quad, line, flipped);
for (int inner = 0; inner < result; ++inner) {
double quadT = intersections[0][inner];
SkDPoint quadXY = quad.ptAtT(quadT);
double lineT = intersections[1][inner];
SkDPoint lineXY = line.ptAtT(lineT);
if (!quadXY.approximatelyEqual(lineXY)) {
quadXY.approximatelyEqual(lineXY);
SkDebugf("");
}
REPORTER_ASSERT(reporter, quadXY.approximatelyEqual(lineXY));
}
}
}
示例15: closestTo
int SkIntersections::closestTo(double rangeStart, double rangeEnd, const SkDPoint& testPt,
double* closestDist) const {
int closest = -1;
*closestDist = SK_ScalarMax;
for (int index = 0; index < fUsed; ++index) {
if (!between(rangeStart, fT[0][index], rangeEnd)) {
continue;
}
const SkDPoint& iPt = fPt[index];
double dist = testPt.distanceSquared(iPt);
if (*closestDist > dist) {
*closestDist = dist;
closest = index;
}
}
return closest;
}