OLD | NEW |
| (Empty) |
1 // | |
2 // Copyright 2014 Google Inc. All rights reserved. | |
3 // | |
4 // Use of this source code is governed by a BSD-style | |
5 // license that can be found in the LICENSE file or at | |
6 // https://developers.google.com/open-source/licenses/bsd | |
7 // | |
8 | |
9 part of charted.core.utils; | |
10 | |
11 /// Interface representing size and position of an element | |
12 class Rect { | |
13 final num x; | |
14 final num y; | |
15 final num width; | |
16 final num height; | |
17 | |
18 const Rect([this.x = 0, this.y = 0, this.width = 0, this.height = 0]); | |
19 const Rect.size(this.width, this.height) : x = 0, y = 0; | |
20 const Rect.position(this.x, this.y) : width = 0, height = 0; | |
21 | |
22 bool operator==(other) => | |
23 other is Rect && isSameSizeAs(other) && isSamePositionAs(other); | |
24 | |
25 bool isSameSizeAs(Rect other) => | |
26 other != null && width == other.width && height == other.height; | |
27 | |
28 bool isSamePositionAs(Rect other) => | |
29 other != null && x == other.x && y == other.y; | |
30 | |
31 bool contains(num otherX, num otherY) => | |
32 otherX >= x && otherX <= x + width && | |
33 otherY >= y && otherY <= y + height; | |
34 | |
35 String toString() => '$x, $y, $width, $height'; | |
36 } | |
37 | |
38 /// Mutable version of [Rect] class. | |
39 class MutableRect extends Rect { | |
40 num x; | |
41 num y; | |
42 num width; | |
43 num height; | |
44 | |
45 MutableRect(this.x, this.y, this.width, this.height); | |
46 MutableRect.size(this.width, this.height); | |
47 MutableRect.position(this.x, this.y); | |
48 } | |
49 | |
50 class AbsoluteRect { | |
51 final num start; | |
52 final num end; | |
53 final num top; | |
54 final num bottom; | |
55 | |
56 const AbsoluteRect(this.top, this.end, this.bottom, this.start); | |
57 | |
58 bool operator==(other) => | |
59 other is AbsoluteRect && | |
60 start == other.start && end == other.end && | |
61 top == other.top && bottom == other.bottom; | |
62 } | |
OLD | NEW |