phetsims / dot

A math library with a focus on mutable and immutable linear algebra for 2D and 3D applications.
http://scenerystack.org/
MIT License
13 stars 6 forks source link

Add normalization function to Range.js #99

Closed zepumph closed 4 years ago

zepumph commented 4 years ago

I asked on slack if this would be useful:

normalize( value) {
  return (value - this.min)/(this.getLength());
}

The answer was yes, and it will help with issues like https://github.com/phetsims/molarity/issues/183. I'll add it. People liked getNormalizedValue best.

zepumph commented 4 years ago

@pixelzoom mentioned that it is a bit weird to have the term "normalize" in a function that doesn't strictly return a number between 0 and 1, since new phet.dot.Range( -10, 10 ).getNormalizedValue( -20 ) => -0.5.

I'll make sure to add some doc for that.

zepumph commented 4 years ago

@samreid also mentioned that he didn't love the term "normalize", and would rather something like “fraction”, “ratio” or “proportion”. No one seemed to second it.

@pixelzoom will you please review this new function and its tests. Anything else here?

pixelzoom commented 4 years ago

Implementation and tests look good. The doc was sort of odd -- there was a typo, and the description of the return value was in 2 different places. So I fixed the typo and consolidated the description into one place, see above commits. Closing.