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

Side by Side Diff: client/touch/Geometry.dart

Issue 9382027: Move client/{base, observable, layout, touch, util, view} to samples/ui_lib . (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « client/touch/FxUtil.dart ('k') | client/touch/InfiniteScroller.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
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() => new Coordinate(x, y);
57
58 String toString() => "($x, $y)";
59 }
60
61 /**
62 * Represents the interval { x | start <= x < end }.
63 */
64 class Interval {
65
66 final num start;
67 final num end;
68
69 Interval(num this.start, num this.end) {}
70
71 num get length() {
72 return end - start;
73 }
74
75 bool operator ==(Interval other) {
76 return other !== null && other.start == start && other.end == end;
77 }
78
79 Interval union(Interval other) {
80 return new Interval(Math.min(start, other.start),
81 Math.max(end, other.end));
82 }
83
84 bool contains(num value) {
85 return value >= start && value < end;
86 }
87
88 String toString() {
89 return '(${start}, ${end})';
90 }
91 }
OLDNEW
« no previous file with comments | « client/touch/FxUtil.dart ('k') | client/touch/InfiniteScroller.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698