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

Side by Side Diff: client/base/Size.dart

Issue 8363040: Implement measurement using futures (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove duplicated imports from html.dart Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | client/base/base.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 (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Represents a point in 2 dimensional space.
7 */
8 class Coordinate {
9
10 /**
11 * X-value
12 */
13 num x;
14
15 /**
16 * Y-value
17 */
18 num y;
19
20 Coordinate([num this.x = 0, num this.y = 0]) {
21 }
22
23 /**
24 * Gets the coordinates of a touch's location relative to the window's
25 * viewport. [input] is either a touch object or an event object.
26 */
27 Coordinate.fromClient(var input) : this(input.clientX, input.clientY);
28
29 static Coordinate difference(Coordinate a, Coordinate b) {
30 return new Coordinate(a.x - b.x, a.y - b.y);
31 }
32
33 static num distance(Coordinate a, Coordinate b) {
34 final dx = a.x - b.x;
35 final dy = a.y - b.y;
36 return Math.sqrt(dx * dx + dy * dy);
37 }
38
39 bool operator ==(Coordinate other) {
40 return other !== null && x == other.x && y == other.y;
41 }
42
43 static num squaredDistance(Coordinate a, Coordinate b) {
44 final dx = a.x - b.x;
45 final dy = a.y - b.y;
46 return dx * dx + dy * dy;
47 }
48
49 static Coordinate sum(Coordinate a, Coordinate b) {
50 return new Coordinate(a.x + b.x, a.y + b.y);
51 }
52
53 /**
54 * Returns a new copy of the coordinate.
55 */
56 Coordinate clone() {
57 return new Coordinate(x, y);
58 }
59
60 /**
61 * Returns a nice string representing the coordinate.
62 * @return {string} In the form (50, 73).
63 */
64 String toString() {
65 return "(${x}, ${y})";
66 }
67 }
68
69 /**
70 * A utility class for representing two-dimensional sizes. 6 * A utility class for representing two-dimensional sizes.
71 */ 7 */
72 class Size { 8 class Size {
73 num width; 9 num width;
74 num height; 10 num height;
75 11
76 Size(num this.width, num this.height) { 12 Size(num this.width, num this.height) {
77 } 13 }
78 14
79 bool operator ==(Size other) { 15 bool operator ==(Size other) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 129 }
194 130
195 /** 131 /**
196 * Returns a nice string representing size. 132 * Returns a nice string representing size.
197 * Returns in the form (50 x 73). 133 * Returns in the form (50 x 73).
198 */ 134 */
199 String toString() { 135 String toString() {
200 return "(${width} x ${height})"; 136 return "(${width} x ${height})";
201 } 137 }
202 } 138 }
203
204 /**
205 * Represents the interval { x | start <= x < end }.
206 */
207 class Interval {
208
209 final num start;
210 final num end;
211
212 Interval(num this.start, num this.end) {}
213
214 num get length() {
215 return end - start;
216 }
217
218 bool operator ==(Interval other) {
219 return other !== null && other.start == start && other.end == end;
220 }
221
222 Interval union(Interval other) {
223 return new Interval(Math.min(start, other.start),
224 Math.max(end, other.end));
225 }
226
227 bool contains(num value) {
228 return value >= start && value < end;
229 }
230
231 String toString() {
232 return '(${start}, ${end})';
233 }
234 }
OLDNEW
« no previous file with comments | « no previous file | client/base/base.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698