| 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 $LIBRARYNAME; |
| 6 | 6 |
| 7 /** | 7 @DocsEditable |
| 8 * A class for representing two-dimensional rectangles. | 8 $(ANNOTATIONS)class $CLASSNAME implements Rect$IMPLEMENTS$NATIVESPEC { |
| 9 */ | |
| 10 class Rect { | |
| 11 final num left; | |
| 12 final num top; | |
| 13 final num width; | |
| 14 final num height; | |
| 15 | |
| 16 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 | |
| 25 factory Rect.fromPoints(Point a, Point b) { | |
| 26 var left; | |
| 27 var width; | |
| 28 if (a.x < b.x) { | |
| 29 left = a.x; | |
| 30 width = b.x - left; | |
| 31 } else { | |
| 32 left = b.x; | |
| 33 width = a.x - left; | |
| 34 } | |
| 35 var top; | |
| 36 var height; | |
| 37 if (a.y < b.y) { | |
| 38 top = a.y; | |
| 39 height = b.y - top; | |
| 40 } else { | |
| 41 top = b.y; | |
| 42 height = a.y - top; | |
| 43 } | |
| 44 | |
| 45 return new Rect(left, top, width, height); | |
| 46 } | |
| 47 | |
| 48 num get right => left + width; | |
| 49 num get bottom => top + height; | |
| 50 | 9 |
| 51 // NOTE! All code below should be common with Rect. | 10 // NOTE! All code below should be common with Rect. |
| 52 // TODO: implement with mixins when available. | 11 // TODO(blois): implement with mixins when available. |
| 53 | 12 |
| 54 String toString() { | 13 String toString() { |
| 55 return '($left, $top, $width, $height)'; | 14 return '($left, $top, $width, $height)'; |
| 56 } | 15 } |
| 57 | 16 |
| 58 bool operator ==(other) { | 17 bool operator ==(other) { |
| 59 if (other is !Rect) return false; | 18 if (other is !Rect) return false; |
| 60 return left == other.left && top == other.top && width == other.width && | 19 return left == other.left && top == other.top && width == other.width && |
| 61 height == other.height; | 20 height == other.height; |
| 62 } | 21 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 /** | 91 /** |
| 133 * Truncates coordinates to integers and returns the result as a new | 92 * Truncates coordinates to integers and returns the result as a new |
| 134 * rectangle. | 93 * rectangle. |
| 135 */ | 94 */ |
| 136 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(), | 95 Rect toInt() => new Rect(left.toInt(), top.toInt(), width.toInt(), |
| 137 height.toInt()); | 96 height.toInt()); |
| 138 | 97 |
| 139 Point get topLeft => new Point(this.left, this.top); | 98 Point get topLeft => new Point(this.left, this.top); |
| 140 Point get bottomRight => new Point(this.left + this.width, | 99 Point get bottomRight => new Point(this.left + this.width, |
| 141 this.top + this.height); | 100 this.top + this.height); |
| 142 } | 101 $!MEMBERS} |
| OLD | NEW |