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..4795e20b6f52994698cddb57a4d6a752452b98be 100644 |
| --- a/sky/engine/core/painting/Rect.dart |
| +++ b/sky/engine/core/painting/Rect.dart |
| @@ -4,29 +4,25 @@ |
| part of dart.sky; |
| +/// Holds 4 floating-point coordinates for a rectangle. |
| class Rect { |
| - Float32List _value; |
| + final Float32List _value = new Float32List(4); |
| double get left => _value[0]; |
| double get top => _value[1]; |
| double get right => _value[2]; |
| double get bottom => _value[3]; |
| - Rect() : new Float32List(4); |
| + Rect(); |
| 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; |
| + _value[0] = point.x |
|
sethladd
2015/05/28 17:27:37
you may want to move this down to:
..[0] = poin
Matt Perry
2015/05/28 17:29:44
Yep! Thanks. Actually, it doesn't work the way it'
|
| + ..[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; |
| + setLTRB(left, top, right, bottom); |
| } |
| Point get upperLeft => new Point(left, top); |
| @@ -36,13 +32,26 @@ 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; |
| + _value |
| + ..[0] = left |
| + ..[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)"; |
| } |