本文整理汇总了C++中SkMatrix::setPerspY方法的典型用法代码示例。如果您正苦于以下问题:C++ SkMatrix::setPerspY方法的具体用法?C++ SkMatrix::setPerspY怎么用?C++ SkMatrix::setPerspY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkMatrix
的用法示例。
在下文中一共展示了SkMatrix::setPerspY方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkPoint pts[2] = {
{ 0, 0 },
{ SkIntToScalar(100), SkIntToScalar(100) }
};
SkShader::TileMode tm = SkShader::kClamp_TileMode;
SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
SkPaint paint;
paint.setAntiAlias(true);
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
canvas->save();
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL);
// apply an increasing y perspective as we move to the right
SkMatrix perspective;
perspective.setIdentity();
perspective.setPerspY(SkScalarDiv(SkIntToScalar((unsigned) i+1),
SkIntToScalar(500)));
perspective.setSkewX(SkScalarDiv(SkIntToScalar((unsigned) i+1),
SkIntToScalar(10)));
shader->setLocalMatrix(perspective);
paint.setShader(shader);
canvas->drawRect(r, paint);
shader->unref();
canvas->translate(0, SkIntToScalar(120));
}
canvas->restore();
canvas->translate(SkIntToScalar(120), 0);
}
}
示例2: onDraw
void onDraw(int loops, SkCanvas* canvas) override {
SkPaint paint;
paint.setAntiAlias(fAA);
paint.setBlendMode(fMode);
SkColor color = start_color(fColorType);
int w = this->getSize().x();
int h = this->getSize().y();
static const SkScalar kRectW = 25.1f;
static const SkScalar kRectH = 25.9f;
if (fColorType == kShaderOpaque_ColorType) {
// The only requirement for the shader is that it requires local coordinates
SkPoint pts[2] = { {0.0f, 0.0f}, {kRectW, kRectH} };
SkColor colors[] = { color, SK_ColorBLUE };
paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
SkTileMode::kClamp));
}
SkMatrix rotate;
// This value was chosen so that we frequently hit the axis-aligned case.
rotate.setRotate(30.f, kRectW / 2, kRectH / 2);
SkMatrix m = rotate;
SkScalar tx = 0, ty = 0;
if (fPerspective) {
// Apply some fixed perspective to change how ops may draw the rects
SkMatrix perspective;
perspective.setIdentity();
perspective.setPerspX(1e-4f);
perspective.setPerspY(1e-3f);
perspective.setSkewX(0.1f);
canvas->concat(perspective);
}
for (int i = 0; i < loops; ++i) {
canvas->save();
canvas->translate(tx, ty);
canvas->concat(m);
paint.setColor(color);
color = advance_color(color, fColorType, i);
canvas->drawRect(SkRect::MakeWH(kRectW, kRectH), paint);
canvas->restore();
tx += kRectW + 2;
if (tx > w) {
tx = 0;
ty += kRectH + 2;
if (ty > h) {
ty = 0;
}
}
m.postConcat(rotate);
}
}
示例3: onDraw
virtual void onDraw(SkCanvas* canvas) {
this->makePath();
// do perspective drawPaint as the background;
SkPaint bkgnrd;
SkPoint center = SkPoint::Make(SkIntToScalar(100),
SkIntToScalar(100));
SkColor colors[] = {SK_ColorBLACK, SK_ColorCYAN,
SK_ColorYELLOW, SK_ColorWHITE};
SkScalar pos[] = {0, SK_ScalarHalf / 2,
3 * SK_ScalarHalf / 2, SK_Scalar1};
SkShader* s = SkGradientShader::CreateRadial(center,
SkIntToScalar(1000),
colors,
pos,
SK_ARRAY_COUNT(colors),
SkShader::kClamp_TileMode);
bkgnrd.setShader(s)->unref();
canvas->save();
canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
SkMatrix mat;
mat.reset();
mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 1000));
canvas->concat(mat);
canvas->drawPaint(bkgnrd);
canvas->restore();
// draw the paths in perspective
SkMatrix persp;
persp.reset();
persp.setPerspX(SkScalarToPersp(-SK_Scalar1 / 1800));
persp.setPerspY(SkScalarToPersp(SK_Scalar1 / 500));
canvas->concat(persp);
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
const SkScalar scale = SkIntToScalar(5)/4;
showFour(canvas, SK_Scalar1, false);
canvas->translate(SkIntToScalar(450), 0);
showFour(canvas, scale, false);
canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
showFour(canvas, SK_Scalar1, true);
canvas->translate(SkIntToScalar(450), 0);
showFour(canvas, scale, true);
}
示例4: SkMatrix
AffineTransform::operator SkMatrix() const
{
SkMatrix result;
result.setScaleX(WebCoreDoubleToSkScalar(a()));
result.setSkewX(WebCoreDoubleToSkScalar(c()));
result.setTranslateX(WebCoreDoubleToSkScalar(e()));
result.setScaleY(WebCoreDoubleToSkScalar(d()));
result.setSkewY(WebCoreDoubleToSkScalar(b()));
result.setTranslateY(WebCoreDoubleToSkScalar(f()));
// FIXME: Set perspective properly.
result.setPerspX(0);
result.setPerspY(0);
result.set(SkMatrix::kMPersp2, SK_Scalar1);
return result;
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_WebKit,代码行数:19,代码来源:AffineTransform.cpp
示例5: affineTransformToSkMatrix
SkMatrix affineTransformToSkMatrix(const AffineTransform& source)
{
SkMatrix result;
result.setScaleX(WebCoreDoubleToSkScalar(source.a()));
result.setSkewX(WebCoreDoubleToSkScalar(source.c()));
result.setTranslateX(WebCoreDoubleToSkScalar(source.e()));
result.setScaleY(WebCoreDoubleToSkScalar(source.d()));
result.setSkewY(WebCoreDoubleToSkScalar(source.b()));
result.setTranslateY(WebCoreDoubleToSkScalar(source.f()));
// FIXME: Set perspective properly.
result.setPerspX(0);
result.setPerspY(0);
result.set(SkMatrix::kMPersp2, SK_Scalar1);
return result;
}
示例6: test_matrix_is_similarity
static void test_matrix_is_similarity(skiatest::Reporter* reporter) {
SkMatrix mat;
// identity
mat.setIdentity();
REPORTER_ASSERT(reporter, mat.isSimilarity());
// translation only
mat.reset();
mat.setTranslate(SkIntToScalar(100), SkIntToScalar(100));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with same size
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with one negative
mat.reset();
mat.setScale(SkIntToScalar(-15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with different size
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(20));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// scale with same size at a pivot point
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(15),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with different size at a pivot point
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(20),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with same size
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with different size
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with same size at a pivot point
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with different size at a pivot point
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// perspective x
mat.reset();
mat.setPerspX(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// perspective y
mat.reset();
mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// rotate
for (int angle = 0; angle < 360; ++angle) {
mat.reset();
mat.setRotate(SkIntToScalar(angle));
REPORTER_ASSERT(reporter, mat.isSimilarity());
}
// see if there are any accumulated precision issues
mat.reset();
for (int i = 1; i < 360; i++) {
mat.postRotate(SkIntToScalar(1));
}
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + translate
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postTranslate(SkIntToScalar(10), SkIntToScalar(20));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + uniform scale
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postScale(SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + non-uniform scale
mat.reset();
mat.setRotate(SkIntToScalar(30));
//.........这里部分代码省略.........
示例7: test_matrix_min_max_scale
static void test_matrix_min_max_scale(skiatest::Reporter* reporter) {
SkScalar scales[2];
bool success;
SkMatrix identity;
identity.reset();
REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMinScale());
REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMaxScale());
success = identity.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success && SK_Scalar1 == scales[0] && SK_Scalar1 == scales[1]);
SkMatrix scale;
scale.setScale(SK_Scalar1 * 2, SK_Scalar1 * 4);
REPORTER_ASSERT(reporter, SK_Scalar1 * 2 == scale.getMinScale());
REPORTER_ASSERT(reporter, SK_Scalar1 * 4 == scale.getMaxScale());
success = scale.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success && SK_Scalar1 * 2 == scales[0] && SK_Scalar1 * 4 == scales[1]);
SkMatrix rot90Scale;
rot90Scale.setRotate(90 * SK_Scalar1);
rot90Scale.postScale(SK_Scalar1 / 4, SK_Scalar1 / 2);
REPORTER_ASSERT(reporter, SK_Scalar1 / 4 == rot90Scale.getMinScale());
REPORTER_ASSERT(reporter, SK_Scalar1 / 2 == rot90Scale.getMaxScale());
success = rot90Scale.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success && SK_Scalar1 / 4 == scales[0] && SK_Scalar1 / 2 == scales[1]);
SkMatrix rotate;
rotate.setRotate(128 * SK_Scalar1);
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMinScale(), SK_ScalarNearlyZero));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMaxScale(), SK_ScalarNearlyZero));
success = rotate.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success);
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, scales[0], SK_ScalarNearlyZero));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, scales[1], SK_ScalarNearlyZero));
SkMatrix translate;
translate.setTranslate(10 * SK_Scalar1, -5 * SK_Scalar1);
REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMinScale());
REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMaxScale());
success = translate.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success && SK_Scalar1 == scales[0] && SK_Scalar1 == scales[1]);
SkMatrix perspX;
perspX.reset();
perspX.setPerspX(SkScalarToPersp(SK_Scalar1 / 1000));
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMinScale());
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMaxScale());
// Verify that getMinMaxScales() doesn't update the scales array on failure.
scales[0] = -5;
scales[1] = -5;
success = perspX.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * SK_Scalar1 == scales[1]);
SkMatrix perspY;
perspY.reset();
perspY.setPerspY(SkScalarToPersp(-SK_Scalar1 / 500));
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMinScale());
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxScale());
scales[0] = -5;
scales[1] = -5;
success = perspY.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * SK_Scalar1 == scales[1]);
SkMatrix baseMats[] = {scale, rot90Scale, rotate,
translate, perspX, perspY};
SkMatrix mats[2*SK_ARRAY_COUNT(baseMats)];
for (size_t i = 0; i < SK_ARRAY_COUNT(baseMats); ++i) {
mats[i] = baseMats[i];
bool invertable = mats[i].invert(&mats[i + SK_ARRAY_COUNT(baseMats)]);
REPORTER_ASSERT(reporter, invertable);
}
SkRandom rand;
for (int m = 0; m < 1000; ++m) {
SkMatrix mat;
mat.reset();
for (int i = 0; i < 4; ++i) {
int x = rand.nextU() % SK_ARRAY_COUNT(mats);
mat.postConcat(mats[x]);
}
SkScalar minScale = mat.getMinScale();
SkScalar maxScale = mat.getMaxScale();
REPORTER_ASSERT(reporter, (minScale < 0) == (maxScale < 0));
REPORTER_ASSERT(reporter, (maxScale < 0) == mat.hasPerspective());
SkScalar scales[2];
bool success = mat.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success == !mat.hasPerspective());
REPORTER_ASSERT(reporter, !success || (scales[0] == minScale && scales[1] == maxScale));
if (mat.hasPerspective()) {
m -= 1; // try another non-persp matrix
continue;
}
// test a bunch of vectors. All should be scaled by between minScale and maxScale
// (modulo some error) and we should find a vector that is scaled by almost each.
static const SkScalar gVectorScaleTol = (105 * SK_Scalar1) / 100;
static const SkScalar gCloseScaleTol = (97 * SK_Scalar1) / 100;
SkScalar max = 0, min = SK_ScalarMax;
//.........这里部分代码省略.........
示例8: test_matrix_is_similarity
static void test_matrix_is_similarity(skiatest::Reporter* reporter) {
SkMatrix mat;
// identity
mat.setIdentity();
REPORTER_ASSERT(reporter, mat.isSimilarity());
// translation only
mat.reset();
mat.setTranslate(SkIntToScalar(100), SkIntToScalar(100));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with same size
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with one negative
mat.reset();
mat.setScale(SkIntToScalar(-15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with different size
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(20));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// scale with same size at a pivot point
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(15),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with different size at a pivot point
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(20),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with same size
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with different size
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with same size at a pivot point
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with different size at a pivot point
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// perspective x
mat.reset();
mat.setPerspX(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// perspective y
mat.reset();
mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
#ifdef SK_SCALAR_IS_FLOAT
/* We bypass the following tests for SK_SCALAR_IS_FIXED build.
* The long discussion can be found in this issue:
* http://codereview.appspot.com/5999050/
* In short, we haven't found a perfect way to fix the precision
* issue, i.e. the way we use tolerance in isSimilarityTransformation
* is incorrect. The situation becomes worse in fixed build, so
* we disabled rotation related tests for fixed build.
*/
// rotate
for (int angle = 0; angle < 360; ++angle) {
mat.reset();
mat.setRotate(SkIntToScalar(angle));
REPORTER_ASSERT(reporter, mat.isSimilarity());
}
// see if there are any accumulated precision issues
mat.reset();
for (int i = 1; i < 360; i++) {
mat.postRotate(SkIntToScalar(1));
}
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + translate
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postTranslate(SkIntToScalar(10), SkIntToScalar(20));
REPORTER_ASSERT(reporter, mat.isSimilarity());
//.........这里部分代码省略.........
示例9: makeMatrix
SkMatrix makeMatrix() {
SkMatrix matrix;
matrix.reset();
RandomSetMatrix setMatrix = (RandomSetMatrix) fRand.nextRangeU(0, kRandomSetMatrix_Last);
if (fPrintName) {
SkDebugf("%.*s%s\n", fPathDepth * 3, fTab, gRandomSetMatrixNames[setMatrix]);
}
switch (setMatrix) {
case kSetIdentity:
break;
case kSetTranslateX:
matrix.setTranslateX(makeScalar());
break;
case kSetTranslateY:
matrix.setTranslateY(makeScalar());
break;
case kSetTranslate:
matrix.setTranslate(makeScalar(), makeScalar());
break;
case kSetScaleX:
matrix.setScaleX(makeScalar());
break;
case kSetScaleY:
matrix.setScaleY(makeScalar());
break;
case kSetScale:
matrix.setScale(makeScalar(), makeScalar());
break;
case kSetScaleTranslate:
matrix.setScale(makeScalar(), makeScalar(), makeScalar(), makeScalar());
break;
case kSetSkewX:
matrix.setSkewX(makeScalar());
break;
case kSetSkewY:
matrix.setSkewY(makeScalar());
break;
case kSetSkew:
matrix.setSkew(makeScalar(), makeScalar());
break;
case kSetSkewTranslate:
matrix.setSkew(makeScalar(), makeScalar(), makeScalar(), makeScalar());
break;
case kSetRotate:
matrix.setRotate(makeScalar());
break;
case kSetRotateTranslate:
matrix.setRotate(makeScalar(), makeScalar(), makeScalar());
break;
case kSetPerspectiveX:
matrix.setPerspX(makeScalar());
break;
case kSetPerspectiveY:
matrix.setPerspY(makeScalar());
break;
case kSetAll:
matrix.setAll(makeScalar(), makeScalar(), makeScalar(),
makeScalar(), makeScalar(), makeScalar(),
makeScalar(), makeScalar(), makeScalar());
break;
}
return matrix;
}
示例10: test_transform_helper
// Called to test various transforms on a single SkRRect.
static void test_transform_helper(skiatest::Reporter* reporter, const SkRRect& orig) {
SkRRect dst;
dst.setEmpty();
// The identity matrix will duplicate the rrect.
bool success = orig.transform(SkMatrix::I(), &dst);
REPORTER_ASSERT(reporter, success);
REPORTER_ASSERT(reporter, orig == dst);
// Skew and Perspective make transform fail.
SkMatrix matrix;
matrix.reset();
matrix.setSkewX(SkIntToScalar(2));
assert_transform_failure(reporter, orig, matrix);
matrix.reset();
matrix.setSkewY(SkIntToScalar(3));
assert_transform_failure(reporter, orig, matrix);
matrix.reset();
matrix.setPerspX(4);
assert_transform_failure(reporter, orig, matrix);
matrix.reset();
matrix.setPerspY(5);
assert_transform_failure(reporter, orig, matrix);
// Rotation fails.
matrix.reset();
matrix.setRotate(SkIntToScalar(90));
assert_transform_failure(reporter, orig, matrix);
matrix.setRotate(SkIntToScalar(37));
assert_transform_failure(reporter, orig, matrix);
// Translate will keep the rect moved, but otherwise the same.
matrix.reset();
SkScalar translateX = SkIntToScalar(32);
SkScalar translateY = SkIntToScalar(15);
matrix.setTranslateX(translateX);
matrix.setTranslateY(translateY);
dst.setEmpty();
success = orig.transform(matrix, &dst);
REPORTER_ASSERT(reporter, success);
for (int i = 0; i < 4; ++i) {
REPORTER_ASSERT(reporter,
orig.radii((SkRRect::Corner) i) == dst.radii((SkRRect::Corner) i));
}
REPORTER_ASSERT(reporter, orig.rect().width() == dst.rect().width());
REPORTER_ASSERT(reporter, orig.rect().height() == dst.rect().height());
REPORTER_ASSERT(reporter, dst.rect().left() == orig.rect().left() + translateX);
REPORTER_ASSERT(reporter, dst.rect().top() == orig.rect().top() + translateY);
// Keeping the translation, but adding skew will make transform fail.
matrix.setSkewY(SkIntToScalar(7));
assert_transform_failure(reporter, orig, matrix);
// Scaling in -x will flip the round rect horizontally.
matrix.reset();
matrix.setScaleX(SkIntToScalar(-1));
dst.setEmpty();
success = orig.transform(matrix, &dst);
REPORTER_ASSERT(reporter, success);
{
GET_RADII;
// Radii have swapped in x.
REPORTER_ASSERT(reporter, origUL == dstUR);
REPORTER_ASSERT(reporter, origUR == dstUL);
REPORTER_ASSERT(reporter, origLR == dstLL);
REPORTER_ASSERT(reporter, origLL == dstLR);
}
// Width and height remain the same.
REPORTER_ASSERT(reporter, orig.rect().width() == dst.rect().width());
REPORTER_ASSERT(reporter, orig.rect().height() == dst.rect().height());
// Right and left have swapped (sort of)
REPORTER_ASSERT(reporter, orig.rect().right() == -dst.rect().left());
// Top has stayed the same.
REPORTER_ASSERT(reporter, orig.rect().top() == dst.rect().top());
// Keeping the scale, but adding a persp will make transform fail.
matrix.setPerspX(7);
assert_transform_failure(reporter, orig, matrix);
// Scaling in -y will flip the round rect vertically.
matrix.reset();
matrix.setScaleY(SkIntToScalar(-1));
dst.setEmpty();
success = orig.transform(matrix, &dst);
REPORTER_ASSERT(reporter, success);
{
GET_RADII;
// Radii have swapped in y.
REPORTER_ASSERT(reporter, origUL == dstLL);
REPORTER_ASSERT(reporter, origUR == dstLR);
REPORTER_ASSERT(reporter, origLR == dstUR);
REPORTER_ASSERT(reporter, origLL == dstUL);
}
// Width and height remain the same.
REPORTER_ASSERT(reporter, orig.rect().width() == dst.rect().width());
REPORTER_ASSERT(reporter, orig.rect().height() == dst.rect().height());
//.........这里部分代码省略.........
示例11: test_matrix_is_similarity
static void test_matrix_is_similarity(skiatest::Reporter* reporter) {
SkMatrix mat;
// identity
mat.setIdentity();
REPORTER_ASSERT(reporter, mat.isSimilarity());
// translation only
mat.reset();
mat.setTranslate(SkIntToScalar(100), SkIntToScalar(100));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with same size
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with one negative
mat.reset();
mat.setScale(SkIntToScalar(-15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with different size
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(20));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// scale with same size at a pivot point
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(15),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with different size at a pivot point
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(20),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with same size
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with different size
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with same size at a pivot point
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with different size at a pivot point
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// perspective x
mat.reset();
mat.setPerspX(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// perspective y
mat.reset();
mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// rotate
for (int angle = 0; angle < 360; ++angle) {
mat.reset();
mat.setRotate(SkIntToScalar(angle));
#ifndef SK_CPU_ARM64
REPORTER_ASSERT(reporter, mat.isSimilarity());
#else
// 64-bit ARM devices built with -O2 and -ffp-contract=fast have a loss
// of precision and require that we have a higher tolerance
REPORTER_ASSERT(reporter, mat.isSimilarity(SK_ScalarNearlyZero + 0.00010113f));
#endif
}
// see if there are any accumulated precision issues
mat.reset();
for (int i = 1; i < 360; i++) {
mat.postRotate(SkIntToScalar(1));
}
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + translate
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postTranslate(SkIntToScalar(10), SkIntToScalar(20));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + uniform scale
mat.reset();
mat.setRotate(SkIntToScalar(30));
//.........这里部分代码省略.........