本文整理汇总了C++中SkRandom::nextRangeF方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRandom::nextRangeF方法的具体用法?C++ SkRandom::nextRangeF怎么用?C++ SkRandom::nextRangeF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRandom
的用法示例。
在下文中一共展示了SkRandom::nextRangeF方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HTDrawable
HTDrawable(SkRandom& rand) {
fR = SkRect::MakeXYWH(rand.nextRangeF(0, 640), rand.nextRangeF(0, 480),
rand.nextRangeF(20, 200), rand.nextRangeF(20, 200));
fColor = rand_opaque_color(rand.nextU());
fInterp = nullptr;
fTime = 0;
}
示例2:
static inline SkRect make_random_rects(SkRandom& rand, int index, int numRects) {
SkRect out;
out.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
out.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
out.fRight = out.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/5);
out.fBottom = out.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/5);
return out;
}
示例3: random_rect
static SkRect random_rect(SkRandom& rand) {
SkRect rect = {0,0,0,0};
while (rect.isEmpty()) {
rect.fLeft = rand.nextRangeF(0, MAX_SIZE);
rect.fRight = rand.nextRangeF(0, MAX_SIZE);
rect.fTop = rand.nextRangeF(0, MAX_SIZE);
rect.fBottom = rand.nextRangeF(0, MAX_SIZE);
rect.sort();
}
return rect;
}
示例4: onAnimate
bool onAnimate(const SkAnimTimer& timer) override {
// We add noise to the scale and rotation animations to
// keep the font atlas from falling into a steady state
fRotation += (1.0f + gRand.nextRangeF(-0.1f, 0.1f));
fScale += (fScaleInc + gRand.nextRangeF(-0.025f, 0.025f));
if (fScale >= 2.0f) {
fScaleInc = -0.1f;
} else if (fScale <= 1.0f) {
fScaleInc = 0.1f;
}
return true;
}
示例5: onDraw
void onDraw(int loops, SkCanvas* canvas) override {
SkRandom rand;
for (int i = 0; i < loops; ++i) {
SkTDArray<int> hits;
SkRect query;
query.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
query.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
query.fRight = query.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/2);
query.fBottom = query.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/2);
fTree.search(query, &hits);
}
}
示例6: SkIntToScalar
static inline SkRect make_XYordered_rects(SkRandom& rand, int index, int numRects) {
SkRect out;
out.fLeft = SkIntToScalar(index % GRID_WIDTH);
out.fTop = SkIntToScalar(index / GRID_WIDTH);
out.fRight = out.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
out.fBottom = out.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
return out;
}
示例7: testTightBoundsLines
static void testTightBoundsLines(PathOpsThreadState* data) {
SkRandom ran;
for (int index = 0; index < 1000; ++index) {
SkPath path;
int contourCount = ran.nextRangeU(1, 10);
for (int cIndex = 0; cIndex < contourCount; ++cIndex) {
int lineCount = ran.nextRangeU(1, 10);
path.moveTo(ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000));
for (int lIndex = 0; lIndex < lineCount; ++lIndex) {
path.lineTo(ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000));
}
if (ran.nextBool()) {
path.close();
}
}
SkRect classicBounds = path.getBounds();
SkRect tightBounds;
REPORTER_ASSERT(data->fReporter, TightBounds(path, &tightBounds));
REPORTER_ASSERT(data->fReporter, classicBounds == tightBounds);
}
}
示例8: makePath
void makePath(SkPath* path) override {
SkRandom rand;
SkRandom randWeight;
int size = SK_ARRAY_COUNT(points);
int hSize = size / 2;
for (int i = 0; i < kMaxPathSize; ++i) {
int xTrans = 10 + 40 * (i%(kMaxPathSize/2));
int yTrans = 0;
if (i > kMaxPathSize/2 - 1) {
yTrans = 40;
}
int base1 = 2 * rand.nextULessThan(hSize);
int base2 = 2 * rand.nextULessThan(hSize);
int base3 = 2 * rand.nextULessThan(hSize);
float weight = randWeight.nextRangeF(0.0f, 2.0f);
path->moveTo(SkIntToScalar(points[base1] + xTrans),
SkIntToScalar(points[base1+1] + yTrans));
path->conicTo(SkIntToScalar(points[base2] + xTrans),
SkIntToScalar(points[base2+1] + yTrans),
SkIntToScalar(points[base3] + xTrans),
SkIntToScalar(points[base3+1] + yTrans),
weight);
}
}
示例9: test_matrix_homogeneous
static void test_matrix_homogeneous(skiatest::Reporter* reporter) {
SkMatrix mat;
const float kRotation0 = 15.5f;
const float kRotation1 = -50.f;
const float kScale0 = 5000.f;
const int kTripleCount = 1000;
const int kMatrixCount = 1000;
SkRandom rand;
SkScalar randTriples[3*kTripleCount];
for (int i = 0; i < 3*kTripleCount; ++i) {
randTriples[i] = rand.nextRangeF(-3000.f, 3000.f);
}
SkMatrix mats[kMatrixCount];
for (int i = 0; i < kMatrixCount; ++i) {
for (int j = 0; j < 9; ++j) {
mats[i].set(j, rand.nextRangeF(-3000.f, 3000.f));
}
}
// identity
{
mat.reset();
SkScalar dst[3*kTripleCount];
mat.mapHomogeneousPoints(dst, randTriples, kTripleCount);
REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(randTriples, dst, kTripleCount*3));
}
// zero matrix
{
mat.setAll(0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
SkScalar dst[3*kTripleCount];
mat.mapHomogeneousPoints(dst, randTriples, kTripleCount);
SkScalar zeros[3] = {0.f, 0.f, 0.f};
for (int i = 0; i < kTripleCount; ++i) {
REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(&dst[i*3], zeros, 3));
}
}
// zero point
{
SkScalar zeros[3] = {0.f, 0.f, 0.f};
for (int i = 0; i < kMatrixCount; ++i) {
SkScalar dst[3];
mats[i].mapHomogeneousPoints(dst, zeros, 1);
REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(dst, zeros, 3));
}
}
// doesn't crash with null dst, src, count == 0
{
mats[0].mapHomogeneousPoints(NULL, NULL, 0);
}
// uniform scale of point
{
mat.setScale(kScale0, kScale0);
SkScalar dst[3];
SkScalar src[3] = {randTriples[0], randTriples[1], 1.f};
SkPoint pnt;
pnt.set(src[0], src[1]);
mat.mapHomogeneousPoints(dst, src, 1);
mat.mapPoints(&pnt, &pnt, 1);
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[0], pnt.fX));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[1], pnt.fY));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[2], SK_Scalar1));
}
// rotation of point
{
mat.setRotate(kRotation0);
SkScalar dst[3];
SkScalar src[3] = {randTriples[0], randTriples[1], 1.f};
SkPoint pnt;
pnt.set(src[0], src[1]);
mat.mapHomogeneousPoints(dst, src, 1);
mat.mapPoints(&pnt, &pnt, 1);
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[0], pnt.fX));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[1], pnt.fY));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[2], SK_Scalar1));
}
// rotation, scale, rotation of point
{
mat.setRotate(kRotation1);
mat.postScale(kScale0, kScale0);
mat.postRotate(kRotation0);
SkScalar dst[3];
SkScalar src[3] = {randTriples[0], randTriples[1], 1.f};
SkPoint pnt;
pnt.set(src[0], src[1]);
mat.mapHomogeneousPoints(dst, src, 1);
mat.mapPoints(&pnt, &pnt, 1);
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[0], pnt.fX));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[1], pnt.fY));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[2], SK_Scalar1));
}
//.........这里部分代码省略.........
示例10: test_matrix_decomposition
//.........这里部分代码省略.........
// uniform scale+reflection, then rotate
mat.setScale(kScale0, -kScale0);
mat.postRotate(kRotation1);
REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
// rotation then anisotropic scale
mat.setRotate(kRotation1);
mat.postScale(kScale1, kScale0);
REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
// rotation then anisotropic scale
mat.setRotate(90);
mat.postScale(kScale1, kScale0);
REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
// anisotropic scale then rotation
mat.setScale(kScale1, kScale0);
mat.postRotate(kRotation0);
REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
// anisotropic scale then rotation
mat.setScale(kScale1, kScale0);
mat.postRotate(90);
REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
// rotation, uniform scale, then different rotation
mat.setRotate(kRotation1);
mat.postScale(kScale0, kScale0);
mat.postRotate(kRotation0);
REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
// rotation, anisotropic scale, then different rotation
mat.setRotate(kRotation0);
mat.postScale(kScale1, kScale0);
mat.postRotate(kRotation1);
REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
// rotation, anisotropic scale + reflection, then different rotation
mat.setRotate(kRotation0);
mat.postScale(-kScale1, kScale0);
mat.postRotate(kRotation1);
REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
// try some random matrices
SkRandom rand;
for (int m = 0; m < 1000; ++m) {
SkScalar rot0 = rand.nextRangeF(-180, 180);
SkScalar sx = rand.nextRangeF(-3000.f, 3000.f);
SkScalar sy = rand.nextRangeF(-3000.f, 3000.f);
SkScalar rot1 = rand.nextRangeF(-180, 180);
mat.setRotate(rot0);
mat.postScale(sx, sy);
mat.postRotate(rot1);
if (SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)) {
REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
} else {
// if the matrix is degenerate, the basis vectors should be near-parallel or near-zero
SkScalar perpdot = mat[SkMatrix::kMScaleX]*mat[SkMatrix::kMScaleY] -
mat[SkMatrix::kMSkewX]*mat[SkMatrix::kMSkewY];
REPORTER_ASSERT(reporter, SkScalarNearlyZero(perpdot));
}
}
// translation shouldn't affect this
mat.postTranslate(-1000.f, 1000.f);
REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
// perspective shouldn't affect this
mat[SkMatrix::kMPersp0] = 12.f;
mat[SkMatrix::kMPersp1] = 4.f;
mat[SkMatrix::kMPersp2] = 1872.f;
REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
// degenerate matrices
// mostly zero entries
mat.reset();
mat[SkMatrix::kMScaleX] = 0.f;
REPORTER_ASSERT(reporter, !SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
mat.reset();
mat[SkMatrix::kMScaleY] = 0.f;
REPORTER_ASSERT(reporter, !SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
mat.reset();
// linearly dependent entries
mat[SkMatrix::kMScaleX] = 1.f;
mat[SkMatrix::kMSkewX] = 2.f;
mat[SkMatrix::kMSkewY] = 4.f;
mat[SkMatrix::kMScaleY] = 8.f;
REPORTER_ASSERT(reporter, !SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
}
示例11: sizeof
// determine that slop required after quad/quad finds a candidate intersection
// use the cross of the tangents plus the distance from 1 or 0 as knobs
DEF_TEST(PathOpsCubicQuadSlop, reporter) {
// create a random non-selfintersecting cubic
// break it into quadratics
// offset the quadratic, measuring the slop required to find the intersection
if (!gPathOpCubicQuadSlopVerbose) { // takes a while to run -- so exclude it by default
return;
}
int results[101];
sk_bzero(results, sizeof(results));
double minCross[101];
sk_bzero(minCross, sizeof(minCross));
double maxCross[101];
sk_bzero(maxCross, sizeof(maxCross));
double sumCross[101];
sk_bzero(sumCross, sizeof(sumCross));
int foundOne = 0;
int slopCount = 1;
SkRandom ran;
for (int index = 0; index < 10000000; ++index) {
if (index % 1000 == 999) SkDebugf(".");
SkDCubic cubic = {{
{ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)},
{ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)},
{ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)},
{ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000)}
}};
SkIntersections i;
if (i.intersect(cubic)) {
continue;
}
SkSTArray<kCubicToQuadSubdivisionDepth, double, true> ts;
cubic.toQuadraticTs(cubic.calcPrecision(), &ts);
double tStart = 0;
int tsCount = ts.count();
for (int i1 = 0; i1 <= tsCount; ++i1) {
const double tEnd = i1 < tsCount ? ts[i1] : 1;
SkDCubic part = cubic.subDivide(tStart, tEnd);
SkDQuad quad = part.toQuad();
SkReduceOrder reducer;
int order = reducer.reduce(quad);
if (order != 3) {
continue;
}
for (int i2 = 0; i2 < 100; ++i2) {
SkDPoint endDisplacement = {ran.nextRangeF(-100, 100), ran.nextRangeF(-100, 100)};
SkDQuad nearby = {{
{quad[0].fX + endDisplacement.fX, quad[0].fY + endDisplacement.fY},
{quad[1].fX + ran.nextRangeF(-100, 100), quad[1].fY + ran.nextRangeF(-100, 100)},
{quad[2].fX - endDisplacement.fX, quad[2].fY - endDisplacement.fY}
}};
order = reducer.reduce(nearby);
if (order != 3) {
continue;
}
SkIntersections locals;
locals.allowNear(false);
locals.intersect(quad, nearby);
if (locals.used() != 1) {
continue;
}
// brute force find actual intersection
SkDLine cubicLine = {{ {0, 0}, {cubic[0].fX, cubic[0].fY } }};
SkIntersections liner;
int i3;
int found = -1;
int foundErr = true;
for (i3 = 1; i3 <= 1000; ++i3) {
cubicLine[0] = cubicLine[1];
cubicLine[1] = cubic.ptAtT(i3 / 1000.);
liner.reset();
liner.allowNear(false);
liner.intersect(nearby, cubicLine);
if (liner.used() == 0) {
continue;
}
if (liner.used() > 1) {
foundErr = true;
break;
}
if (found > 0) {
foundErr = true;
break;
}
foundErr = false;
found = i3;
}
if (foundErr) {
continue;
}
SkDVector dist = liner.pt(0) - locals.pt(0);
SkDVector qV = nearby.dxdyAtT(locals[0][0]);
double cubicT = (found - 1 + liner[1][0]) / 1000.;
SkDVector cV = cubic.dxdyAtT(cubicT);
double qxc = qV.crossCheck(cV);
double qvLen = qV.length();
double cvLen = cV.length();
double maxLen = SkTMax(qvLen, cvLen);
qxc /= maxLen;
//.........这里部分代码省略.........
示例12: testTightBoundsQuads
static void testTightBoundsQuads(PathOpsThreadState* data) {
SkRandom ran;
const int bitWidth = 32;
const int bitHeight = 32;
const float pathMin = 1;
const float pathMax = (float) (bitHeight - 2);
SkBitmap& bits = *data->fBitmap;
if (bits.width() == 0) {
bits.allocN32Pixels(bitWidth, bitHeight);
}
SkCanvas canvas(bits);
SkPaint paint;
for (int index = 0; index < 100; ++index) {
SkPath path;
int contourCount = ran.nextRangeU(1, 10);
for (int cIndex = 0; cIndex < contourCount; ++cIndex) {
int lineCount = ran.nextRangeU(1, 10);
path.moveTo(ran.nextRangeF(1, pathMax), ran.nextRangeF(pathMin, pathMax));
for (int lIndex = 0; lIndex < lineCount; ++lIndex) {
if (ran.nextBool()) {
path.lineTo(ran.nextRangeF(pathMin, pathMax), ran.nextRangeF(pathMin, pathMax));
} else {
path.quadTo(ran.nextRangeF(pathMin, pathMax), ran.nextRangeF(pathMin, pathMax),
ran.nextRangeF(pathMin, pathMax), ran.nextRangeF(pathMin, pathMax));
}
}
if (ran.nextBool()) {
path.close();
}
}
SkRect classicBounds = path.getBounds();
SkRect tightBounds;
REPORTER_ASSERT(data->fReporter, TightBounds(path, &tightBounds));
REPORTER_ASSERT(data->fReporter, classicBounds.contains(tightBounds));
canvas.drawColor(SK_ColorWHITE);
canvas.drawPath(path, paint);
SkIRect bitsWritten = {31, 31, 0, 0};
for (int y = 0; y < bitHeight; ++y) {
uint32_t* addr1 = data->fBitmap->getAddr32(0, y);
bool lineWritten = false;
for (int x = 0; x < bitWidth; ++x) {
if (addr1[x] == (uint32_t) -1) {
continue;
}
lineWritten = true;
bitsWritten.fLeft = SkTMin(bitsWritten.fLeft, x);
bitsWritten.fRight = SkTMax(bitsWritten.fRight, x);
}
if (!lineWritten) {
continue;
}
bitsWritten.fTop = SkTMin(bitsWritten.fTop, y);
bitsWritten.fBottom = SkTMax(bitsWritten.fBottom, y);
}
if (!bitsWritten.isEmpty()) {
SkIRect tightOut;
tightBounds.roundOut(&tightOut);
REPORTER_ASSERT(data->fReporter, tightOut.contains(bitsWritten));
}
}
}