| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 part of dart.math; | 4 part of dart.math; |
| 5 | 5 |
| 6 /** | 6 /** |
| 7 * A utility class for representing two-dimensional positions. | 7 * A utility class for representing two-dimensional positions. |
| 8 */ | 8 */ |
| 9 class Point<T extends num> { | 9 class Point<T extends num> { |
| 10 final T x; | 10 final T x; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Scale this point by [factor] as if it were a vector. | 50 * Scale this point by [factor] as if it were a vector. |
| 51 * | 51 * |
| 52 * *Important* *Note*: This function accepts a `num` as its argument only so | 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 | 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 | 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_ | 55 * it, passing in a double [factor] on a `Point<int>` _causes_ _a_ |
| 56 * _runtime_ _error_ in checked mode. | 56 * _runtime_ _error_ in checked mode. |
| 57 */ | 57 */ |
| 58 Point<T> operator *(num factor) { | 58 Point<T> operator *(num/*T|int*/ factor) { |
| 59 return new Point<T>(x * factor, y * factor); | 59 return new Point<T>( |
| 60 (x * factor) as dynamic/*=T*/, (y * factor) as dynamic/*=T*/); |
| 60 } | 61 } |
| 61 | 62 |
| 62 /** | 63 /** |
| 63 * Get the straight line (Euclidean) distance between the origin (0, 0) and | 64 * Get the straight line (Euclidean) distance between the origin (0, 0) and |
| 64 * this point. | 65 * this point. |
| 65 */ | 66 */ |
| 66 double get magnitude => sqrt(x * x + y * y); | 67 double get magnitude => sqrt(x * x + y * y); |
| 67 | 68 |
| 68 /** | 69 /** |
| 69 * Returns the distance between `this` and [other]. | 70 * Returns the distance between `this` and [other]. |
| 70 */ | 71 */ |
| 71 double distanceTo(Point<T> other) { | 72 double distanceTo(Point<T> other) { |
| 72 var dx = x - other.x; | 73 var dx = x - other.x; |
| 73 var dy = y - other.y; | 74 var dy = y - other.y; |
| 74 return sqrt(dx * dx + dy * dy); | 75 return sqrt(dx * dx + dy * dy); |
| 75 } | 76 } |
| 76 | 77 |
| 77 /** | 78 /** |
| 78 * Returns the squared distance between `this` and [other]. | 79 * Returns the squared distance between `this` and [other]. |
| 79 * | 80 * |
| 80 * Squared distances can be used for comparisons when the actual value is not | 81 * Squared distances can be used for comparisons when the actual value is not |
| 81 * required. | 82 * required. |
| 82 */ | 83 */ |
| 83 T squaredDistanceTo(Point<T> other) { | 84 T squaredDistanceTo(Point<T> other) { |
| 84 var dx = x - other.x; | 85 var dx = x - other.x; |
| 85 var dy = y - other.y; | 86 var dy = y - other.y; |
| 86 return dx * dx + dy * dy; | 87 return dx * dx + dy * dy; |
| 87 } | 88 } |
| 88 } | 89 } |
| OLD | NEW |