phetsims / energy-skate-park-basics

"Energy Skate Park: Basics" is an educational simulation in HTML5, by PhET Interactive Simulations.
http://phet.colorado.edu/en/simulation/energy-skate-park-basics
GNU General Public License v3.0
2 stars 9 forks source link

isApproxEqual could be moved to dot/Util? #410

Closed jessegreenberg closed 6 years ago

jessegreenberg commented 6 years ago
  /**
   * Determine if two numbers are within tolerance of each other
   * @param {number} a
   * @param {number} b
   * @param {number} tolerance
   * @returns {boolean}
   */
  function isApproxEqual( a, b, tolerance ) { return Math.abs( a - b ) <= tolerance; }

This seems like it could be generally useful. For #398.

jessegreenberg commented 6 years ago

On slack:

Jesse Greenberg [6:10 PM]
EnergySkateParkBasicsModel has an `isApproxEqual` function that returns true if two values are equal within a tolerance. Seems generally useful, and I would move it to dot/Util. Others OK with this?

Jonathan Olson [6:13 PM]
hah, I have equalsEpsilon as a function on most dot types, but don't have it for basic numbers. Feel free to add it

Jesse Greenberg [6:14 PM]
Cool, call it equalsEpsilon in Util?

Jonathan Olson [6:15 PM]
Sure, sounds good. (Should we rename them in general to isApproxEquals? Might be easier to find/understand)

Jesse Greenberg [6:17 PM]
I don't think it is worth a rename, my first search would be "equal" and I would fine equalsEpsilon that way

Ill add it to Util.

jessegreenberg commented 6 years ago

Done with the above commits.