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

Side by Side Diff: sdk/lib/math/rectangle.dart

Issue 228533002: Fix assert in dart:math/Rectangle. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/lib/math/rectangle_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 base class for representing two-dimensional axis-aligned rectangles. 7 * A base class for representing two-dimensional axis-aligned rectangles.
8 * 8 *
9 * This rectangle uses a left-handed Cartesian coordinate system, with x 9 * This rectangle uses a left-handed Cartesian coordinate system, with x
10 * directed to the right and y directed down, as per the convention in 2D 10 * directed to the right and y directed down, as per the convention in 2D
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 * with x-coordinate between `left` and `left + width`, and 141 * with x-coordinate between `left` and `left + width`, and
142 * with y-coordinate between `top` and `top + height`, both inclusive. 142 * with y-coordinate between `top` and `top + height`, both inclusive.
143 * 143 *
144 * The `width` and `height` should be non-negative. 144 * The `width` and `height` should be non-negative.
145 * If `width` or `height` are negative, they are clamped to zero. 145 * If `width` or `height` are negative, they are clamped to zero.
146 * 146 *
147 * If `width` and `height` are zero, the "rectangle" comprises only the single 147 * If `width` and `height` are zero, the "rectangle" comprises only the single
148 * point `(left, top)`. 148 * point `(left, top)`.
149 */ 149 */
150 const Rectangle(this.left, this.top, T width, T height) 150 const Rectangle(this.left, this.top, T width, T height)
151 : this.width = (width >= 0) ? width : -width * 0, // Inline _clampToZero. 151 : this.width = (width < 0) ? -width * 0 : width, // Inline _clampToZero.
152 this.height = (height >= 0) ? height : -height * 0; 152 this.height = (height < 0) ? -height * 0 : height;
153 153
154 /** 154 /**
155 * Create a rectangle spanned by the points [a] and [b]; 155 * Create a rectangle spanned by the points [a] and [b];
156 * 156 *
157 * The rectangle contains the points 157 * The rectangle contains the points
158 * with x-coordinate between `a.x` and `b.x`, and 158 * with x-coordinate between `a.x` and `b.x`, and
159 * with y-coordinate between `a.y` and `b.y`, both inclusive. 159 * with y-coordinate between `a.y` and `b.y`, both inclusive.
160 * 160 *
161 * If the distance between `a.x` and `b.x` is not representable 161 * If the distance between `a.x` and `b.x` is not representable
162 * (which can happen if one or both is a double), 162 * (which can happen if one or both is a double),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 * with x-coordinate between `left` and `left + width`, and 202 * with x-coordinate between `left` and `left + width`, and
203 * with y-coordinate between `top` and `top + height`, both inclusive. 203 * with y-coordinate between `top` and `top + height`, both inclusive.
204 * 204 *
205 * The `width` and `height` should be non-negative. 205 * The `width` and `height` should be non-negative.
206 * If `width` or `height` are negative, they are clamped to zero. 206 * If `width` or `height` are negative, they are clamped to zero.
207 * 207 *
208 * If `width` and `height` are zero, the "rectangle" comprises only the single 208 * If `width` and `height` are zero, the "rectangle" comprises only the single
209 * point `(left, top)`. 209 * point `(left, top)`.
210 */ 210 */
211 MutableRectangle(this.left, this.top, T width, T height) 211 MutableRectangle(this.left, this.top, T width, T height)
212 : this._width = (width >= 0) ? width : _clampToZero(width), 212 : this._width = (width < 0) ? _clampToZero(width) : width,
213 this._height = (height >= 0) ? height : _clampToZero(height); 213 this._height = (height < 0) ? _clampToZero(height) : height;
214 214
215 /** 215 /**
216 * Create a mutable rectangle spanned by the points [a] and [b]; 216 * Create a mutable rectangle spanned by the points [a] and [b];
217 * 217 *
218 * The rectangle contains the points 218 * The rectangle contains the points
219 * with x-coordinate between `a.x` and `b.x`, and 219 * with x-coordinate between `a.x` and `b.x`, and
220 * with y-coordinate between `a.y` and `b.y`, both inclusive. 220 * with y-coordinate between `a.y` and `b.y`, both inclusive.
221 * 221 *
222 * If the distance between `a.x` and `b.x` is not representable 222 * If the distance between `a.x` and `b.x` is not representable
223 * (which can happen if one or both is a double), 223 * (which can happen if one or both is a double),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 267
268 /** 268 /**
269 * Converts a negative [int] or [double] to a zero-value of the same type. 269 * Converts a negative [int] or [double] to a zero-value of the same type.
270 * 270 *
271 * Returns `0` if value is int, `0.0` if value is double. 271 * Returns `0` if value is int, `0.0` if value is double.
272 */ 272 */
273 num _clampToZero(num value) { 273 num _clampToZero(num value) {
274 assert(value < 0); 274 assert(value < 0);
275 return -value * 0; 275 return -value * 0;
276 } 276 }
OLDNEW
« 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