Try out operator overloads for Sk2x.
BUG=skia: Review URL: https://codereview.chromium.org/1024473005
This commit is contained in:
parent
12f03121bb
commit
d800d878ca
@ -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.
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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); }
|
||||
|
Loading…
Reference in New Issue
Block a user