| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.sky; | 5 part of dart.sky; |
| 6 | 6 |
| 7 /// Holds 4 floating-point coordinates for a rectangle. | 7 /// Holds 4 floating-point coordinates for a rectangle. |
| 8 class Rect { | 8 class Rect { |
| 9 Rect(); | 9 Rect(); |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 ..[2] = left + width | 23 ..[2] = left + width |
| 24 ..[3] = top + height; | 24 ..[3] = top + height; |
| 25 } | 25 } |
| 26 | 26 |
| 27 final Float32List _value = new Float32List(4); | 27 final Float32List _value = new Float32List(4); |
| 28 double get left => _value[0]; | 28 double get left => _value[0]; |
| 29 double get top => _value[1]; | 29 double get top => _value[1]; |
| 30 double get right => _value[2]; | 30 double get right => _value[2]; |
| 31 double get bottom => _value[3]; | 31 double get bottom => _value[3]; |
| 32 | 32 |
| 33 Point get center => new Point(left + right / 2.0, top + bottom / 2.0); | 33 double get width => right - left; |
| 34 double get height => bottom - top; |
| 35 |
| 36 Size get size => new Size(width, height); |
| 37 |
| 38 double get shortestSide { |
| 39 double w = width.abs(); |
| 40 double h = height.abs(); |
| 41 return w < h ? w : h; |
| 42 } |
| 43 |
| 44 Point get center => new Point(left + width / 2.0, top + height / 2.0); |
| 34 Point get topLeft => new Point(left, top); | 45 Point get topLeft => new Point(left, top); |
| 35 Point get topRight => new Point(right, top); | 46 Point get topRight => new Point(right, top); |
| 36 Point get bottomLeft => new Point(left, bottom); | 47 Point get bottomLeft => new Point(left, bottom); |
| 37 Point get bottomRight => new Point(right, bottom); | 48 Point get bottomRight => new Point(right, bottom); |
| 38 | 49 |
| 39 Size get size => new Size(right - left, bottom - top); | |
| 40 | |
| 41 // Rects are inclusive of the top and left edges but exclusive of the bottom | 50 // Rects are inclusive of the top and left edges but exclusive of the bottom |
| 42 // right edges. | 51 // right edges. |
| 43 bool contains(Point point) { | 52 bool contains(Point point) { |
| 44 return point.x >= left && point.x < right && point.y >= top && point.y < bot
tom; | 53 return point.x >= left && point.x < right && point.y >= top && point.y < bot
tom; |
| 45 } | 54 } |
| 46 | 55 |
| 47 bool operator ==(other) { | 56 bool operator ==(other) { |
| 48 if (other is! Rect) | 57 if (other is! Rect) |
| 49 return false; | 58 return false; |
| 50 for (var i = 0; i < 4; ++i) { | 59 for (var i = 0; i < 4; ++i) { |
| 51 if (_value[i] != other._value[i]) | 60 if (_value[i] != other._value[i]) |
| 52 return false; | 61 return false; |
| 53 } | 62 } |
| 54 return true; | 63 return true; |
| 55 } | 64 } |
| 56 int get hashCode =>_value.fold(373, (value, item) => (37 * value + item.hashCo
de)); | 65 int get hashCode =>_value.fold(373, (value, item) => (37 * value + item.hashCo
de)); |
| 57 String toString() => "Rect.fromLTRB($left, $top, $right, $bottom)"; | 66 String toString() => "Rect.fromLTRB($left, $top, $right, $bottom)"; |
| 58 } | 67 } |
| OLD | NEW |