Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use double multiplication by a scale instead of 3 divides for speed. #6154

Merged
merged 1 commit into from
Sep 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions flow/matrix_decomposition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ static inline SkVector3 SkVector3Cross(const SkVector3& a, const SkVector3& b) {
MatrixDecomposition::MatrixDecomposition(const SkMatrix& matrix)
: MatrixDecomposition(SkMatrix44{matrix}) {}

// TODO(garyq): use skia row[x].normalize() when skia fixes it
// Use custom normalize to avoid skia precision loss/normalize() privatization.
static inline void SkVector3Normalize(SkVector3& v) {
float mag = sqrt(v.fX * v.fX + v.fY * v.fY + v.fZ * v.fZ);
v.fX /= mag;
v.fY /= mag;
v.fZ /= mag;
double mag = sqrt(v.fX * v.fX + v.fY * v.fY + v.fZ * v.fZ);
double scale = 1.0 / mag;
v.fX *= scale;
v.fY *= scale;
v.fZ *= scale;
}

MatrixDecomposition::MatrixDecomposition(SkMatrix44 matrix) : valid_(false) {
Expand Down