| 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 | 4 |
| 5 part of html; | 5 part of html; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A class for representing two-dimensional rectangles. | 8 * A class for representing two-dimensional rectangles. |
| 9 */ | 9 */ |
| 10 class Rect { | 10 class Rect { |
| 11 final num left; | 11 final num left; |
| 12 final num top; | 12 final num top; |
| 13 final num width; | 13 final num width; |
| 14 final num height; | 14 final num height; |
| 15 | 15 |
| 16 Rect(this.left, this.top, this.width, this.height) { | 16 const Rect(this.left, this.top, this.width, this.height); |
| 17 if (width < 0) { | |
| 18 throw new ArgumentError(width); | |
| 19 } | |
| 20 if (height < 0) { | |
| 21 throw new ArgumentError(height); | |
| 22 } | |
| 23 } | |
| 24 | 17 |
| 25 factory Rect.fromPoints(Point a, Point b) { | 18 factory Rect.fromPoints(Point a, Point b) { |
| 26 var left; | 19 var left; |
| 27 var width; | 20 var width; |
| 28 if (a.x < b.x) { | 21 if (a.x < b.x) { |
| 29 left = a.x; | 22 left = a.x; |
| 30 width = b.x - left; | 23 width = b.x - left; |
| 31 } else { | 24 } else { |
| 32 left = b.x; | 25 left = b.x; |
| 33 width = a.x - left; | 26 width = a.x - left; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 * Truncates coordinates to integers and returns the result as a new | 126 * Truncates coordinates to integers and returns the result as a new |
| 134 * rectangle. | 127 * rectangle. |
| 135 */ | 128 */ |
| 136 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(), | 129 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(), |
| 137 height.toInt()); | 130 height.toInt()); |
| 138 | 131 |
| 139 Point get topLeft => new Point(this.left, this.top); | 132 Point get topLeft => new Point(this.left, this.top); |
| 140 Point get bottomRight => new Point(this.left + this.width, | 133 Point get bottomRight => new Point(this.left + this.width, |
| 141 this.top + this.height); | 134 this.top + this.height); |
| 142 } | 135 } |
| OLD | NEW |