Commit 15eeb7f5 authored by Adam Barth's avatar Adam Barth

Merge pull request #1235 from abarth/handle_degenerate_transforms

Handle degenerate transforms better
parents 193ed22b 192c6e24
...@@ -636,6 +636,9 @@ abstract class RenderBox extends RenderObject { ...@@ -636,6 +636,9 @@ abstract class RenderBox extends RenderObject {
/// Convert the given point from the global coodinate system to the local /// Convert the given point from the global coodinate system to the local
/// coordinate system for this box. /// coordinate system for this box.
///
/// If the transform from global coordinates to local coordinates is
/// degenerate, this function returns Point.origin.
Point globalToLocal(Point point) { Point globalToLocal(Point point) {
assert(attached); assert(attached);
Matrix4 transform = new Matrix4.identity(); Matrix4 transform = new Matrix4.identity();
...@@ -645,8 +648,9 @@ abstract class RenderBox extends RenderObject { ...@@ -645,8 +648,9 @@ abstract class RenderBox extends RenderObject {
rendererParent.applyPaintTransform(renderer, transform); rendererParent.applyPaintTransform(renderer, transform);
renderer = rendererParent; renderer = rendererParent;
} }
/* double det = */ transform.invert(); double det = transform.invert();
// TODO(abarth): Check the determinant for degeneracy. if (det == 0.0)
return Point.origin;
return _transformPoint(transform, point); return _transformPoint(transform, point);
} }
......
...@@ -991,9 +991,14 @@ class RenderTransform extends RenderProxyBox { ...@@ -991,9 +991,14 @@ class RenderTransform extends RenderProxyBox {
bool hitTest(HitTestResult result, { Point position }) { bool hitTest(HitTestResult result, { Point position }) {
if (transformHitTests) { if (transformHitTests) {
Matrix4 inverse = new Matrix4.zero(); Matrix4 inverse;
// TODO(abarth): Check the determinant for degeneracy. try {
inverse.copyInverse(_effectiveTransform); inverse = new Matrix4.inverted(_effectiveTransform);
} catch (e) {
// We cannot invert the effective transform. That means the child
// doesn't appear on screen and cannot be hit.
return false;
}
Vector3 position3 = new Vector3(position.x, position.y, 0.0); Vector3 position3 = new Vector3(position.x, position.y, 0.0);
Vector3 transformed3 = inverse.transform3(position3); Vector3 transformed3 = inverse.transform3(position3);
position = new Point(transformed3.x, transformed3.y); position = new Point(transformed3.x, transformed3.y);
......
...@@ -10,7 +10,7 @@ dependencies: ...@@ -10,7 +10,7 @@ dependencies:
material_design_icons: '>=0.0.3 <0.1.0' material_design_icons: '>=0.0.3 <0.1.0'
sky_engine: 0.0.81 sky_engine: 0.0.81
sky_services: 0.0.81 sky_services: 0.0.81
vector_math: '>=1.4.3 <2.0.0' vector_math: '>=1.4.5 <2.0.0'
quiver: '>=0.21.4 <0.22.0' quiver: '>=0.21.4 <0.22.0'
# See the comment in flutter_tools' pubspec.yaml. We have to pin it # See the comment in flutter_tools' pubspec.yaml. We have to pin it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment