Skip to content

Commit 885126e

Browse files
parloughCommit Queue
authored and
Commit Queue
committed
[sdk/math] Mark Point, Rectangle, and MutableRectangle as legacy
These can't be deprecated for a while, at least not until 'dart:html' itself is. In the mean time, we can at least discourage usage of it and direct developers to more appropriate, long-term solutions. Contributes to #54852 CoreLibraryReviewExempt: Documentation only change that directs developers to more specific, performant, or flexible solutions. Change-Id: I9d099a49909673f8af23eab480fdd225e56bcab2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351961 Reviewed-by: Nate Bosch <[email protected]> Reviewed-by: Lasse Nielsen <[email protected]> Commit-Queue: Lasse Nielsen <[email protected]>
1 parent 9626a25 commit 885126e

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

sdk/lib/math/point.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,35 @@ part of dart.math;
1111
/// var leftTop = const Point(0, 0);
1212
/// var rightBottom = const Point(200, 400);
1313
/// ```
14+
///
15+
/// **Legacy:** New usages of [Point] are discouraged.
16+
///
17+
/// - If you are using the `Point` class with `dart:html`,
18+
/// we recommend migrating to `package:web`.
19+
/// To learn how and why to migrate,
20+
/// check out the [migration guide](https://dart.dev/go/package-web).
21+
/// - If you want to combine an `x` and `y` coordinate,
22+
/// consider using a [record](https://dart.dev/language/records).
23+
/// Depending on how you will use it, this could look
24+
/// like `var point = (x, y)` or `var point = (x: x, y: y)`.
25+
/// - If you want to perform vector operations,
26+
/// like vector addition or scalar multiplication,
27+
/// consider using a dedicated vector math library,
28+
/// such as [`package:vector_math`](https://pub.dev/packages/vector_math).
29+
/// - If you are developing a Flutter application or package,
30+
/// consider using the
31+
/// [`Offset`](https://api.flutter.dev/flutter/dart-ui/Offset-class.html)
32+
/// type from `dart:ui`.
33+
// TODO: @Deprecated(
34+
// 'Use records or a dedicated library like package:vector_math instead.')
1435
class Point<T extends num> {
1536
final T x;
1637
final T y;
1738

1839
/// Creates a point with the provided [x] and [y] coordinates.
40+
///
41+
/// **Legacy:** New usages of [Point] are discouraged.
42+
/// To learn more, check out the [Point] class API docs.
1943
const Point(T x, T y)
2044
: this.x = x,
2145
this.y = y;

sdk/lib/math/rectangle.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ part of dart.math;
1616
/// The rectangle is the set of points with representable coordinates greater
1717
/// than or equal to left/top, and with distance to left/top no greater than
1818
/// width/height (to the limit of the precision of the coordinates).
19+
///
20+
/// **Legacy:** New usages of [_RectangleBase] are discouraged.
21+
/// To learn more, check out the [Rectangle] class API docs.
1922
abstract class _RectangleBase<T extends num> {
2023
const _RectangleBase();
2124

@@ -117,6 +120,27 @@ abstract class _RectangleBase<T extends num> {
117120

118121
/// A class for representing two-dimensional rectangles whose properties are
119122
/// immutable.
123+
///
124+
/// **Legacy:** New usages of [Rectangle] are discouraged.
125+
///
126+
/// - If you are using the `Rectangle` class with `dart:html`,
127+
/// we recommend migrating to `package:web`.
128+
/// To learn how and why to migrate,
129+
/// check out the [migration guide](https://dart.dev/go/package-web).
130+
/// - If you want to store the boundaries of a rectangle
131+
/// in some coordinate system,
132+
/// consider using a [record](https://dart.dev/language/records).
133+
/// Depending on how you will use it, this could look
134+
/// like `var boundaries = (mixX: x1, maxX: x2, minY: y1, maxY: y2)`.
135+
/// - If you need to perform intersection calculations or containment checks,
136+
/// consider using a dedicated library, such as
137+
/// [`package:vector_math`](https://pub.dev/packages/vector_math).
138+
/// - If you are developing a Flutter application or package,
139+
/// consider using the
140+
/// [`Rect`](https://api.flutter.dev/flutter/dart-ui/Rect-class.html)
141+
/// type from `dart:ui`.
142+
// TODO: @Deprecated(
143+
// 'Use records or a dedicated library like package:vector_math instead.')
120144
class Rectangle<T extends num> extends _RectangleBase<T> {
121145
final T left;
122146
final T top;
@@ -144,6 +168,9 @@ class Rectangle<T extends num> extends _RectangleBase<T> {
144168
/// print(rectangle.right); // 320
145169
/// print(rectangle.bottom); // 650
146170
/// ```
171+
///
172+
/// **Legacy:** New usages of [Rectangle] are discouraged.
173+
/// To learn more, check out the [Rectangle] class API docs.
147174
const Rectangle(this.left, this.top, T width, T height)
148175
: width = (width < 0)
149176
? (width == double.negativeInfinity ? 0.0 : (-width * 0)) as dynamic
@@ -187,6 +214,27 @@ class Rectangle<T extends num> extends _RectangleBase<T> {
187214

188215
/// A class for representing two-dimensional axis-aligned rectangles with
189216
/// mutable properties.
217+
///
218+
/// **Legacy:** New usages of [MutableRectangle] are discouraged.
219+
///
220+
/// - If you are using the `MutableRectangle` class with `dart:html`,
221+
/// we recommend migrating to `package:web`.
222+
/// To learn how and why to migrate,
223+
/// check out the [migration guide](https://dart.dev/go/package-web).
224+
/// - If you want to store the boundaries of a rectangle
225+
/// in some coordinate system,
226+
/// consider using a [record](https://dart.dev/language/records).
227+
/// Depending on how you will use it, this could look
228+
/// like `var boundaries = (mixX: x1, maxX: x2, minY: y1, maxY: y2)`.
229+
/// - If you need to perform intersection calculations or containment checks,
230+
/// consider using a dedicated library, such as
231+
/// [`package:vector_math`](https://pub.dev/packages/vector_math).
232+
/// - If you are developing a Flutter application or package,
233+
/// consider using the
234+
/// [`Rect`](https://api.flutter.dev/flutter/dart-ui/Rect-class.html)
235+
/// type from `dart:ui`.
236+
// TODO: @Deprecated(
237+
// 'Use records or a dedicated library like package:vector_math instead.')
190238
class MutableRectangle<T extends num> extends _RectangleBase<T>
191239
implements Rectangle<T> {
192240
/// The x-coordinate of the left edge.
@@ -233,6 +281,9 @@ class MutableRectangle<T extends num> extends _RectangleBase<T>
233281
/// print(rectangle.right); // 220
234282
/// print(rectangle.bottom); // 150
235283
/// ```
284+
///
285+
/// **Legacy:** New usages of [MutableRectangle] are discouraged.
286+
/// To learn more, check out the [MutableRectangle] class API docs.
236287
MutableRectangle(this.left, this.top, T width, T height)
237288
: this._width =
238289
(width < 0) ? _clampToZero<T>(width) : (width + 0 as dynamic),

0 commit comments

Comments
 (0)