math: dartfmt -f --fix
Change-Id: I1ffb3c418479903d982f17753e74d264b9341361
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97447
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Kevin Moore <kevmoo@google.com>
diff --git a/sdk/lib/math/jenkins_smi_hash.dart b/sdk/lib/math/jenkins_smi_hash.dart
index 1fc7dda..d756b37 100644
--- a/sdk/lib/math/jenkins_smi_hash.dart
+++ b/sdk/lib/math/jenkins_smi_hash.dart
@@ -3,22 +3,20 @@
// BSD-style license that can be found in the LICENSE file.
part of dart.math;
-/**
- * This is the [Jenkins hash function][1] but using masking to keep
- * values in SMI range.
- *
- * [1]: http://en.wikipedia.org/wiki/Jenkins_hash_function
- *
- * Use:
- * Hash each value with the hash of the previous value, then get the final
- * hash by calling finish.
- *
- * var hash = 0;
- * for (var value in values) {
- * hash = JenkinsSmiHash.combine(hash, value.hashCode);
- * }
- * hash = JenkinsSmiHash.finish(hash);
- */
+/// This is the [Jenkins hash function][1] but using masking to keep
+/// values in SMI range.
+///
+/// [1]: http://en.wikipedia.org/wiki/Jenkins_hash_function
+///
+/// Use:
+/// Hash each value with the hash of the previous value, then get the final
+/// hash by calling finish.
+///
+/// var hash = 0;
+/// for (var value in values) {
+/// hash = JenkinsSmiHash.combine(hash, value.hashCode);
+/// }
+/// hash = JenkinsSmiHash.finish(hash);
class _JenkinsSmiHash {
// TODO(11617): This class should be optimized and standardized elsewhere.
diff --git a/sdk/lib/math/math.dart b/sdk/lib/math/math.dart
index f33a7a8..548fb59 100644
--- a/sdk/lib/math/math.dart
+++ b/sdk/lib/math/math.dart
@@ -2,15 +2,13 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-/**
- * Mathematical constants and functions, plus a random number generator.
- *
- * To use this library in your code:
- *
- * import 'dart:math';
- *
- * {@category Core}
- */
+/// Mathematical constants and functions, plus a random number generator.
+///
+/// To use this library in your code:
+///
+/// import 'dart:math';
+///
+/// {@category Core}
library dart.math;
part "jenkins_smi_hash.dart";
@@ -18,204 +16,164 @@
part "random.dart";
part "rectangle.dart";
-/**
- * Base of the natural logarithms.
- *
- * Typically written as "e".
- */
+/// Base of the natural logarithms.
+///
+/// Typically written as "e".
const double e = 2.718281828459045;
-/**
- * Natural logarithm of 10.
- *
- * The natural logarithm of 10 is the number such that `pow(E, LN10) == 10`.
- * This value is not exact, but it is the closest representable double to the
- * exact mathematical value.
- */
+/// Natural logarithm of 10.
+///
+/// The natural logarithm of 10 is the number such that `pow(E, LN10) == 10`.
+/// This value is not exact, but it is the closest representable double to the
+/// exact mathematical value.
const double ln10 = 2.302585092994046;
-/**
- * Natural logarithm of 2.
- *
- * The natural logarithm of 2 is the number such that `pow(E, LN2) == 2`.
- * This value is not exact, but it is the closest representable double to the
- * exact mathematical value.
- */
+/// Natural logarithm of 2.
+///
+/// The natural logarithm of 2 is the number such that `pow(E, LN2) == 2`.
+/// This value is not exact, but it is the closest representable double to the
+/// exact mathematical value.
const double ln2 = 0.6931471805599453;
-/**
- * Base-2 logarithm of [e].
- */
+/// Base-2 logarithm of [e].
const double log2e = 1.4426950408889634;
-/**
- * Base-10 logarithm of [e].
- */
+/// Base-10 logarithm of [e].
const double log10e = 0.4342944819032518;
-/**
- * The PI constant.
- */
+/// The PI constant.
const double pi = 3.1415926535897932;
-/**
- * Square root of 1/2.
- */
+/// Square root of 1/2.
const double sqrt1_2 = 0.7071067811865476;
-/**
- * Square root of 2.
- */
+/// Square root of 2.
const double sqrt2 = 1.4142135623730951;
-/**
- * Returns the lesser of two numbers.
- *
- * Returns NaN if either argument is NaN.
- * The lesser of `-0.0` and `0.0` is `-0.0`.
- * If the arguments are otherwise equal (including int and doubles with the
- * same mathematical value) then it is unspecified which of the two arguments
- * is returned.
- */
+/// Returns the lesser of two numbers.
+///
+/// Returns NaN if either argument is NaN.
+/// The lesser of `-0.0` and `0.0` is `-0.0`.
+/// If the arguments are otherwise equal (including int and doubles with the
+/// same mathematical value) then it is unspecified which of the two arguments
+/// is returned.
external T min<T extends num>(T a, T b);
-/**
- * Returns the larger of two numbers.
- *
- * Returns NaN if either argument is NaN.
- * The larger of `-0.0` and `0.0` is `0.0`. If the arguments are
- * otherwise equal (including int and doubles with the same mathematical value)
- * then it is unspecified which of the two arguments is returned.
- */
+/// Returns the larger of two numbers.
+///
+/// Returns NaN if either argument is NaN.
+/// The larger of `-0.0` and `0.0` is `0.0`. If the arguments are
+/// otherwise equal (including int and doubles with the same mathematical value)
+/// then it is unspecified which of the two arguments is returned.
external T max<T extends num>(T a, T b);
-/**
- * A variant of [atan].
- *
- * Converts both arguments to [double]s.
- *
- * Returns the angle in radians between the positive x-axis
- * and the vector ([b],[a]).
- * The result is in the range -PI..PI.
- *
- * If [b] is positive, this is the same as `atan(b/a)`.
- *
- * The result is negative when [a] is negative (including when [a] is the
- * double -0.0).
- *
- * If [a] is equal to zero, the vector ([b],[a]) is considered parallel to
- * the x-axis, even if [b] is also equal to zero. The sign of [b] determines
- * the direction of the vector along the x-axis.
- *
- * Returns NaN if either argument is NaN.
- */
+/// A variant of [atan].
+///
+/// Converts both arguments to [double]s.
+///
+/// Returns the angle in radians between the positive x-axis
+/// and the vector ([b],[a]).
+/// The result is in the range -PI..PI.
+///
+/// If [b] is positive, this is the same as `atan(b/a)`.
+///
+/// The result is negative when [a] is negative (including when [a] is the
+/// double -0.0).
+///
+/// If [a] is equal to zero, the vector ([b],[a]) is considered parallel to
+/// the x-axis, even if [b] is also equal to zero. The sign of [b] determines
+/// the direction of the vector along the x-axis.
+///
+/// Returns NaN if either argument is NaN.
external double atan2(num a, num b);
-/**
- * Returns [x] to the power of [exponent].
- *
- * If [x] is an [int] and [exponent] is a non-negative [int], the result is
- * an [int], otherwise both arguments are converted to doubles first, and the
- * result is a [double].
- *
- * For integers, the power is always equal to the mathematical result of `x` to
- * the power `exponent`, only limited by the available memory.
- *
- * For doubles, `pow(x, y)` handles edge cases as follows:
- *
- * - if `y` is zero (0.0 or -0.0), the result is always 1.0.
- * - if `x` is 1.0, the result is always 1.0.
- * - otherwise, if either `x` or `y` is NaN then the result is NaN.
- * - if `x` is negative (but not -0.0) and `y` is a finite non-integer, the
- * result is NaN.
- * - if `x` is Infinity and `y` is negative, the result is 0.0.
- * - if `x` is Infinity and `y` is positive, the result is Infinity.
- * - if `x` is 0.0 and `y` is negative, the result is Infinity.
- * - if `x` is 0.0 and `y` is positive, the result is 0.0.
- * - if `x` is -Infinity or -0.0 and `y` is an odd integer, then the result is
- * `-pow(-x ,y)`.
- * - if `x` is -Infinity or -0.0 and `y` is not an odd integer, then the result
- * is the same as `pow(-x , y)`.
- * - if `y` is Infinity and the absolute value of `x` is less than 1, the
- * result is 0.0.
- * - if `y` is Infinity and `x` is -1, the result is 1.0.
- * - if `y` is Infinity and the absolute value of `x` is greater than 1,
- * the result is Infinity.
- * - if `y` is -Infinity, the result is `1/pow(x, Infinity)`.
- *
- * This corresponds to the `pow` function defined in the IEEE Standard 754-2008.
- *
- * Notice that the result may overflow. If integers are represented as 64-bit
- * numbers, an integer result may be truncated, and a double result may overflow
- * to positive or negative [double.infinity].
- */
+/// Returns [x] to the power of [exponent].
+///
+/// If [x] is an [int] and [exponent] is a non-negative [int], the result is
+/// an [int], otherwise both arguments are converted to doubles first, and the
+/// result is a [double].
+///
+/// For integers, the power is always equal to the mathematical result of `x` to
+/// the power `exponent`, only limited by the available memory.
+///
+/// For doubles, `pow(x, y)` handles edge cases as follows:
+///
+/// - if `y` is zero (0.0 or -0.0), the result is always 1.0.
+/// - if `x` is 1.0, the result is always 1.0.
+/// - otherwise, if either `x` or `y` is NaN then the result is NaN.
+/// - if `x` is negative (but not -0.0) and `y` is a finite non-integer, the
+/// result is NaN.
+/// - if `x` is Infinity and `y` is negative, the result is 0.0.
+/// - if `x` is Infinity and `y` is positive, the result is Infinity.
+/// - if `x` is 0.0 and `y` is negative, the result is Infinity.
+/// - if `x` is 0.0 and `y` is positive, the result is 0.0.
+/// - if `x` is -Infinity or -0.0 and `y` is an odd integer, then the result is
+/// `-pow(-x ,y)`.
+/// - if `x` is -Infinity or -0.0 and `y` is not an odd integer, then the result
+/// is the same as `pow(-x , y)`.
+/// - if `y` is Infinity and the absolute value of `x` is less than 1, the
+/// result is 0.0.
+/// - if `y` is Infinity and `x` is -1, the result is 1.0.
+/// - if `y` is Infinity and the absolute value of `x` is greater than 1,
+/// the result is Infinity.
+/// - if `y` is -Infinity, the result is `1/pow(x, Infinity)`.
+///
+/// This corresponds to the `pow` function defined in the IEEE Standard
+/// 754-2008.
+///
+/// Notice that the result may overflow. If integers are represented as 64-bit
+/// numbers, an integer result may be truncated, and a double result may
+/// overflow to positive or negative [double.infinity].
external num pow(num x, num exponent);
-/**
- * Converts [radians] to a [double] and returns the sine of the value.
- *
- * If [radians] is not a finite number, the result is NaN.
- */
+/// Converts [radians] to a [double] and returns the sine of the value.
+///
+/// If [radians] is not a finite number, the result is NaN.
external double sin(num radians);
-/**
- * Converts [radians] to a [double] and returns the cosine of the value.
- *
- * If [radians] is not a finite number, the result is NaN.
- */
+/// Converts [radians] to a [double] and returns the cosine of the value.
+///
+/// If [radians] is not a finite number, the result is NaN.
external double cos(num radians);
-/**
- * Converts [radians] to a [double] and returns the tangent of the value.
- *
- * The tangent function is equivalent to `sin(radians)/cos(radians)` and may be
- * infinite (positive or negative) when `cos(radians)` is equal to zero.
- * If [radians] is not a finite number, the result is NaN.
- */
+/// Converts [radians] to a [double] and returns the tangent of the value.
+///
+/// The tangent function is equivalent to `sin(radians)/cos(radians)` and may be
+/// infinite (positive or negative) when `cos(radians)` is equal to zero.
+/// If [radians] is not a finite number, the result is NaN.
external double tan(num radians);
-/**
- * Converts [x] to a [double] and returns its arc cosine in radians.
- *
- * Returns a value in the range 0..PI, or NaN if [x] is outside
- * the range -1..1.
- */
+/// Converts [x] to a [double] and returns its arc cosine in radians.
+///
+/// Returns a value in the range 0..PI, or NaN if [x] is outside
+/// the range -1..1.
external double acos(num x);
-/**
- * Converts [x] to a [double] and returns its arc sine in radians.
- *
- * Returns a value in the range -PI/2..PI/2, or NaN if [x] is outside
- * the range -1..1.
- */
+/// Converts [x] to a [double] and returns its arc sine in radians.
+///
+/// Returns a value in the range -PI/2..PI/2, or NaN if [x] is outside
+/// the range -1..1.
external double asin(num x);
-/**
- * Converts [x] to a [double] and returns its arc tangent in radians.
- *
- * Returns a value in the range -PI/2..PI/2, or NaN if [x] is NaN.
- */
+/// Converts [x] to a [double] and returns its arc tangent in radians.
+///
+/// Returns a value in the range -PI/2..PI/2, or NaN if [x] is NaN.
external double atan(num x);
-/**
- * Converts [x] to a [double] and returns the positive square root of the value.
- *
- * Returns -0.0 if [x] is -0.0, and NaN if [x] is otherwise negative or NaN.
- */
+/// Converts [x] to a [double] and returns the positive square root of the
+/// value.
+///
+/// Returns -0.0 if [x] is -0.0, and NaN if [x] is otherwise negative or NaN.
external double sqrt(num x);
-/**
- * Converts [x] to a [double] and returns the natural exponent, [e],
- * to the power [x].
- *
- * Returns NaN if [x] is NaN.
- */
+/// Converts [x] to a [double] and returns the natural exponent, [e],
+/// to the power [x].
+///
+/// Returns NaN if [x] is NaN.
external double exp(num x);
-/**
- * Converts [x] to a [double] and returns the natural logarithm of the value.
- *
- * Returns negative infinity if [x] is equal to zero.
- * Returns NaN if [x] is NaN or less than zero.
- */
+/// Converts [x] to a [double] and returns the natural logarithm of the value.
+///
+/// Returns negative infinity if [x] is equal to zero.
+/// Returns NaN if [x] is NaN or less than zero.
external double log(num x);
diff --git a/sdk/lib/math/point.dart b/sdk/lib/math/point.dart
index f627dcf..1015e7b 100644
--- a/sdk/lib/math/point.dart
+++ b/sdk/lib/math/point.dart
@@ -3,9 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
part of dart.math;
-/**
- * A utility class for representing two-dimensional positions.
- */
+/// A utility class for representing two-dimensional positions.
class Point<T extends num> {
final T x;
final T y;
@@ -16,13 +14,11 @@
String toString() => 'Point($x, $y)';
- /**
- * A `Point` is only equal to another `Point` with the same coordinates.
- *
- * This point is equal to `other` if, and only if,
- * `other` is a `Point` with
- * [x] equal to `other.x` and [y] equal to `other.y`.
- */
+ /// A `Point` is only equal to another `Point` with the same coordinates.
+ ///
+ /// This point is equal to `other` if, and only if,
+ /// `other` is a `Point` with
+ /// [x] equal to `other.x` and [y] equal to `other.y`.
bool operator ==(dynamic other) =>
// Cannot change parameter type to `Object` in case some class
// inherits the type and uses their argument dynamically.
@@ -30,58 +26,46 @@
int get hashCode => _JenkinsSmiHash.hash2(x.hashCode, y.hashCode);
- /**
- * Add [other] to `this`, as if both points were vectors.
- *
- * Returns the resulting "vector" as a Point.
- */
+ /// Add [other] to `this`, as if both points were vectors.
+ ///
+ /// Returns the resulting "vector" as a Point.
Point<T> operator +(Point<T> other) {
- return new Point<T>(x + other.x, y + other.y);
+ return Point<T>(x + other.x, y + other.y);
}
- /**
- * Subtract [other] from `this`, as if both points were vectors.
- *
- * Returns the resulting "vector" as a Point.
- */
+ /// Subtract [other] from `this`, as if both points were vectors.
+ ///
+ /// Returns the resulting "vector" as a Point.
Point<T> operator -(Point<T> other) {
- return new Point<T>(x - other.x, y - other.y);
+ return Point<T>(x - other.x, y - other.y);
}
- /**
- * Scale this point by [factor] as if it were a vector.
- *
- * *Important* *Note*: This function accepts a `num` as its argument only so
- * that you can scale Point<double> objects by an `int` factor. Because the
- * star operator always returns the same type of Point that originally called
- * it, passing in a double [factor] on a `Point<int>` _causes_ _a_
- * _runtime_ _error_ in checked mode.
- */
+ /// Scale this point by [factor] as if it were a vector.
+ ///
+ /// *Important* *Note*: This function accepts a `num` as its argument only so
+ /// that you can scale Point<double> objects by an `int` factor. Because the
+ /// star operator always returns the same type of Point that originally called
+ /// it, passing in a double [factor] on a `Point<int>` _causes_ _a_
+ /// _runtime_ _error_ in checked mode.
Point<T> operator *(num /*T|int*/ factor) {
- return new Point<T>((x * factor), (y * factor));
+ return Point<T>((x * factor), (y * factor));
}
- /**
- * Get the straight line (Euclidean) distance between the origin (0, 0) and
- * this point.
- */
+ /// Get the straight line (Euclidean) distance between the origin (0, 0) and
+ /// this point.
double get magnitude => sqrt(x * x + y * y);
- /**
- * Returns the distance between `this` and [other].
- */
+ /// Returns the distance between `this` and [other].
double distanceTo(Point<T> other) {
var dx = x - other.x;
var dy = y - other.y;
return sqrt(dx * dx + dy * dy);
}
- /**
- * Returns the squared distance between `this` and [other].
- *
- * Squared distances can be used for comparisons when the actual value is not
- * required.
- */
+ /// Returns the squared distance between `this` and [other].
+ ///
+ /// Squared distances can be used for comparisons when the actual value is not
+ /// required.
T squaredDistanceTo(Point<T> other) {
var dx = x - other.x;
var dy = y - other.y;
diff --git a/sdk/lib/math/random.dart b/sdk/lib/math/random.dart
index 99906cd..80e588b 100644
--- a/sdk/lib/math/random.dart
+++ b/sdk/lib/math/random.dart
@@ -11,40 +11,30 @@
///
/// Use the [Random.secure]() constructor for cryptographic purposes.
abstract class Random {
- /**
- * Creates a random number generator.
- *
- * The optional parameter [seed] is used to initialize the
- * internal state of the generator. The implementation of the
- * random stream can change between releases of the library.
- */
+ /// Creates a random number generator.
+ ///
+ /// The optional parameter [seed] is used to initialize the
+ /// internal state of the generator. The implementation of the
+ /// random stream can change between releases of the library.
external factory Random([int seed]);
- /**
- * Creates a cryptographically secure random number generator.
- *
- * If the program cannot provide a cryptographically secure
- * source of random numbers, it throws an [UnsupportedError].
- */
+ /// Creates a cryptographically secure random number generator.
+ ///
+ /// If the program cannot provide a cryptographically secure
+ /// source of random numbers, it throws an [UnsupportedError].
external factory Random.secure();
- /**
- * Generates a non-negative random integer uniformly distributed in the range
- * from 0, inclusive, to [max], exclusive.
- *
- * Implementation note: The default implementation supports [max] values
- * between 1 and (1<<32) inclusive.
- */
+ /// Generates a non-negative random integer uniformly distributed in the range
+ /// from 0, inclusive, to [max], exclusive.
+ ///
+ /// Implementation note: The default implementation supports [max] values
+ /// between 1 and (1<<32) inclusive.
int nextInt(int max);
- /**
- * Generates a non-negative random floating point value uniformly distributed
- * in the range from 0.0, inclusive, to 1.0, exclusive.
- */
+ /// Generates a non-negative random floating point value uniformly distributed
+ /// in the range from 0.0, inclusive, to 1.0, exclusive.
double nextDouble();
- /**
- * Generates a random boolean value.
- */
+ /// Generates a random boolean value.
bool nextBool();
}
diff --git a/sdk/lib/math/rectangle.dart b/sdk/lib/math/rectangle.dart
index 88e0eda..6e72036 100644
--- a/sdk/lib/math/rectangle.dart
+++ b/sdk/lib/math/rectangle.dart
@@ -3,35 +3,37 @@
// BSD-style license that can be found in the LICENSE file.
part of dart.math;
-/**
- * A base class for representing two-dimensional axis-aligned rectangles.
- *
- * This rectangle uses a left-handed Cartesian coordinate system, with x
- * directed to the right and y directed down, as per the convention in 2D
- * computer graphics.
- *
- * See also:
- * [W3C Coordinate Systems Specification](http://www.w3.org/TR/SVG/coords.html#InitialCoordinateSystem).
- *
- * The rectangle is the set of points with representable coordinates greater
- * than or equal to left/top, and with distance to left/top no greater than
- * width/height (to the limit of the precision of the coordinates).
- */
+/// A base class for representing two-dimensional axis-aligned rectangles.
+///
+/// This rectangle uses a left-handed Cartesian coordinate system, with x
+/// directed to the right and y directed down, as per the convention in 2D
+/// computer graphics.
+///
+/// See also:
+/// [W3C Coordinate Systems Specification](http://www.w3.org/TR/SVG/coords.html#InitialCoordinateSystem).
+///
+/// The rectangle is the set of points with representable coordinates greater
+/// than or equal to left/top, and with distance to left/top no greater than
+/// width/height (to the limit of the precision of the coordinates).
abstract class _RectangleBase<T extends num> {
const _RectangleBase();
- /** The x-coordinate of the left edge. */
+ /// The x-coordinate of the left edge.
T get left;
- /** The y-coordinate of the top edge. */
+
+ /// The y-coordinate of the top edge.
T get top;
- /** The width of the rectangle. */
+
+ /// The width of the rectangle.
T get width;
- /** The height of the rectangle. */
+
+ /// The height of the rectangle.
T get height;
- /** The x-coordinate of the right edge. */
+ /// The x-coordinate of the right edge.
T get right => left + width;
- /** The y-coordinate of the bottom edge. */
+
+ /// The y-coordinate of the bottom edge.
T get bottom => top + height;
String toString() {
@@ -50,15 +52,13 @@
int get hashCode => _JenkinsSmiHash.hash4(
left.hashCode, top.hashCode, right.hashCode, bottom.hashCode);
- /**
- * Computes the intersection of `this` and [other].
- *
- * The intersection of two axis-aligned rectangles, if any, is always another
- * axis-aligned rectangle.
- *
- * Returns the intersection of this and `other`, or `null` if they don't
- * intersect.
- */
+ /// Computes the intersection of `this` and [other].
+ ///
+ /// The intersection of two axis-aligned rectangles, if any, is always another
+ /// axis-aligned rectangle.
+ ///
+ /// Returns the intersection of this and `other`, or `null` if they don't
+ /// intersect.
Rectangle<T> intersection(Rectangle<T> other) {
var x0 = max(left, other.left);
var x1 = min(left + width, other.left + other.width);
@@ -68,15 +68,13 @@
var y1 = min(top + height, other.top + other.height);
if (y0 <= y1) {
- return new Rectangle<T>(x0, y0, x1 - x0, y1 - y0);
+ return Rectangle<T>(x0, y0, x1 - x0, y1 - y0);
}
}
return null;
}
- /**
- * Returns true if `this` intersects [other].
- */
+ /// Returns true if `this` intersects [other].
bool intersects(Rectangle<num> other) {
return (left <= other.left + other.width &&
other.left <= left + width &&
@@ -84,9 +82,7 @@
other.top <= top + height);
}
- /**
- * Returns a new rectangle which completely contains `this` and [other].
- */
+ /// Returns a new rectangle which completely contains `this` and [other].
Rectangle<T> boundingBox(Rectangle<T> other) {
var right = max(this.left + this.width, other.left + other.width);
var bottom = max(this.top + this.height, other.top + other.height);
@@ -94,12 +90,10 @@
var left = min(this.left, other.left);
var top = min(this.top, other.top);
- return new Rectangle<T>(left, top, right - left, bottom - top);
+ return Rectangle<T>(left, top, right - left, bottom - top);
}
- /**
- * Tests whether `this` entirely contains [another].
- */
+ /// Tests whether `this` entirely contains [another].
bool containsRectangle(Rectangle<num> another) {
return left <= another.left &&
left + width >= another.left + another.width &&
@@ -107,9 +101,7 @@
top + height >= another.top + another.height;
}
- /**
- * Tests whether [another] is inside or along the edges of `this`.
- */
+ /// Tests whether [another] is inside or along the edges of `this`.
bool containsPoint(Point<num> another) {
return another.x >= left &&
another.x <= left + width &&
@@ -117,158 +109,138 @@
another.y <= top + height;
}
- Point<T> get topLeft => new Point<T>(this.left, this.top);
- Point<T> get topRight => new Point<T>(this.left + this.width, this.top);
+ Point<T> get topLeft => Point<T>(this.left, this.top);
+ Point<T> get topRight => Point<T>(this.left + this.width, this.top);
Point<T> get bottomRight =>
- new Point<T>(this.left + this.width, this.top + this.height);
- Point<T> get bottomLeft => new Point<T>(this.left, this.top + this.height);
+ Point<T>(this.left + this.width, this.top + this.height);
+ Point<T> get bottomLeft => Point<T>(this.left, this.top + this.height);
}
-/**
- * A class for representing two-dimensional rectangles whose properties are
- * immutable.
- */
+/// A class for representing two-dimensional rectangles whose properties are
+/// immutable.
class Rectangle<T extends num> extends _RectangleBase<T> {
final T left;
final T top;
final T width;
final T height;
- /**
- * Create a rectangle spanned by `(left, top)` and `(left+width, top+height)`.
- *
- * The rectangle contains the points
- * with x-coordinate between `left` and `left + width`, and
- * with y-coordinate between `top` and `top + height`, both inclusive.
- *
- * The `width` and `height` should be non-negative.
- * If `width` or `height` are negative, they are clamped to zero.
- *
- * If `width` and `height` are zero, the "rectangle" comprises only the single
- * point `(left, top)`.
- */
+ /// Create a rectangle spanned by `(left, top)` and
+ /// `(left+width, top+height)`.
+ ///
+ /// The rectangle contains the points
+ /// with x-coordinate between `left` and `left + width`, and
+ /// with y-coordinate between `top` and `top + height`, both inclusive.
+ ///
+ /// The `width` and `height` should be non-negative.
+ /// If `width` or `height` are negative, they are clamped to zero.
+ ///
+ /// If `width` and `height` are zero, the "rectangle" comprises only the
+ /// single point `(left, top)`.
const Rectangle(this.left, this.top, T width, T height)
: this.width = (width < 0) ? -width * 0 : width, // Inline _clampToZero.
this.height = (height < 0) ? -height * 0 : height;
- /**
- * Create a rectangle spanned by the points [a] and [b];
- *
- * The rectangle contains the points
- * with x-coordinate between `a.x` and `b.x`, and
- * with y-coordinate between `a.y` and `b.y`, both inclusive.
- *
- * If the distance between `a.x` and `b.x` is not representable
- * (which can happen if one or both is a double),
- * the actual right edge might be slightly off from `max(a.x, b.x)`.
- * Similar for the y-coordinates and the bottom edge.
- */
+ /// Create a rectangle spanned by the points [a] and [b];
+ ///
+ /// The rectangle contains the points
+ /// with x-coordinate between `a.x` and `b.x`, and
+ /// with y-coordinate between `a.y` and `b.y`, both inclusive.
+ ///
+ /// If the distance between `a.x` and `b.x` is not representable
+ /// (which can happen if one or both is a double),
+ /// the actual right edge might be slightly off from `max(a.x, b.x)`.
+ /// Similar for the y-coordinates and the bottom edge.
factory Rectangle.fromPoints(Point<T> a, Point<T> b) {
T left = min(a.x, b.x);
T width = max(a.x, b.x) - left;
T top = min(a.y, b.y);
T height = max(a.y, b.y) - top;
- return new Rectangle<T>(left, top, width, height);
+ return Rectangle<T>(left, top, width, height);
}
}
-/**
- * A class for representing two-dimensional axis-aligned rectangles with mutable
- * properties.
- */
+/// A class for representing two-dimensional axis-aligned rectangles with
+/// mutable properties.
class MutableRectangle<T extends num> extends _RectangleBase<T>
implements Rectangle<T> {
- /**
- * The x-coordinate of the left edge.
- *
- * Setting the value will move the rectangle without changing its width.
- */
+ /// The x-coordinate of the left edge.
+ ///
+ /// Setting the value will move the rectangle without changing its width.
T left;
- /**
- * The y-coordinate of the left edge.
- *
- * Setting the value will move the rectangle without changing its height.
- */
+
+ /// The y-coordinate of the left edge.
+ ///
+ /// Setting the value will move the rectangle without changing its height.
T top;
T _width;
T _height;
- /**
- * Create a mutable rectangle spanned by `(left, top)` and
- * `(left+width, top+height)`.
- *
- * The rectangle contains the points
- * with x-coordinate between `left` and `left + width`, and
- * with y-coordinate between `top` and `top + height`, both inclusive.
- *
- * The `width` and `height` should be non-negative.
- * If `width` or `height` are negative, they are clamped to zero.
- *
- * If `width` and `height` are zero, the "rectangle" comprises only the single
- * point `(left, top)`.
- */
+ /// Create a mutable rectangle spanned by `(left, top)` and
+ /// `(left+width, top+height)`.
+ ///
+ /// The rectangle contains the points
+ /// with x-coordinate between `left` and `left + width`, and
+ /// with y-coordinate between `top` and `top + height`, both inclusive.
+ ///
+ /// The `width` and `height` should be non-negative.
+ /// If `width` or `height` are negative, they are clamped to zero.
+ ///
+ /// If `width` and `height` are zero, the "rectangle" comprises only the
+ /// single point `(left, top)`.
MutableRectangle(this.left, this.top, T width, T height)
: this._width = (width < 0) ? _clampToZero<T>(width) : width,
this._height = (height < 0) ? _clampToZero<T>(height) : height;
- /**
- * Create a mutable rectangle spanned by the points [a] and [b];
- *
- * The rectangle contains the points
- * with x-coordinate between `a.x` and `b.x`, and
- * with y-coordinate between `a.y` and `b.y`, both inclusive.
- *
- * If the distance between `a.x` and `b.x` is not representable
- * (which can happen if one or both is a double),
- * the actual right edge might be slightly off from `max(a.x, b.x)`.
- * Similar for the y-coordinates and the bottom edge.
- */
+ /// Create a mutable rectangle spanned by the points [a] and [b];
+ ///
+ /// The rectangle contains the points
+ /// with x-coordinate between `a.x` and `b.x`, and
+ /// with y-coordinate between `a.y` and `b.y`, both inclusive.
+ ///
+ /// If the distance between `a.x` and `b.x` is not representable
+ /// (which can happen if one or both is a double),
+ /// the actual right edge might be slightly off from `max(a.x, b.x)`.
+ /// Similar for the y-coordinates and the bottom edge.
factory MutableRectangle.fromPoints(Point<T> a, Point<T> b) {
T left = min(a.x, b.x);
T width = max(a.x, b.x) - left;
T top = min(a.y, b.y);
T height = max(a.y, b.y) - top;
- return new MutableRectangle<T>(left, top, width, height);
+ return MutableRectangle<T>(left, top, width, height);
}
T get width => _width;
- /**
- * Sets the width of the rectangle.
- *
- * The width must be non-negative.
- * If a negative width is supplied, it is clamped to zero.
- *
- * Setting the value will change the right edge of the rectangle,
- * but will not change [left].
- */
- void set width(T width) {
+ /// Sets the width of the rectangle.
+ ///
+ /// The width must be non-negative.
+ /// If a negative width is supplied, it is clamped to zero.
+ ///
+ /// Setting the value will change the right edge of the rectangle,
+ /// but will not change [left].
+ set width(T width) {
if (width < 0) width = _clampToZero<T>(width);
_width = width;
}
T get height => _height;
- /**
- * Sets the height of the rectangle.
- *
- * The height must be non-negative.
- * If a negative height is supplied, it is clamped to zero.
- *
- * Setting the value will change the bottom edge of the rectangle,
- * but will not change [top].
- */
- void set height(T height) {
+ /// Sets the height of the rectangle.
+ ///
+ /// The height must be non-negative.
+ /// If a negative height is supplied, it is clamped to zero.
+ ///
+ /// Setting the value will change the bottom edge of the rectangle,
+ /// but will not change [top].
+ set height(T height) {
if (height < 0) height = _clampToZero<T>(height);
_height = height;
}
}
-/**
- * Converts a negative [int] or [double] to a zero-value of the same type.
- *
- * Returns `0` if value is int, `0.0` if value is double.
- */
+/// Converts a negative [int] or [double] to a zero-value of the same type.
+///
+/// Returns `0` if value is int, `0.0` if value is double.
T _clampToZero<T extends num>(T value) {
assert(value < 0);
return -value * 0;