| 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 | 4 |
| 5 part of html; | 5 part of html; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A utility class for representing two-dimensional positions. | 8 * A utility class for representing two-dimensional positions. |
| 9 */ | 9 */ |
| 10 class Point { | 10 class Point { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 Point operator -(Point other) { | 29 Point operator -(Point other) { |
| 30 return new Point(x - other.x, y - other.y); | 30 return new Point(x - other.x, y - other.y); |
| 31 } | 31 } |
| 32 | 32 |
| 33 Point operator *(num factor) { | 33 Point operator *(num factor) { |
| 34 return new Point(x * factor, y * factor); | 34 return new Point(x * factor, y * factor); |
| 35 } | 35 } |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * Get the straight line (Euclidean) distance between the origin (0, 0) and |
| 39 * this point. |
| 40 */ |
| 41 num get magnitude => sqrt(x * x + y * y); |
| 42 |
| 43 /** |
| 38 * Returns the distance between two points. | 44 * Returns the distance between two points. |
| 39 */ | 45 */ |
| 40 double distanceTo(Point other) { | 46 double distanceTo(Point other) { |
| 41 var dx = x - other.x; | 47 var dx = x - other.x; |
| 42 var dy = y - other.y; | 48 var dy = y - other.y; |
| 43 return sqrt(dx * dx + dy * dy); | 49 return sqrt(dx * dx + dy * dy); |
| 44 } | 50 } |
| 45 | 51 |
| 46 /** | 52 /** |
| 47 * Returns the squared distance between two points. | 53 * Returns the squared distance between two points. |
| 48 * | 54 * |
| 49 * Squared distances can be used for comparisons when the actual value is not | 55 * Squared distances can be used for comparisons when the actual value is not |
| 50 * required. | 56 * required. |
| 51 */ | 57 */ |
| 52 num squaredDistanceTo(Point other) { | 58 num squaredDistanceTo(Point other) { |
| 53 var dx = x - other.x; | 59 var dx = x - other.x; |
| 54 var dy = y - other.y; | 60 var dy = y - other.y; |
| 55 return dx * dx + dy * dy; | 61 return dx * dx + dy * dy; |
| 56 } | 62 } |
| 57 | 63 |
| 58 Point ceil() => new Point(x.ceil(), y.ceil()); | 64 Point ceil() => new Point(x.ceil(), y.ceil()); |
| 59 Point floor() => new Point(x.floor(), y.floor()); | 65 Point floor() => new Point(x.floor(), y.floor()); |
| 60 Point round() => new Point(x.round(), y.round()); | 66 Point round() => new Point(x.round(), y.round()); |
| 61 | 67 |
| 62 /** | 68 /** |
| 63 * Truncates x and y to integers and returns the result as a new point. | 69 * Truncates x and y to integers and returns the result as a new point. |
| 64 */ | 70 */ |
| 65 Point toInt() => new Point(x.toInt(), y.toInt()); | 71 Point toInt() => new Point(x.toInt(), y.toInt()); |
| 66 } | 72 } |
| OLD | NEW |