Move Path and PathMetrics from canvas.dart into their own files. No delta (flutter/engine#13772)

* Move Path and PathMetrics into their own files. No delta
* update file list in licenses_flutter
This commit is contained in:
Ferhat
2019-11-11 21:27:15 -08:00
committed by GitHub
parent fc817859be
commit e26e220a6f
5 changed files with 1287 additions and 1273 deletions

View File

@@ -446,6 +446,8 @@ FILE: ../../../flutter/lib/web_ui/lib/src/ui/initialization.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/lerp.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/natives.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/painting.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/path.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/path_metrics.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/pointer.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/semantics.dart
FILE: ../../../flutter/lib/web_ui/lib/src/ui/test_embedding.dart

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,176 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of ui;
/// An iterable collection of [PathMetric] objects describing a [Path].
///
/// A [PathMetrics] object is created by using the [Path.computeMetrics] method,
/// and represents the path as it stood at the time of the call. Subsequent
/// modifications of the path do not affect the [PathMetrics] object.
///
/// Each path metric corresponds to a segment, or contour, of a path.
///
/// For example, a path consisting of a [Path.lineTo], a [Path.moveTo], and
/// another [Path.lineTo] will contain two contours and thus be represented by
/// two [PathMetric] objects.
///
/// When iterating across a [PathMetrics]' contours, the [PathMetric] objects
/// are only valid until the next one is obtained.
class PathMetrics extends collection.IterableBase<PathMetric> {
PathMetrics._(Path path, bool forceClosed)
: _iterator = PathMetricIterator._(PathMetric._(path, forceClosed));
final Iterator<PathMetric> _iterator;
@override
Iterator<PathMetric> get iterator => _iterator;
}
/// Tracks iteration from one segment of a path to the next for measurement.
class PathMetricIterator implements Iterator<PathMetric> {
PathMetricIterator._(this._pathMetric);
PathMetric _pathMetric;
bool _firstTime = true;
@override
PathMetric get current => _firstTime ? null : _pathMetric;
@override
bool moveNext() {
// PathMetric isn't a normal iterable - it's already initialized to its
// first Path. Should only call _moveNext when done with the first one.
if (_firstTime == true) {
_firstTime = false;
return true;
} else if (_pathMetric?._moveNext() == true) {
return true;
}
_pathMetric = null;
return false;
}
}
/// Utilities for measuring a [Path] and extracting subpaths.
///
/// Iterate over the object returned by [Path.computeMetrics] to obtain
/// [PathMetric] objects.
///
/// Once created, metrics will only be valid while the iterator is at the given
/// contour. When the next contour's [PathMetric] is obtained, this object
/// becomes invalid.
class PathMetric {
final Path _path;
final bool _forceClosed;
/// Create a new empty [Path] object.
PathMetric._(this._path, this._forceClosed);
/// Return the total length of the current contour.
double get length => throw UnimplementedError();
/// Computes the position of hte current contour at the given offset, and the
/// angle of the path at that point.
///
/// For example, calling this method with a distance of 1.41 for a line from
/// 0.0,0.0 to 2.0,2.0 would give a point 1.0,1.0 and the angle 45 degrees
/// (but in radians).
///
/// Returns null if the contour has zero [length].
///
/// The distance is clamped to the [length] of the current contour.
Tangent getTangentForOffset(double distance) {
final Float32List posTan = _getPosTan(distance);
// first entry == 0 indicates that Skia returned false
if (posTan[0] == 0.0) {
return null;
} else {
return Tangent(
Offset(posTan[1], posTan[2]), Offset(posTan[3], posTan[4]));
}
}
Float32List _getPosTan(double distance) => throw UnimplementedError();
/// Given a start and stop distance, return the intervening segment(s).
///
/// `start` and `end` are pinned to legal values (0..[length])
/// Returns null if the segment is 0 length or `start` > `stop`.
/// Begin the segment with a moveTo if `startWithMoveTo` is true.
Path extractPath(double start, double end, {bool startWithMoveTo = true}) =>
throw UnimplementedError();
/// Whether the contour is closed.
///
/// Returns true if the contour ends with a call to [Path.close] (which may
/// have been implied when using [Path.addRect]) or if `forceClosed` was
/// specified as true in the call to [Path.computeMetrics]. Returns false
/// otherwise.
bool get isClosed => throw UnimplementedError();
// Move to the next contour in the path.
//
// A path can have a next contour if [Path.moveTo] was called after drawing
// began. Return true if one exists, or false.
//
// This is not exactly congruent with a regular [Iterator.moveNext].
// Typically, [Iterator.moveNext] should be called before accessing the
// [Iterator.current]. In this case, the [PathMetric] is valid before
// calling `_moveNext` - `_moveNext` should be called after the first
// iteration is done instead of before.
bool _moveNext() => throw UnimplementedError();
@override
String toString() => 'PathMetric';
}
/// The geometric description of a tangent: the angle at a point.
///
/// See also:
/// * [PathMetric.getTangentForOffset], which returns the tangent of an offset
/// along a path.
class Tangent {
/// Creates a [Tangent] with the given values.
///
/// The arguments must not be null.
const Tangent(this.position, this.vector)
: assert(position != null),
assert(vector != null);
/// Creates a [Tangent] based on the angle rather than the vector.
///
/// The [vector] is computed to be the unit vector at the given angle,
/// interpreted as clockwise radians from the x axis.
factory Tangent.fromAngle(Offset position, double angle) {
return Tangent(position, Offset(math.cos(angle), math.sin(angle)));
}
/// Position of the tangent.
///
/// When used with [PathMetric.getTangentForOffset], this represents the
/// precise position that the given offset along the path corresponds to.
final Offset position;
/// The vector of the curve at [position].
///
/// When used with [PathMetric.getTangentForOffset], this is the vector of the
/// curve that is at the given offset along the path (i.e. the direction of
/// the curve at [position]).
final Offset vector;
/// The direction of the curve at [position].
///
/// When used with [PathMetric.getTangentForOffset], this is the angle of the
/// curve that is the given offset along the path (i.e. the direction of the
/// curve at [position]).
///
/// This value is in radians, with 0.0 meaning pointing along the x axis in
/// the positive x-axis direction, positive numbers pointing downward toward
/// the negative y-axis, i.e. in a clockwise direction, and negative numbers
/// pointing upward toward the positive y-axis, i.e. in a counter-clockwise
/// direction.
// flip the sign to be consistent with [Path.arcTo]'s `sweepAngle`
double get angle => -math.atan2(vector.dy, vector.dx);
}

View File

@@ -32,6 +32,8 @@ part 'src/ui/initialization.dart';
part 'src/ui/lerp.dart';
part 'src/ui/natives.dart';
part 'src/ui/painting.dart';
part 'src/ui/path.dart';
part 'src/ui/path_metrics.dart';
part 'src/ui/pointer.dart';
part 'src/ui/semantics.dart';
part 'src/ui/test_embedding.dart';