OLD | NEW |
1 // | 1 // |
2 // Copyright 2014 Google Inc. All rights reserved. | 2 // Copyright 2014 Google Inc. All rights reserved. |
3 // | 3 // |
4 // Use of this source code is governed by a BSD-style | 4 // Use of this source code is governed by a BSD-style |
5 // license that can be found in the LICENSE file or at | 5 // license that can be found in the LICENSE file or at |
6 // https://developers.google.com/open-source/licenses/bsd | 6 // https://developers.google.com/open-source/licenses/bsd |
7 // | 7 // |
8 | 8 |
9 part of charted.core.utils; | 9 part of charted.core.utils; |
10 | 10 |
11 /// Interface representing size and position of an element | 11 /// Interface representing size and position of an element |
12 class Rect { | 12 class Rect { |
13 final num x; | 13 final num _x; |
14 final num y; | 14 final num _y; |
15 final num width; | 15 final num _width; |
16 final num height; | 16 final num _height; |
17 | 17 |
18 const Rect([this.x = 0, this.y = 0, this.width = 0, this.height = 0]); | 18 num get x => _x; |
19 const Rect.size(this.width, this.height) | 19 num get y => _y; |
20 : x = 0, | 20 num get width => _width; |
21 y = 0; | 21 num get height => _height; |
22 const Rect.position(this.x, this.y) | 22 |
23 : width = 0, | 23 const Rect([this._x = 0, this._y = 0, this._width = 0, this._height = 0]); |
24 height = 0; | 24 const Rect.size(this._width, this._height) |
| 25 : _x = 0, |
| 26 _y = 0; |
| 27 const Rect.position(this._x, this._y) |
| 28 : _width = 0, |
| 29 _height = 0; |
25 | 30 |
26 bool isSameSizeAs(Rect other) => | 31 bool isSameSizeAs(Rect other) => |
27 other != null && width == other.width && height == other.height; | 32 other != null && width == other.width && height == other.height; |
28 | 33 |
29 bool isSamePositionAs(Rect other) => | 34 bool isSamePositionAs(Rect other) => |
30 other != null && x == other.x && y == other.y; | 35 other != null && x == other.x && y == other.y; |
31 | 36 |
32 bool contains(num otherX, num otherY) => | 37 bool contains(num otherX, num otherY) => |
33 otherX >= x && otherX <= x + width && otherY >= y && otherY <= y + height; | 38 otherX >= x && otherX <= x + width && otherY >= y && otherY <= y + height; |
34 | 39 |
(...skipping 30 matching lines...) Expand all Loading... |
65 @override | 70 @override |
66 bool operator ==(other) => other is AbsoluteRect && | 71 bool operator ==(other) => other is AbsoluteRect && |
67 start == other.start && | 72 start == other.start && |
68 end == other.end && | 73 end == other.end && |
69 top == other.top && | 74 top == other.top && |
70 bottom == other.bottom; | 75 bottom == other.bottom; |
71 | 76 |
72 @override | 77 @override |
73 int get hashCode => hash4(start, end, top, bottom); | 78 int get hashCode => hash4(start, end, top, bottom); |
74 } | 79 } |
OLD | NEW |