Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: sky/engine/core/painting/Rect.dart

Issue 1154213005: Add operator==, hashCode, and toString for Rect and Point dart classes. (Closed) Base URL: git@github.com:/domokit/mojo.git@master
Patch Set: nits Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/engine/core/painting/Point.dart ('k') | sky/engine/core/painting/Size.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)";
}
« no previous file with comments | « sky/engine/core/painting/Point.dart ('k') | sky/engine/core/painting/Size.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698