Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 part of dart.math; | 4 part of dart.math; |
| 5 | 5 |
| 6 /** | 6 /** |
| 7 * A base class for representing two-dimensional axis-aligned rectangles. | 7 * A base class for representing two-dimensional axis-aligned rectangles. |
| 8 * | 8 * |
| 9 * This rectangle uses a left-handed Cartesian coordinate system, with x | 9 * This rectangle uses a left-handed Cartesian coordinate system, with x |
| 10 * directed to the right and y directed down, as per the convention in 2D | 10 * directed to the right and y directed down, as per the convention in 2D |
| 11 * computer graphics. | 11 * computer graphics. |
| 12 * | 12 * |
| 13 * See also: | 13 * See also: |
| 14 * [W3C Coordinate Systems Specification](http://www.w3.org/TR/SVG/coords.htm l#InitialCoordinateSystem). | 14 * [W3C Coordinate Systems Specification](http://www.w3.org/TR/SVG/coords.htm l#InitialCoordinateSystem). |
| 15 * | |
| 16 * The rectangle is the set of points with representable coordinates greater | |
| 17 * than or equal to left/top, and with distance to left/top no greater than | |
| 18 * width/height (to the limit of the precission of the coordinates). | |
| 15 */ | 19 */ |
| 16 abstract class _RectangleBase<T extends num> { | 20 abstract class _RectangleBase<T extends num> { |
| 17 const _RectangleBase(); | 21 const _RectangleBase(); |
| 18 | 22 |
| 19 /** The x-coordinate of the left edge. */ | 23 /** The x-coordinate of the left edge. */ |
| 20 T get left; | 24 T get left; |
| 21 /** The y-coordinate of the top edge. */ | 25 /** The y-coordinate of the top edge. */ |
| 22 T get top; | 26 T get top; |
| 23 /** The `width` of the rectangle. */ | 27 /** The `width` of the rectangle. */ |
| 24 T get width; | 28 T get width; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 /** | 127 /** |
| 124 * A class for representing two-dimensional rectangles whose properties are | 128 * A class for representing two-dimensional rectangles whose properties are |
| 125 * immutable. | 129 * immutable. |
| 126 */ | 130 */ |
| 127 class Rectangle<T extends num> extends _RectangleBase<T> { | 131 class Rectangle<T extends num> extends _RectangleBase<T> { |
| 128 final T left; | 132 final T left; |
| 129 final T top; | 133 final T top; |
| 130 final T width; | 134 final T width; |
| 131 final T height; | 135 final T height; |
| 132 | 136 |
| 133 const Rectangle(this.left, this.top, this.width, this.height); | 137 const Rectangle(left, top, width, height) |
| 138 : left = (width >= 0) ? left : left + width, | |
| 139 width = (width >= 0) ? width : -width, | |
| 140 top = (height >= 0) ? top : top + height, | |
| 141 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
| |
| 134 | 142 |
| 135 factory Rectangle.fromPoints(Point<T> a, Point<T> b) { | 143 factory Rectangle.fromPoints(Point<T> a, Point<T> b) { |
| 136 T left = min(a.x, b.x); | 144 T left = min(a.x, b.x); |
| 137 T width = max(a.x, b.x) - left; | 145 T width = max(a.x, b.x) - left; |
| 138 T top = min(a.y, b.y); | 146 T top = min(a.y, b.y); |
| 139 T height = max(a.y, b.y) - top; | 147 T height = max(a.y, b.y) - top; |
| 140 return new Rectangle<T>(left, top, width, height); | 148 return new Rectangle<T>(left, top, width, height); |
| 141 } | 149 } |
| 142 } | 150 } |
| 143 | 151 |
| 144 /** | 152 /** |
| 145 * A class for representing two-dimensional axis-aligned rectangles with mutable | 153 * A class for representing two-dimensional axis-aligned rectangles with mutable |
| 146 * properties. | 154 * properties. |
| 147 */ | 155 */ |
| 148 class MutableRectangle<T extends num> extends _RectangleBase<T> | 156 class MutableRectangle<T extends num> extends _RectangleBase<T> |
| 149 implements Rectangle<T> { | 157 implements Rectangle<T> { |
| 150 T left; | 158 T left; |
| 151 T top; | 159 T top; |
| 152 T width; | 160 T width; |
| 153 T height; | 161 T height; |
| 154 | 162 |
| 155 MutableRectangle(this.left, this.top, this.width, this.height); | 163 MutableRectangle(left, top, width, height) |
| 164 : left = (width >= 0) ? left : left + width, | |
| 165 width = (width >= 0) ? width : -width, | |
| 166 top = (height >= 0) ? top : top + height, | |
| 167 height = (height >= 0) ? height : -height; | |
| 156 | 168 |
| 157 factory MutableRectangle.fromPoints(Point<T> a, Point<T> b) { | 169 factory MutableRectangle.fromPoints(Point<T> a, Point<T> b) { |
| 158 T left = min(a.x, b.x); | 170 T left = min(a.x, b.x); |
| 159 T width = max(a.x, b.x) - left; | 171 T width = max(a.x, b.x) - left; |
| 160 T top = min(a.y, b.y); | 172 T top = min(a.y, b.y); |
| 161 T height = max(a.y, b.y) - top; | 173 T height = max(a.y, b.y) - top; |
| 162 return new MutableRectangle<T>(left, top, width, height); | 174 return new MutableRectangle<T>(left, top, width, height); |
| 163 } | 175 } |
| 164 } | 176 } |
| OLD | NEW |