| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 // TODO(jacobr): pick a better name. This was goog.math in Closure. | |
| 6 /** | |
| 7 * Math utility functions originally from the closure Math library. | |
| 8 */ | |
| 9 class GoogleMath { | |
| 10 /** | |
| 11 * Takes a [value] and clamps it to within the bounds specified by | |
| 12 * [min] and [max]. | |
| 13 */ | |
| 14 static num clamp(num value, num min, num max) { | |
| 15 return Math.min(Math.max(value, min), max); | |
| 16 } | |
| 17 | |
| 18 /** | |
| 19 * Tests whether the two values are equal to each other, within a certain | |
| 20 * tolerance to adjust for floating point errors. | |
| 21 * The optional [tolerance] value d Defaults to 0.000001. If specified, | |
| 22 * it should be greater than 0. | |
| 23 * Returns whether [a] and [b] are nearly equal. | |
| 24 */ | |
| 25 static bool nearlyEquals(num a, num b, [num tolerance = 0.000001]) { | |
| 26 return (a - b).abs() <= tolerance; | |
| 27 } | |
| 28 } | |
| OLD | NEW |