Chromium Code Reviews| Index: sdk/lib/math/point.dart |
| diff --git a/tools/dom/src/Point.dart b/sdk/lib/math/point.dart |
| similarity index 64% |
| rename from tools/dom/src/Point.dart |
| rename to sdk/lib/math/point.dart |
| index c5c1df8d741f0916aa5ff0bfd88439b0a4b39ecb..039649dfd973a6ad698c770716fab568166ba844 100644 |
| --- a/tools/dom/src/Point.dart |
| +++ b/sdk/lib/math/point.dart |
| @@ -1,17 +1,16 @@ |
| // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| - |
| -part of html; |
| +part of dart.math; |
| /** |
| * A utility class for representing two-dimensional positions. |
| */ |
| -class Point { |
| - final num x; |
| - final num y; |
| +class Point<T extends num> { |
| + final T x; |
| + final T y; |
| - const Point([num x = 0, num y = 0]): x = x, y = y; |
| + const Point([T x = 0, T y = 0]): x = x, y = y; |
|
floitsch
2013/10/02 08:54:09
*minor* nit: this.x = x, this.y = y;
Emily Fortuna
2013/10/02 18:32:40
Done.
|
| String toString() => '($x, $y)'; |
| @@ -20,17 +19,17 @@ class Point { |
| return x == other.x && y == other.y; |
| } |
| - int get hashCode => JenkinsSmiHash.hash2(x.hashCode, y.hashCode); |
| + int get hashCode => _JenkinsSmiHash.hash2(x.hashCode, y.hashCode); |
| - Point operator +(Point other) { |
| + Point<T> operator +(Point<T> other) { |
| return new Point(x + other.x, y + other.y); |
| } |
| - Point operator -(Point other) { |
| + Point<T> operator -(Point<T> other) { |
| return new Point(x - other.x, y - other.y); |
| } |
| - Point operator *(num factor) { |
| + Point<T> operator *(T factor) { |
|
floitsch
2013/10/02 08:54:09
that one is hard.
There is no reason not to write
Emily Fortuna
2013/10/02 18:32:40
Done.
|
| return new Point(x * factor, y * factor); |
| } |
| @@ -38,12 +37,12 @@ class Point { |
| * Get the straight line (Euclidean) distance between the origin (0, 0) and |
| * this point. |
| */ |
| - num get magnitude => sqrt(x * x + y * y); |
| + T get magnitude => sqrt(x * x + y * y); |
| /** |
| * Returns the distance between two points. |
|
floitsch
2013/10/02 08:54:09
`this` and [other].
Emily Fortuna
2013/10/02 18:32:40
Done.
|
| */ |
| - double distanceTo(Point other) { |
| + double distanceTo(Point<T> other) { |
| var dx = x - other.x; |
| var dy = y - other.y; |
| return sqrt(dx * dx + dy * dy); |
| @@ -55,18 +54,18 @@ class Point { |
| * Squared distances can be used for comparisons when the actual value is not |
| * required. |
| */ |
| - num squaredDistanceTo(Point other) { |
| + T squaredDistanceTo(Point<T> other) { |
| var dx = x - other.x; |
| var dy = y - other.y; |
| return dx * dx + dy * dy; |
| } |
| - Point ceil() => new Point(x.ceil(), y.ceil()); |
| - Point floor() => new Point(x.floor(), y.floor()); |
| - Point round() => new Point(x.round(), y.round()); |
| + Point<T> ceil() => new Point<T>(x.ceil(), y.ceil()); |
|
Emily Fortuna
2013/10/01 23:12:21
One could argue that these should always return Po
floitsch
2013/10/02 08:54:09
Are these functions really needed?
I think you ne
Emily Fortuna
2013/10/02 18:32:40
Done (converted them to int).
These functions wer
|
| + Point<T> floor() => new Point<T>(x.floor(), y.floor()); |
| + Point<T> round() => new Point<T>(x.round(), y.round()); |
| /** |
| * Truncates x and y to integers and returns the result as a new point. |
| */ |
| - Point toInt() => new Point(x.toInt(), y.toInt()); |
| + Point<int> truncate() => new Point<int>(x.toInt(), y.toInt()); |
| } |