constint SkDCubic::gPrecisionUnit = 256; // FIXME: test different values in test framework
void SkDCubic::align(int endIndex, int ctrlIndex, SkDPoint* dstPt) const { if (fPts[endIndex].fX == fPts[ctrlIndex].fX) {
dstPt->fX = fPts[endIndex].fX;
} if (fPts[endIndex].fY == fPts[ctrlIndex].fY) {
dstPt->fY = fPts[endIndex].fY;
}
}
// give up when changing t no longer moves point // also, copy point rather than recompute it when it does change double SkDCubic::binarySearch(double min, double max, double axisIntercept,
SearchAxis xAxis) const { double t = (min + max) / 2; double step = (t - min) / 2;
SkDPoint cubicAtT = ptAtT(t); double calcPos = (&cubicAtT.fX)[xAxis]; double calcDist = calcPos - axisIntercept; do { double priorT = std::max(min, t - step);
SkDPoint lessPt = ptAtT(priorT); if (approximately_equal_half(lessPt.fX, cubicAtT.fX)
&& approximately_equal_half(lessPt.fY, cubicAtT.fY)) { return -1; // binary search found no point at this axis intercept
} double lessDist = (&lessPt.fX)[xAxis] - axisIntercept; #if DEBUG_CUBIC_BINARY_SEARCH
SkDebugf("t=%1.9g calc=%1.9g dist=%1.9g step=%1.9g less=%1.9g\n", t, calcPos, calcDist,
step, lessDist); #endif double lastStep = step;
step /= 2; if (calcDist > 0 ? calcDist > lessDist : calcDist < lessDist) {
t = priorT;
} else { double nextT = t + lastStep; if (nextT > max) { return -1;
}
SkDPoint morePt = ptAtT(nextT); if (approximately_equal_half(morePt.fX, cubicAtT.fX)
&& approximately_equal_half(morePt.fY, cubicAtT.fY)) { return -1; // binary search found no point at this axis intercept
} double moreDist = (&morePt.fX)[xAxis] - axisIntercept; if (calcDist > 0 ? calcDist <= moreDist : calcDist >= moreDist) { continue;
}
t = nextT;
}
SkDPoint testAtT = ptAtT(t);
cubicAtT = testAtT;
calcPos = (&cubicAtT.fX)[xAxis];
calcDist = calcPos - axisIntercept;
} while (!approximately_equal(calcPos, axisIntercept)); return t;
}
// get the rough scale of the cubic; used to determine if curvature is extreme double SkDCubic::calcPrecision() const { return ((fPts[1] - fPts[0]).length()
+ (fPts[2] - fPts[1]).length()
+ (fPts[3] - fPts[2]).length()) / gPrecisionUnit;
}
/* classic one t subdivision */ staticvoid interp_cubic_coords(constdouble* src, double* dst, double t) { double ab = SkDInterp(src[0], src[2], t); double bc = SkDInterp(src[2], src[4], t); double cd = SkDInterp(src[4], src[6], t); double abc = SkDInterp(ab, bc, t); double bcd = SkDInterp(bc, cd, t); double abcd = SkDInterp(abc, bcd, t);
// Do a quick reject by rotating all points relative to a line formed by // a pair of one cubic's points. If the 2nd cubic's points // are on the line or on the opposite side from the 1st cubic's 'odd man', the // curves at most intersect at the endpoints. /* if returning true, check contains true if cubic's hull collapsed, making the cubic linear ifreturningfalse,checkcontainstrueifthethecubicpairhaveonlytheendpointincommon
*/ bool SkDCubic::hullIntersects(const SkDPoint* pts, int ptCount, bool* isLinear) const { bool linear = true; char hullOrder[4]; int hullCount = convexHull(hullOrder); int end1 = hullOrder[0]; int hullIndex = 0; const SkDPoint* endPt[2];
endPt[0] = &fPts[end1]; do {
hullIndex = (hullIndex + 1) % hullCount; int end2 = hullOrder[hullIndex];
endPt[1] = &fPts[end2]; double origX = endPt[0]->fX; double origY = endPt[0]->fY; double adj = endPt[1]->fX - origX; double opp = endPt[1]->fY - origY; int oddManMask = other_two(end1, end2); int oddMan = end1 ^ oddManMask; double sign = (fPts[oddMan].fY - origY) * adj - (fPts[oddMan].fX - origX) * opp; int oddMan2 = end2 ^ oddManMask; double sign2 = (fPts[oddMan2].fY - origY) * adj - (fPts[oddMan2].fX - origX) * opp; if (sign * sign2 < 0) { continue;
} if (approximately_zero(sign)) {
sign = sign2; if (approximately_zero(sign)) { continue;
}
}
linear = false; bool foundOutlier = false; for (int n = 0; n < ptCount; ++n) { double test = (pts[n].fY - origY) * adj - (pts[n].fX - origX) * opp; if (test * sign > 0 && !precisely_zero(test)) {
foundOutlier = true; break;
}
} if (!foundOutlier) { returnfalse;
}
endPt[0] = endPt[1];
end1 = end2;
} while (hullIndex);
*isLinear = linear; return true;
}
int SkDCubic::searchRoots(double extremeTs[6], int extrema, double axisIntercept,
SearchAxis xAxis, double* validRoots) const {
extrema += findInflections(&extremeTs[extrema]);
extremeTs[extrema++] = 0;
extremeTs[extrema] = 1;
SkASSERT(extrema < 6);
SkTQSort(extremeTs, extremeTs + extrema + 1); int validCount = 0; for (int index = 0; index < extrema; ) { double min = extremeTs[index]; double max = extremeTs[++index]; if (min == max) { continue;
} double newT = binarySearch(min, max, axisIntercept, xAxis); if (newT >= 0) { if (validCount >= 3) { return0;
}
validRoots[validCount++] = newT;
}
} return validCount;
}
// cubic roots
// from SkGeometry.cpp (and Numeric Solutions, 5.6) // // TODO(skbug.com/40045140) Deduplicate with SkCubics::RootsValidT int SkDCubic::RootsValidT(double A, double B, double C, double D, double t[3]) { double s[3]; int realRoots = RootsReal(A, B, C, D, s); int foundRoots = SkDQuad::AddValidTs(s, realRoots, t); for (int index = 0; index < realRoots; ++index) { double tValue = s[index]; if (!approximately_one_or_less(tValue) && between(1, tValue, 1.00005)) { for (int idx2 = 0; idx2 < foundRoots; ++idx2) { if (approximately_equal(t[idx2], 1)) { goto nextRoot;
}
}
SkASSERT(foundRoots < 3);
t[foundRoots++] = 1;
} elseif (!approximately_zero_or_more(tValue) && between(-0.00005, tValue, 0)) { for (int idx2 = 0; idx2 < foundRoots; ++idx2) { if (approximately_equal(t[idx2], 0)) { goto nextRoot;
}
}
SkASSERT(foundRoots < 3);
t[foundRoots++] = 0;
}
nextRoot:
;
} return foundRoots;
}
// TODO(skbug.com/40045140) Deduplicate with SkCubics::RootsReal int SkDCubic::RootsReal(double A, double B, double C, double D, double s[3]) { #ifdef SK_DEBUG #if ONE_OFF_DEBUG && ONE_OFF_DEBUG_MATHEMATICA // create a string mathematica understands // GDB set print repe 15 # if repeated digits is a bother // set print elements 400 # if line doesn't fit char str[1024];
sk_bzero(str, sizeof(str));
snprintf(str, sizeof(str), "Solve[%1.19g x^3 + %1.19g x^2 + %1.19g x + %1.19g == 0, x]",
A, B, C, D);
SkPathOpsDebug::MathematicaIze(str, sizeof(str));
SkDebugf("%s\n", str); #endif #endif if (approximately_zero(A)
&& approximately_zero_when_compared_to(A, B)
&& approximately_zero_when_compared_to(A, C)
&& approximately_zero_when_compared_to(A, D)) { // we're just a quadratic return SkDQuad::RootsReal(B, C, D, s);
} if (approximately_zero_when_compared_to(D, A)
&& approximately_zero_when_compared_to(D, B)
&& approximately_zero_when_compared_to(D, C)) { // 0 is one root int num = SkDQuad::RootsReal(A, B, C, s); for (int i = 0; i < num; ++i) { if (approximately_zero(s[i])) { return num;
}
}
s[num++] = 0; return num;
} if (approximately_zero(A + B + C + D)) { // 1 is one root int num = SkDQuad::RootsReal(A, A + B, -D, s); for (int i = 0; i < num; ++i) { if (AlmostDequalUlps(s[i], 1)) { return num;
}
}
s[num++] = 1; return num;
} double a, b, c;
{ double invA = 1 / A;
a = B * invA;
b = C * invA;
c = D * invA;
} double a2 = a * a; double Q = (a2 - b * 3) / 9; double R = (2 * a2 * a - 9 * a * b + 27 * c) / 54; double R2 = R * R; double Q3 = Q * Q * Q; double R2MinusQ3 = R2 - Q3; double adiv3 = a / 3; double r; double* roots = s; if (R2MinusQ3 < 0) { // we have 3 real roots // the divide/root can, due to finite precisions, be slightly outside of -1...1 double theta = acos(SkTPin(R / sqrt(Q3), -1., 1.)); double neg2RootQ = -2 * sqrt(Q);
staticvoid formulate_F1DotF2(constdouble src[], double coeff[4]) { double a = src[2] - src[0]; double b = src[4] - 2 * src[2] + src[0]; double c = src[6] + 3 * (src[2] - src[4]) - src[0];
coeff[0] = c * c;
coeff[1] = 3 * b * c;
coeff[2] = 2 * b * b + c * a;
coeff[3] = a * b;
}
/** SkDCubic'(t) = At^2 + Bt + C, where A=3(-a+3(b-c)+d) B=6(a-2b+c) C=3(b-a) Solvefort,keepingonlythosethatfitbetween0<t<1
*/ int SkDCubic::FindExtrema(constdouble src[], double tValues[2]) { // we divide A,B,C by 3 to simplify double a = src[0]; double b = src[2]; double c = src[4]; double d = src[6]; double A = d - a + 3 * (b - c); double B = 2 * (a - b - b + c); double C = b - a;
return SkDQuad::RootsValidT(A, B, C, tValues);
}
/* from SkGeometry.cpp LookingforF'dotF''==0
A=b-a B=c-2b+a C=d-3c+3b-a
F'=3Ct^2+6Bt+3A F''=6Ct+6B
F'dotF''->CCt^3+3BCt^2+(2BB+CA)t+AB
*/ int SkDCubic::findMaxCurvature(double tValues[]) const { double coeffX[4], coeffY[4]; int i;
formulate_F1DotF2(&fPts[0].fX, coeffX);
formulate_F1DotF2(&fPts[0].fY, coeffY); for (i = 0; i < 4; i++) {
coeffX[i] = coeffX[i] + coeffY[i];
} return RootsValidT(coeffX[0], coeffX[1], coeffX[2], coeffX[3], tValues);
}
SkDPoint SkDCubic::ptAtT(double t) const { if (0 == t) { return fPts[0];
} if (1 == t) { return fPts[3];
} double one_t = 1 - t; double one_t2 = one_t * one_t; double a = one_t2 * one_t; double b = 3 * one_t2 * t; double t2 = t * t; double c = 3 * one_t * t2; double d = t2 * t;
SkDPoint result = {a * fPts[0].fX + b * fPts[1].fX + c * fPts[2].fX + d * fPts[3].fX,
a * fPts[0].fY + b * fPts[1].fY + c * fPts[2].fY + d * fPts[3].fY}; return result;
}
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.17Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-26)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.