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 final Float32List _value = new Float32List(4); | 9 final Float32List _value = new Float32List(4); |
10 double get left => _value[0]; | 10 double get left => _value[0]; |
(...skipping 11 matching lines...) Expand all Loading... |
22 ..[3] = point.y + size.height; | 22 ..[3] = point.y + size.height; |
23 } | 23 } |
24 | 24 |
25 Rect.fromSize(Size size) { | 25 Rect.fromSize(Size size) { |
26 _value | 26 _value |
27 ..[2] = size.width | 27 ..[2] = size.width |
28 ..[3] = size.height; | 28 ..[3] = size.height; |
29 } | 29 } |
30 | 30 |
31 Rect.fromLTRB(double left, double top, double right, double bottom) { | 31 Rect.fromLTRB(double left, double top, double right, double bottom) { |
32 setLTRB(left, top, right, bottom); | 32 _value |
| 33 ..[0] = left |
| 34 ..[1] = top |
| 35 ..[2] = right |
| 36 ..[3] = bottom; |
33 } | 37 } |
34 | 38 |
35 Point get upperLeft => new Point(left, top); | 39 Point get upperLeft => new Point(left, top); |
36 Point get lowerRight => new Point(right, bottom); | 40 Point get lowerRight => new Point(right, bottom); |
37 Point get center => new Point(left + right / 2.0, top + bottom / 2.0); | 41 Point get center => new Point(left + right / 2.0, top + bottom / 2.0); |
38 | 42 |
39 Size get size => new Size(right - left, bottom - top); | 43 Size get size => new Size(right - left, bottom - top); |
40 | 44 |
41 // Rects are inclusive of the top and left edges but exclusive of the bottom | 45 // Rects are inclusive of the top and left edges but exclusive of the bottom |
42 // right edges. | 46 // right edges. |
43 bool contains(Point point) => | 47 bool contains(Point point) => |
44 point.x >= left && point.x < right && point.y >= top && point.y < bottom; | 48 point.x >= left && point.x < right && point.y >= top && point.y < bottom; |
45 | 49 |
46 void setLTRB(double left, double top, double right, double bottom) { | |
47 _value | |
48 ..[0] = left | |
49 ..[1] = top | |
50 ..[2] = right | |
51 ..[3] = bottom; | |
52 } | |
53 | |
54 bool operator ==(other) { | 50 bool operator ==(other) { |
55 if (!(other is Rect)) return false; | 51 if (!(other is Rect)) return false; |
56 for (var i = 0; i < 4; ++i) { | 52 for (var i = 0; i < 4; ++i) { |
57 if (_value[i] != other._value[i]) return false; | 53 if (_value[i] != other._value[i]) return false; |
58 } | 54 } |
59 return true; | 55 return true; |
60 } | 56 } |
61 int get hashCode { | 57 int get hashCode { |
62 return _value.fold(373, (value, item) => (37 * value + item.hashCode)); | 58 return _value.fold(373, (value, item) => (37 * value + item.hashCode)); |
63 } | 59 } |
64 String toString() => "Rect.LTRB($left, $top, $right, $bottom)"; | 60 String toString() => "Rect.LTRB($left, $top, $right, $bottom)"; |
65 } | 61 } |
OLD | NEW |