// Enum for corner also clockwise. enum Corner {
kTopLeft_Corner = 0,
kTopRight_Corner,
kBottomRight_Corner,
kBottomLeft_Corner
};
} // namespace
/** * Evaluator to sample the values of a cubic bezier using forward differences. * Forward differences is a method for evaluating a nth degree polynomial at a uniform step by only * adding precalculated values. * For a linear example we have the function f(t) = m*t+b, then the value of that function at t+h * would be f(t+h) = m*(t+h)+b. If we want to know the uniform step that we must add to the first * evaluation f(t) then we need to substract f(t+h) - f(t) = m*t + m*h + b - m*t + b = mh. After * obtaining this value (mh) we could just add this constant step to our first sampled point * to compute the next one. * * For the cubic case the first difference gives as a result a quadratic polynomial to which we can * apply again forward differences and get linear function to which we can apply again forward * differences to get a constant difference. This is why we keep an array of size 4, the 0th * position keeps the sampled value while the next ones keep the quadratic, linear and constant * difference values.
*/
class FwDCubicEvaluator {
public:
/** * Receives the 4 control points of the cubic bezier.
*/
/** * Restarts the forward differences evaluator to the first value of t = 0.
*/ void restart(int divisions) {
fDivisions = divisions;
fCurrent = 0;
fMax = fDivisions + 1;
skvx::float2 h = 1.f / fDivisions;
skvx::float2 h2 = h * h;
skvx::float2 h3 = h2 * h;
skvx::float2 fwDiff3 = 6 * fCoefs.fA * h3;
fFwDiff[3] = to_point(fwDiff3);
fFwDiff[2] = to_point(fwDiff3 + times_2(fCoefs.fB) * h2);
fFwDiff[1] = to_point(fCoefs.fA * h3 + fCoefs.fB * h2 + fCoefs.fC * h);
fFwDiff[0] = to_point(fCoefs.fD);
}
/** * Check if the evaluator is still within the range of 0<=t<=1
*/ bool done() const { return fCurrent > fMax;
}
/** * Call next to obtain the SkPoint sampled and move to the next one.
*/
SkPoint next() {
SkPoint point = fFwDiff[0];
fFwDiff[0] += fFwDiff[1];
fFwDiff[1] += fFwDiff[2];
fFwDiff[2] += fFwDiff[3];
fCurrent++; return point;
}
if (topLength < 0 || bottomLength < 0 || leftLength < 0 || rightLength < 0) { return {0, 0}; // negative length is a sentinel for bad length (i.e. non-finite)
}
// Level of detail per axis, based on the larger side between top and bottom or left and right int lodX = static_cast<int>(std::max(topLength, bottomLength) / kPartitionSize); int lodY = static_cast<int>(std::max(leftLength, rightLength) / kPartitionSize);
// Treat null interpolation space as sRGB. if (!colorSpace) {
colorSpace = sk_srgb_singleton();
}
int vertexCount = SkToS32(mult64); // it is recommended to generate draw calls of no more than 65536 indices, so we never generate // more than 60000 indices. To accomplish that we resize the LOD and vertex count if (vertexCount > 10000 || lodX > 200 || lodY > 200) { float weightX = static_cast<float>(lodX) / (lodX + lodY); float weightY = static_cast<float>(lodY) / (lodX + lodY);
// 200 comes from the 100 * 2 which is the max value of vertices because of the limit of // 60000 indices ( sqrt(60000 / 6) that comes from data->fIndexCount = lodX * lodY * 6) // Need a min of 1 since we later divide by lod
lodX = std::max(1, sk_float_floor2int_no_saturate(weightX * 200));
lodY = std::max(1, sk_float_floor2int_no_saturate(weightY * 200));
vertexCount = (lodX + 1) * (lodY + 1);
} constint indexCount = lodX * lodY * 6;
uint32_t flags = 0; if (srcTexCoords) {
flags |= SkVertices::kHasTexCoords_BuilderFlag;
} if (srcColors) {
flags |= SkVertices::kHasColors_BuilderFlag;
}
SkScalar u = 0.0f; int stride = lodY + 1; for (int x = 0; x <= lodX; x++) {
SkPoint bottom = fBottom.next(), top = fTop.next();
fLeft.restart(lodY);
fRight.restart(lodY);
SkScalar v = 0.f; for (int y = 0; y <= lodY; y++) { int dataIndex = x * (lodY + 1) + y;
SkPoint left = fLeft.next(), right = fRight.next();
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.