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

Unified Diff: sdk/lib/math/rectangle.dart

Issue 135273009: Make Rectangle and MutableRectangle constructors handle negative lengths. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/lib/math/rectangle_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/math/rectangle.dart
diff --git a/sdk/lib/math/rectangle.dart b/sdk/lib/math/rectangle.dart
index e0a3b9870fce43a6644f1baa255ffe8f6ca82ac0..fd6b7bec2b0e1a5ee9cb7f222a5bd33019937ee2 100644
--- a/sdk/lib/math/rectangle.dart
+++ b/sdk/lib/math/rectangle.dart
@@ -12,6 +12,10 @@ part of dart.math;
*
* See also:
* [W3C Coordinate Systems Specification](http://www.w3.org/TR/SVG/coords.html#InitialCoordinateSystem).
+ *
+ * The rectangle is the set of points with representable coordinates greater
+ * than or equal to left/top, and with distance to left/top no greater than
+ * width/height (to the limit of the precission of the coordinates).
*/
abstract class _RectangleBase<T extends num> {
const _RectangleBase();
@@ -130,7 +134,11 @@ class Rectangle<T extends num> extends _RectangleBase<T> {
final T width;
final T height;
- const Rectangle(this.left, this.top, this.width, this.height);
+ const Rectangle(left, top, width, height)
+ : left = (width >= 0) ? left : left + width,
+ width = (width >= 0) ? width : -width,
+ top = (height >= 0) ? top : top + height,
+ height = (height >= 0) ? height : -height;
srdjan 2014/01/28 16:47:41 This looks very unreadable to me (same names for a
Lasse Reichstein Nielsen 2014/01/28 17:49:59 Yes, they should be typed "T", and I should write
factory Rectangle.fromPoints(Point<T> a, Point<T> b) {
T left = min(a.x, b.x);
@@ -145,14 +153,18 @@ class Rectangle<T extends num> extends _RectangleBase<T> {
* A class for representing two-dimensional axis-aligned rectangles with mutable
* properties.
*/
-class MutableRectangle<T extends num> extends _RectangleBase<T>
- implements Rectangle<T> {
+class MutableRectangle<T extends num> extends _RectangleBase<T>
+ implements Rectangle<T> {
T left;
T top;
T width;
T height;
- MutableRectangle(this.left, this.top, this.width, this.height);
+ MutableRectangle(left, top, width, height)
+ : left = (width >= 0) ? left : left + width,
+ width = (width >= 0) ? width : -width,
+ top = (height >= 0) ? top : top + height,
+ height = (height >= 0) ? height : -height;
factory MutableRectangle.fromPoints(Point<T> a, Point<T> b) {
T left = min(a.x, b.x);
« no previous file with comments | « no previous file | tests/lib/math/rectangle_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698