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

Side by Side 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: Size hashCode Created 5 years, 6 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 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.
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() : _value = new Float32List(4);
15 16
16 Rect.fromPointAndSize(Point point, Size size) { 17 Rect.fromPointAndSize(Point point, Size size) {
17 _value = new Float32List(4) 18 _value = new Float32List(4)
18 ..[0] = point.x 19 ..[0] = point.x
19 ..[1] = point.y 20 ..[1] = point.y
20 ..[2] = point.x + size.width 21 ..[2] = point.x + size.width
21 ..[3] = point.y + size.height; 22 ..[3] = point.y + size.height;
22 } 23 }
23 24
24 Rect.fromLTRB(double left, double top, double right, double bottom) { 25 Rect.fromLTRB(double left, double top, double right, double bottom) {
25 _value = new Float32List(4) 26 _value = new Float32List(4)
26 ..[0] = left 27 ..[0] = left
27 ..[1] = top 28 ..[1] = top
28 ..[2] = right 29 ..[2] = right
29 ..[3] = bottom; 30 ..[3] = bottom;
30 } 31 }
31 32
32 Point get upperLeft => new Point(left, top); 33 Point get upperLeft => new Point(left, top);
33 Point get lowerRight => new Point(right, bottom); 34 Point get lowerRight => new Point(right, bottom);
34 35
35 Size get size => new Size(right - left, bottom - top); 36 Size get size => new Size(right - left, bottom - top);
36 37
37 // Rects are inclusive of the top and left edges but exclusive of the bottom 38 // Rects are inclusive of the top and left edges but exclusive of the bottom
38 // right edges. 39 // right edges.
39 bool contains(Point point) => point.x >= left && point.x < right 40 bool contains(Point point) =>
40 && point.y >= top && point.y < bottom; 41 point.x >= left && point.x < right && point.y >= top && point.y < bottom;
41 42
42 void setLTRB(double left, double top, double right, double bottom) { 43 void setLTRB(double left, double top, double right, double bottom) {
43 _value[0] = left 44 _value[0] = left
44 ..[1] = top 45 ..[1] = top
45 ..[2] = right 46 ..[2] = right
46 ..[3] = bottom; 47 ..[3] = bottom;
47 } 48 }
49
50 bool operator ==(other) {
51 if (!(other is Rect)) return false;
52 for (var i = 0; i < 4; ++i) {
53 if (_value[i] != other._value[i]) return false;
54 }
55 return true;
56 }
57 int get hashCode {
58 return _value.fold(373, (value, item) => (37 * value + item.hashCode));
59 }
60 String toString() => "Rect.LTRB($left, $top, $right, $bottom)";
48 } 61 }
OLDNEW
« 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