Chromium Code Reviews| Index: sdk/lib/math/rectangle.dart |
| diff --git a/sdk/lib/math/rectangle.dart b/sdk/lib/math/rectangle.dart |
| index e0a3b9870fce43a6644f1baa255ffe8f6ca82ac0..fd6b7bec2b0e1a5ee9cb7f222a5bd33019937ee2 100644 |
| --- a/sdk/lib/math/rectangle.dart |
| +++ b/sdk/lib/math/rectangle.dart |
| @@ -12,6 +12,10 @@ part of dart.math; |
| * |
| * 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 precission of the coordinates). |
| */ |
| abstract class _RectangleBase<T extends num> { |
| const _RectangleBase(); |
| @@ -130,7 +134,11 @@ class Rectangle<T extends num> extends _RectangleBase<T> { |
| final T width; |
| final T height; |
| - const Rectangle(this.left, this.top, this.width, this.height); |
| + const Rectangle(left, top, width, height) |
| + : left = (width >= 0) ? left : left + width, |
| + width = (width >= 0) ? width : -width, |
| + top = (height >= 0) ? top : top + height, |
| + height = (height >= 0) ? height : -height; |
|
srdjan
2014/01/28 16:47:41
This looks very unreadable to me (same names for a
Lasse Reichstein Nielsen
2014/01/28 17:49:59
Yes, they should be typed "T", and I should write
|
| factory Rectangle.fromPoints(Point<T> a, Point<T> b) { |
| T left = min(a.x, b.x); |
| @@ -145,14 +153,18 @@ class Rectangle<T extends num> extends _RectangleBase<T> { |
| * A class for representing two-dimensional axis-aligned rectangles with mutable |
| * properties. |
| */ |
| -class MutableRectangle<T extends num> extends _RectangleBase<T> |
| - implements Rectangle<T> { |
| +class MutableRectangle<T extends num> extends _RectangleBase<T> |
| + implements Rectangle<T> { |
| T left; |
| T top; |
| T width; |
| T height; |
| - MutableRectangle(this.left, this.top, this.width, this.height); |
| + MutableRectangle(left, top, width, height) |
| + : left = (width >= 0) ? left : left + width, |
| + width = (width >= 0) ? width : -width, |
| + top = (height >= 0) ? top : top + height, |
| + height = (height >= 0) ? height : -height; |
| factory MutableRectangle.fromPoints(Point<T> a, Point<T> b) { |
| T left = min(a.x, b.x); |