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

Side by Side Diff: test/generated_sdk/lib/math/point.dart

Issue 1162723007: remove generated_sdk from checked in code (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: 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 | « test/generated_sdk/lib/math/math.dart ('k') | test/generated_sdk/lib/math/random.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) 2013, 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 part of dart.math;
5
6 /**
7 * A utility class for representing two-dimensional positions.
8 */
9 class Point<T extends num> {
10 final T x;
11 final T y;
12
13 const Point(T x, T y): this.x = x, this.y = y;
14
15 String toString() => 'Point($x, $y)';
16
17 /**
18 * A `Point` is only equal to another `Point` with the same coordinates.
19 *
20 * This point is equal to `other` if, and only if,
21 * `other` is a `Point` with
22 * [x] equal to `other.x` and [y] equal to `other.y`.
23 */
24 bool operator ==(other) {
25 if (other is !Point) return false;
26 return x == other.x && y == other.y;
27 }
28
29 int get hashCode => _JenkinsSmiHash.hash2(x.hashCode, y.hashCode);
30
31 /**
32 * Add [other] to `this`, as if both points were vectors.
33 *
34 * Returns the resulting "vector" as a Point.
35 */
36 Point<T> operator +(Point<T> other) {
37 return new Point<T>(x + other.x, y + other.y);
38 }
39
40 /**
41 * Subtract [other] from `this`, as if both points were vectors.
42 *
43 * Returns the resulting "vector" as a Point.
44 */
45 Point<T> operator -(Point<T> other) {
46 return new Point<T>(x - other.x, y - other.y);
47 }
48
49 /**
50 * Scale this point by [factor] as if it were a vector.
51 *
52 * *Important* *Note*: This function accepts a `num` as its argument only so
53 * that you can scale Point<double> objects by an `int` factor. Because the
54 * star operator always returns the same type of Point that originally called
55 * it, passing in a double [factor] on a `Point<int>` _causes_ _a_
56 * _runtime_ _error_ in checked mode.
57 */
58 Point<T> operator *(num factor) {
59 return new Point<T>(x * factor, y * factor);
60 }
61
62 /**
63 * Get the straight line (Euclidean) distance between the origin (0, 0) and
64 * this point.
65 */
66 double get magnitude => sqrt(x * x + y * y);
67
68 /**
69 * Returns the distance between `this` and [other].
70 */
71 double distanceTo(Point<T> other) {
72 var dx = x - other.x;
73 var dy = y - other.y;
74 return sqrt(dx * dx + dy * dy);
75 }
76
77 /**
78 * Returns the squared distance between `this` and [other].
79 *
80 * Squared distances can be used for comparisons when the actual value is not
81 * required.
82 */
83 T squaredDistanceTo(Point<T> other) {
84 var dx = x - other.x;
85 var dy = y - other.y;
86 return dx * dx + dy * dy;
87 }
88 }
OLDNEW
« no previous file with comments | « test/generated_sdk/lib/math/math.dart ('k') | test/generated_sdk/lib/math/random.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698