Chromium Code Reviews| 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 class Rect { | 8 class Rect { |
| 8 Float32List _value; | 9 final Float32List _value = new Float32List(4); |
| 9 double get left => _value[0]; | 10 double get left => _value[0]; |
| 10 double get top => _value[1]; | 11 double get top => _value[1]; |
| 11 double get right => _value[2]; | 12 double get right => _value[2]; |
| 12 double get bottom => _value[3]; | 13 double get bottom => _value[3]; |
| 13 | 14 |
| 14 Rect() : new Float32List(4); | 15 Rect(); |
| 15 | 16 |
| 16 Rect.fromPointAndSize(Point point, Size size) { | 17 Rect.fromPointAndSize(Point point, Size size) { |
| 17 _value = new Float32List(4) | 18 _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'
| |
| 18 ..[0] = point.x | 19 ..[1] = point.y |
| 19 ..[1] = point.y | 20 ..[2] = point.x + size.width |
| 20 ..[2] = point.x + size.width | 21 ..[3] = point.y + size.height; |
| 21 ..[3] = point.y + size.height; | |
| 22 } | 22 } |
| 23 | 23 |
| 24 Rect.fromLTRB(double left, double top, double right, double bottom) { | 24 Rect.fromLTRB(double left, double top, double right, double bottom) { |
| 25 _value = new Float32List(4) | 25 setLTRB(left, top, right, bottom); |
| 26 ..[0] = left | |
| 27 ..[1] = top | |
| 28 ..[2] = right | |
| 29 ..[3] = bottom; | |
| 30 } | 26 } |
| 31 | 27 |
| 32 Point get upperLeft => new Point(left, top); | 28 Point get upperLeft => new Point(left, top); |
| 33 Point get lowerRight => new Point(right, bottom); | 29 Point get lowerRight => new Point(right, bottom); |
| 34 | 30 |
| 35 Size get size => new Size(right - left, bottom - top); | 31 Size get size => new Size(right - left, bottom - top); |
| 36 | 32 |
| 37 // Rects are inclusive of the top and left edges but exclusive of the bottom | 33 // Rects are inclusive of the top and left edges but exclusive of the bottom |
| 38 // right edges. | 34 // right edges. |
| 39 bool contains(Point point) => point.x >= left && point.x < right | 35 bool contains(Point point) => |
| 40 && point.y >= top && point.y < bottom; | 36 point.x >= left && point.x < right && point.y >= top && point.y < bottom; |
| 41 | 37 |
| 42 void setLTRB(double left, double top, double right, double bottom) { | 38 void setLTRB(double left, double top, double right, double bottom) { |
| 43 _value[0] = left | 39 _value |
| 44 ..[1] = top | 40 ..[0] = left |
| 45 ..[2] = right | 41 ..[1] = top |
| 46 ..[3] = bottom; | 42 ..[2] = right |
| 43 ..[3] = bottom; | |
| 47 } | 44 } |
| 45 | |
| 46 bool operator ==(other) { | |
| 47 if (!(other is Rect)) return false; | |
| 48 for (var i = 0; i < 4; ++i) { | |
| 49 if (_value[i] != other._value[i]) return false; | |
| 50 } | |
| 51 return true; | |
| 52 } | |
| 53 int get hashCode { | |
| 54 return _value.fold(373, (value, item) => (37 * value + item.hashCode)); | |
| 55 } | |
| 56 String toString() => "Rect.LTRB($left, $top, $right, $bottom)"; | |
| 48 } | 57 } |
| OLD | NEW |