Try out operator overloads for Sk2x.

BUG=skia:

Review URL: https://codereview.chromium.org/1024473005
This commit is contained in:
mtklein 2015-03-19 14:28:31 -07:00 committed by Commit bot
parent 12f03121bb
commit d800d878ca
3 changed files with 21 additions and 4 deletions

View File

@ -49,6 +49,14 @@ public:
Sk2x subtract(const Sk2x&) const;
Sk2x multiply(const Sk2x&) const;
Sk2x operator +(const Sk2x& o) const { return this->add(o); }
Sk2x operator -(const Sk2x& o) const { return this->subtract(o); }
Sk2x operator *(const Sk2x& o) const { return this->multiply(o); }
Sk2x& operator +=(const Sk2x& o) { return (*this = *this + o); }
Sk2x& operator -=(const Sk2x& o) { return (*this = *this - o); }
Sk2x& operator *=(const Sk2x& o) { return (*this = *this * o); }
Sk2x rsqrt() const; // Approximate 1/this->sqrt().
Sk2x sqrt() const; // this->multiply(this->rsqrt()) may be faster, but less precise.

View File

@ -139,12 +139,11 @@ SkPoint SkEvalQuadAt(const SkPoint src[3], SkScalar t) {
Sk2f P1 = Sk2f::Load(&src[1].fX);
Sk2f P2 = Sk2f::Load(&src[2].fX);
Sk2f A = P2.subtract(P1.add(P1)).add(P0);
Sk2f B = P1.subtract(P0);
B = B.add(B);
Sk2f B = P1 - P0;
Sk2f A = P2 - P1 - B;
SkPoint result;
A.multiply(t2).add(B).multiply(t2).add(P0).store(&result.fX);
((A * t2 + B+B) * t2 + P0).store(&result.fX);
return result;
}

View File

@ -45,11 +45,21 @@ static void test(skiatest::Reporter* r) {
REPORTER_ASSERT(r, eq(a.subtract(d), 2, -1));
REPORTER_ASSERT(r, eq(a.multiply(d), 8, 20));
REPORTER_ASSERT(r, eq(a + d, 6, 9));
REPORTER_ASSERT(r, eq(a - d, 2, -1));
REPORTER_ASSERT(r, eq(a * d, 8, 20));
REPORTER_ASSERT(r, nearly_eq(0.001, a.rsqrt(), 0.5, 0.5));
REPORTER_ASSERT(r, eq(a.sqrt(), 2, 2));
REPORTER_ASSERT(r, eq(Sk2x<T>::Min(a, d), 2, 4));
REPORTER_ASSERT(r, eq(Sk2x<T>::Max(a, d), 4, 5));
// A bit of both.
a += d;
a *= d;
a -= d;
REPORTER_ASSERT(r, eq(a, 10,40));
}
DEF_TEST(Sk2f, r) { test< float>(r); }