Move Point to Offset (#9277)

* Manually fix every use of Point.x and Point.y

Some of these were moved to dx/dy, but not all.

* Manually convert uses of the old gradient API

* Remove old reference to Point.

* Mechanical changes

I applied the following at the root of the Flutter repository:

git ls-files -z | xargs -0 sed -i 's/\bPoint[.]origin\b/Offset.zero/g'
git ls-files -z | xargs -0 sed -i 's/\bPoint[.]lerp\b/Offset.lerp/g'
git ls-files -z | xargs -0 sed -i 's/\bnew Point\b/new Offset/g'
git ls-files -z | xargs -0 sed -i 's/\bconst Point\b/const Offset/g'
git ls-files -z | xargs -0 sed -i 's/\bstatic Point /static Offset /g'
git ls-files -z | xargs -0 sed -i 's/\bfinal Point /final Offset /g'
git ls-files -z | xargs -0 sed -i 's/^\( *\)Point /\1Offset /g'
git ls-files -z | xargs -0 sed -i 's/ui[.]Point\b/ui.Offset/g'
git ls-files -z | xargs -0 sed -i 's/(Point\b/(Offset/g'
git ls-files -z | xargs -0 sed -i 's/\([[{,]\) Point\b/\1 Offset/g'
git ls-files -z | xargs -0 sed -i 's/@required Point\b/@required Offset/g'
git ls-files -z | xargs -0 sed -i 's/<Point>/<Offset>/g'
git ls-files -z | xargs -0 sed -i 's/[.]toOffset()//g'
git ls-files -z | xargs -0 sed -i 's/[.]toPoint()//g'
git ls-files -z | xargs -0 sed -i 's/\bshow Point, /show /g'
git ls-files -z | xargs -0 sed -i 's/\bshow Point;/show Offset;/g'

* Mechanical changes - dartdocs

I applied the following at the root of the Flutter repository:

git ls-files -z | xargs -0 sed -i 's/\ba \[Point\]/an [Offset]/g'
git ls-files -z | xargs -0 sed -i 's/\[Point\]/[Offset]/g'

* Further improvements and a test

* Fix minor errors from rebasing...

* Roll engine
This commit is contained in:
Ian Hickson
2017-04-12 15:06:12 -07:00
committed by GitHub
parent 7b0b5c5760
commit bf017b79b3
182 changed files with 2374 additions and 2389 deletions

View File

@@ -197,12 +197,12 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
/// Convert the given point from the global coodinate system (as used by
/// pointer events from the device) to the coordinate system used by the
/// tests (an 800 by 600 window).
Point globalToLocal(Point point) => point;
Offset globalToLocal(Offset point) => point;
/// Convert the given point from the coordinate system used by the tests (an
/// 800 by 600 window) to the global coodinate system (as used by pointer
/// events from the device).
Point localToGlobal(Point point) => point;
Offset localToGlobal(Offset point) => point;
@override
void dispatchEvent(PointerEvent event, HitTestResult result, {
@@ -852,16 +852,16 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
}
@override
Point globalToLocal(Point point) {
Offset globalToLocal(Offset point) {
final Matrix4 transform = renderView.configuration.toHitTestMatrix();
final double det = transform.invert();
assert(det != 0.0);
final Point result = MatrixUtils.transformPoint(transform, point);
final Offset result = MatrixUtils.transformPoint(transform, point);
return result;
}
@override
Point localToGlobal(Point point) {
Offset localToGlobal(Offset point) {
final Matrix4 transform = renderView.configuration.toHitTestMatrix();
return MatrixUtils.transformPoint(transform, point);
}
@@ -932,7 +932,7 @@ class _LiveTestPointerRecord {
decay = 1;
final int pointer;
final Color color;
Point position;
Offset position;
int decay; // >0 means down, <0 means up, increases by one each time, removed at 0
}
@@ -970,7 +970,7 @@ class _LiveTestRenderView extends RenderView {
}
@override
bool hitTest(HitTestResult result, { Point position }) {
bool hitTest(HitTestResult result, { Offset position }) {
final Matrix4 transform = configuration.toHitTestMatrix();
final double det = transform.invert();
assert(det != 0.0);
@@ -985,7 +985,7 @@ class _LiveTestRenderView extends RenderView {
if (_pointers.isNotEmpty) {
final double radius = configuration.size.shortestSide * 0.05;
final Path path = new Path()
..addOval(new Rect.fromCircle(center: Point.origin, radius: radius))
..addOval(new Rect.fromCircle(center: Offset.zero, radius: radius))
..moveTo(0.0, -radius * 2.0)
..lineTo(0.0, radius * 2.0)
..moveTo(-radius * 2.0, 0.0)
@@ -998,7 +998,7 @@ class _LiveTestRenderView extends RenderView {
for (int pointer in _pointers.keys) {
final _LiveTestPointerRecord record = _pointers[pointer];
paint.color = record.color.withOpacity(record.decay < 0 ? (record.decay / (_kPointerDecay - 1)) : 1.0);
canvas.drawPath(path.shift(record.position.toOffset()), paint);
canvas.drawPath(path.shift(record.position), paint);
if (record.decay < 0)
dirty = true;
record.decay += 1;

View File

@@ -257,7 +257,7 @@ class WidgetController {
}
/// Dispatch a pointer down / pointer up sequence at the given location.
Future<Null> tapAt(Point location, { int pointer }) {
Future<Null> tapAt(Offset location, { int pointer }) {
return TestAsyncUtils.guard(() async {
final TestGesture gesture = await startGesture(location, pointer: pointer);
await gesture.up();
@@ -277,7 +277,7 @@ class WidgetController {
/// Dispatch a pointer down / pointer up sequence at the given location with
/// a delay of [kLongPressTimeout] + [kPressTimeout] between the two events.
Future<Null> longPressAt(Point location, { int pointer }) {
Future<Null> longPressAt(Offset location, { int pointer }) {
return TestAsyncUtils.guard(() async {
final TestGesture gesture = await startGesture(location, pointer: pointer);
await pump(kLongPressTimeout + kPressTimeout);
@@ -324,7 +324,7 @@ class WidgetController {
///
/// A fling is essentially a drag that ends at a particular speed. If you
/// just want to drag and end without a fling, use [dragFrom].
Future<Null> flingFrom(Point startLocation, Offset offset, double speed, { int pointer, Duration frameInterval: const Duration(milliseconds: 16) }) {
Future<Null> flingFrom(Offset startLocation, Offset offset, double speed, { int pointer, Duration frameInterval: const Duration(milliseconds: 16) }) {
assert(offset.distance > 0.0);
assert(speed > 0.0); // speed is pixels/second
return TestAsyncUtils.guard(() async {
@@ -336,7 +336,7 @@ class WidgetController {
double lastTimeStamp = timeStamp;
await sendEventToBinding(testPointer.down(startLocation, timeStamp: new Duration(milliseconds: timeStamp.round())), result);
for (int i = 0; i <= kMoveCount; i += 1) {
final Point location = startLocation + Offset.lerp(Offset.zero, offset, i / kMoveCount);
final Offset location = startLocation + Offset.lerp(Offset.zero, offset, i / kMoveCount);
await sendEventToBinding(testPointer.move(location, timeStamp: new Duration(milliseconds: timeStamp.round())), result);
timeStamp += timeStampDelta;
if (timeStamp - lastTimeStamp > frameInterval.inMilliseconds) {
@@ -377,7 +377,7 @@ class WidgetController {
/// If you want the drag to end with a speed so that the gesture recognition
/// system identifies the gesture as a fling, consider using [flingFrom]
/// instead.
Future<Null> dragFrom(Point startLocation, Offset offset, { int pointer }) {
Future<Null> dragFrom(Offset startLocation, Offset offset, { int pointer }) {
return TestAsyncUtils.guard(() async {
final TestGesture gesture = await startGesture(startLocation, pointer: pointer);
assert(gesture != null);
@@ -401,7 +401,7 @@ class WidgetController {
/// Begins a gesture at a particular point, and returns the
/// [TestGesture] object which you can use to continue the gesture.
Future<TestGesture> startGesture(Point downLocation, { int pointer }) {
Future<TestGesture> startGesture(Offset downLocation, { int pointer }) {
return TestGesture.down(
downLocation,
pointer: pointer ?? _getNextPointer(),
@@ -411,7 +411,7 @@ class WidgetController {
}
/// Forwards the given location to the binding's hitTest logic.
HitTestResult hitTestOnBinding(Point location) {
HitTestResult hitTestOnBinding(Offset location) {
final HitTestResult result = new HitTestResult();
binding.hitTest(result, location);
return result;
@@ -429,34 +429,34 @@ class WidgetController {
// GEOMETRY
/// Returns the point at the center of the given widget.
Point getCenter(Finder finder) {
return _getElementPoint(finder, (Size size) => size.center(Point.origin));
Offset getCenter(Finder finder) {
return _getElementPoint(finder, (Size size) => size.center(Offset.zero));
}
/// Returns the point at the top left of the given widget.
Point getTopLeft(Finder finder) {
return _getElementPoint(finder, (Size size) => Point.origin);
Offset getTopLeft(Finder finder) {
return _getElementPoint(finder, (Size size) => Offset.zero);
}
/// Returns the point at the top right of the given widget. This
/// point is not inside the object's hit test area.
Point getTopRight(Finder finder) {
return _getElementPoint(finder, (Size size) => size.topRight(Point.origin));
Offset getTopRight(Finder finder) {
return _getElementPoint(finder, (Size size) => size.topRight(Offset.zero));
}
/// Returns the point at the bottom left of the given widget. This
/// point is not inside the object's hit test area.
Point getBottomLeft(Finder finder) {
return _getElementPoint(finder, (Size size) => size.bottomLeft(Point.origin));
Offset getBottomLeft(Finder finder) {
return _getElementPoint(finder, (Size size) => size.bottomLeft(Offset.zero));
}
/// Returns the point at the bottom right of the given widget. This
/// point is not inside the object's hit test area.
Point getBottomRight(Finder finder) {
return _getElementPoint(finder, (Size size) => size.bottomRight(Point.origin));
Offset getBottomRight(Finder finder) {
return _getElementPoint(finder, (Size size) => size.bottomRight(Offset.zero));
}
Point _getElementPoint(Finder finder, Point sizeToPoint(Size size)) {
Offset _getElementPoint(Finder finder, Offset sizeToPoint(Size size)) {
TestAsyncUtils.guardSync();
final Element element = finder.evaluate().single;
final RenderBox box = element.renderObject;

View File

@@ -9,7 +9,7 @@ import 'package:flutter/gestures.dart';
import 'test_async_utils.dart';
export 'dart:ui' show Point;
export 'dart:ui' show Offset;
/// A class for generating coherent artificial pointer events.
///
@@ -40,15 +40,15 @@ class TestPointer {
/// The position of the last event sent by this object.
///
/// If no event has ever been sent by this object, returns null.
Point get location => _location;
Point _location;
Offset get location => _location;
Offset _location;
/// Create a [PointerDownEvent] at the given location.
///
/// By default, the time stamp on the event is [Duration.ZERO]. You
/// can give a specific time stamp by passing the `timeStamp`
/// argument.
PointerDownEvent down(Point newLocation, { Duration timeStamp: Duration.ZERO }) {
PointerDownEvent down(Offset newLocation, { Duration timeStamp: Duration.ZERO }) {
assert(!isDown);
_isDown = true;
_location = newLocation;
@@ -64,7 +64,7 @@ class TestPointer {
/// By default, the time stamp on the event is [Duration.ZERO]. You
/// can give a specific time stamp by passing the `timeStamp`
/// argument.
PointerMoveEvent move(Point newLocation, { Duration timeStamp: Duration.ZERO }) {
PointerMoveEvent move(Offset newLocation, { Duration timeStamp: Duration.ZERO }) {
assert(isDown);
final Offset delta = newLocation - location;
_location = newLocation;
@@ -116,7 +116,7 @@ class TestPointer {
typedef Future<Null> EventDispatcher(PointerEvent event, HitTestResult result);
/// Signature for callbacks that perform hit-testing at a given location.
typedef HitTestResult HitTester(Point location);
typedef HitTestResult HitTester(Offset location);
/// A class for performing gestures in tests.
///
@@ -134,7 +134,7 @@ class TestGesture {
/// A function to use for hit testing should be provided via the `hitTester`
/// argument, and a function to use for dispatching events should be provided
/// via the `dispatcher` argument.
static Future<TestGesture> down(Point downLocation, {
static Future<TestGesture> down(Offset downLocation, {
int pointer: 1,
@required HitTester hitTester,
@required EventDispatcher dispatcher,
@@ -169,7 +169,7 @@ class TestGesture {
}
/// Send a move event moving the pointer to the given location.
Future<Null> moveTo(Point location) {
Future<Null> moveTo(Offset location) {
return TestAsyncUtils.guard(() {
assert(_pointer._isDown);
return _dispatcher(_pointer.move(location), _result);

View File

@@ -261,7 +261,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
bool get hasRunningAnimations => binding.transientCallbackCount > 0;
@override
HitTestResult hitTestOnBinding(Point location) {
HitTestResult hitTestOnBinding(Offset location) {
location = binding.localToGlobal(location);
return super.hitTestOnBinding(location);
}