Chromium Code Reviews| Index: sky/engine/core/painting/Rect.dart |
| diff --git a/sky/engine/core/painting/Rect.dart b/sky/engine/core/painting/Rect.dart |
| index a54f7aeaf9cbeffd2f17600846bb8cf9268ba14e..39cefedb4f213f79b2071b7e6163318f0c5beee8 100644 |
| --- a/sky/engine/core/painting/Rect.dart |
| +++ b/sky/engine/core/painting/Rect.dart |
| @@ -4,6 +4,7 @@ |
| part of dart.sky; |
| +/// Holds 4 floating-point coordinates for a rectangle. |
| class Rect { |
| Float32List _value; |
|
sethladd
2015/05/28 17:09:03
you could initialize this value here.
Float32List
Matt Perry
2015/05/28 17:25:06
Done.
|
| double get left => _value[0]; |
| @@ -11,22 +12,22 @@ class Rect { |
| double get right => _value[2]; |
| double get bottom => _value[3]; |
| - Rect() : new Float32List(4); |
| + Rect() : _value = new Float32List(4); |
| Rect.fromPointAndSize(Point point, Size size) { |
| _value = new Float32List(4) |
| - ..[0] = point.x |
| - ..[1] = point.y |
| - ..[2] = point.x + size.width |
| - ..[3] = point.y + size.height; |
| + ..[0] = point.x |
| + ..[1] = point.y |
| + ..[2] = point.x + size.width |
| + ..[3] = point.y + size.height; |
| } |
| Rect.fromLTRB(double left, double top, double right, double bottom) { |
| _value = new Float32List(4) |
| - ..[0] = left |
| - ..[1] = top |
| - ..[2] = right |
| - ..[3] = bottom; |
| + ..[0] = left |
| + ..[1] = top |
| + ..[2] = right |
| + ..[3] = bottom; |
| } |
| Point get upperLeft => new Point(left, top); |
| @@ -36,13 +37,25 @@ class Rect { |
| // Rects are inclusive of the top and left edges but exclusive of the bottom |
| // right edges. |
| - bool contains(Point point) => point.x >= left && point.x < right |
| - && point.y >= top && point.y < bottom; |
| + bool contains(Point point) => |
| + point.x >= left && point.x < right && point.y >= top && point.y < bottom; |
| void setLTRB(double left, double top, double right, double bottom) { |
| _value[0] = left |
| - ..[1] = top |
| - ..[2] = right |
| - ..[3] = bottom; |
| + ..[1] = top |
| + ..[2] = right |
| + ..[3] = bottom; |
| } |
| + |
| + bool operator ==(other) { |
| + if (!(other is Rect)) return false; |
| + for (var i = 0; i < 4; ++i) { |
| + if (_value[i] != other._value[i]) return false; |
| + } |
| + return true; |
| + } |
| + int get hashCode { |
| + return _value.fold(373, (value, item) => (37 * value + item.hashCode)); |
| + } |
| + String toString() => "Rect.LTRB($left, $top, $right, $bottom)"; |
| } |