Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
94c9b232
Commit
94c9b232
authored
Nov 22, 2015
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #547 from Hixie/matrix-math
Avoid using transforms when simple offsets will do.
parents
355fe033
ebf032b8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
2 deletions
+91
-2
painting.dart
packages/flutter/lib/painting.dart
+1
-0
transforms.dart
packages/flutter/lib/src/painting/transforms.dart
+40
-0
proxy_box.dart
packages/flutter/lib/src/rendering/proxy_box.dart
+8
-2
transform_utilities_test.dart
packages/unit/test/painting/transform_utilities_test.dart
+42
-0
No files found.
packages/flutter/lib/painting.dart
View file @
94c9b232
...
...
@@ -18,3 +18,4 @@ export 'src/painting/colors.dart';
export
'src/painting/shadows.dart'
;
export
'src/painting/text_painter.dart'
;
export
'src/painting/text_style.dart'
;
export
'src/painting/transforms.dart'
;
packages/flutter/lib/src/painting/transforms.dart
0 → 100644
View file @
94c9b232
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:typed_data'
;
import
'package:vector_math/vector_math_64.dart'
;
import
'basic_types.dart'
;
class
MatrixUtils
{
MatrixUtils
.
_
();
/// If the given transform is nothing but a 2D translation, then returns that
/// translation as an Offset.
///
/// Otherwise, returns null.
static
Offset
getAsTranslation
(
Matrix4
transform
)
{
Float64List
values
=
transform
.
storage
;
// values are stored in column-major order
if
(
values
[
0
]
==
1.0
&&
values
[
1
]
==
0.0
&&
values
[
2
]
==
0.0
&&
values
[
3
]
==
0.0
&&
values
[
4
]
==
0.0
&&
values
[
5
]
==
1.0
&&
values
[
6
]
==
0.0
&&
values
[
7
]
==
0.0
&&
values
[
8
]
==
0.0
&&
values
[
9
]
==
0.0
&&
values
[
10
]
==
1.0
&&
values
[
11
]
==
0.0
&&
values
[
14
]
==
0.0
&&
values
[
15
]
==
1.0
)
{
return
new
Offset
(
values
[
12
],
values
[
13
]);
}
return
null
;
}
}
\ No newline at end of file
packages/flutter/lib/src/rendering/proxy_box.dart
View file @
94c9b232
...
...
@@ -865,8 +865,14 @@ class RenderTransform extends RenderProxyBox {
}
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
if
(
child
!=
null
)
context
.
pushTransform
(
needsCompositing
,
offset
,
_effectiveTransform
,
super
.
paint
);
if
(
child
!=
null
)
{
Matrix4
transform
=
_effectiveTransform
;
Offset
childOffset
=
MatrixUtils
.
getAsTranslation
(
transform
);
if
(
childOffset
==
null
)
context
.
pushTransform
(
needsCompositing
,
offset
,
transform
,
super
.
paint
);
else
super
.
paint
(
context
,
offset
+
childOffset
);
}
}
void
applyPaintTransform
(
Matrix4
transform
)
{
...
...
packages/unit/test/painting/transform_utilities_test.dart
0 → 100644
View file @
94c9b232
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/painting.dart'
;
import
'package:test/test.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
void
main
(
)
{
test
(
"MatrixUtils.getAsTranslation()"
,
()
{
Matrix4
test
;
test
=
new
Matrix4
.
identity
();
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
equals
(
Offset
.
zero
));
test
=
new
Matrix4
.
zero
();
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
isNull
);
test
=
new
Matrix4
.
rotationX
(
1.0
);
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
isNull
);
test
=
new
Matrix4
.
rotationZ
(
1.0
);
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
isNull
);
test
=
new
Matrix4
.
translationValues
(
1.0
,
2.0
,
0.0
);
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
equals
(
const
Offset
(
1.0
,
2.0
)));
test
=
new
Matrix4
.
translationValues
(
1.0
,
2.0
,
3.0
);
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
isNull
);
test
=
new
Matrix4
.
identity
();
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
equals
(
Offset
.
zero
));
test
.
rotateX
(
2.0
);
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
isNull
);
test
=
new
Matrix4
.
identity
();
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
equals
(
Offset
.
zero
));
test
.
scale
(
2.0
);
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
isNull
);
test
=
new
Matrix4
.
identity
();
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
equals
(
Offset
.
zero
));
test
.
translate
(
2.0
,
-
2.0
);
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
equals
(
const
Offset
(
2.0
,
-
2.0
)));
test
.
translate
(
4.0
,
8.0
);
expect
(
MatrixUtils
.
getAsTranslation
(
test
),
equals
(
const
Offset
(
6.0
,
6.0
)));
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment