-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mutable functions to Range #77
Comments
@pixelzoom please review at your convenience. I was not sure if I should use |
Based on problems reported on Slack, I'm guessing that this is not ready for review at the moment. Please assign back to me when it's ready. |
Now ready for review @pixelzoom. To add to my question/thinking in #77 (comment), I realized that only makes sense in Range.js itself (I think), so I reverted the |
Signed-off-by: Chris Malley <cmalley@pixelzoom.com>
I made some changes, see above commit. Three corrections:
One subjective change:
One recommendation:
Two things to discuss:
const r1 = new phet.dot.Range( 0, 1 );
const r2 = new phet.dot.RangeWithValue( 0, 1, 0.5 );
r1.equals( r2 ) -> true
r2.equals( r1 ) -> false
const range = new RangeWithValue( -10, 10 );
...
something = range.defaultValue; // obfuscates
something = range.min; // much clearer what it going on |
Labeling for developer meeting to discuss the "Two things to discuss" in the previous comment. |
Yes, generally. We have usually avoided equals() in things that get inherited, but there are many cases where we don't have constructor/type checks. |
Signed-off-by: Chris Malley <cmalley@pixelzoom.com>
@jonathanolson Which question are you answering "yes" to? |
The |
Range and RangeWithValue
|
Signed-off-by: Chris Malley <cmalley@pixelzoom.com>
The remaining bit of work for this issue is unit tests |
Something this fundamental should not be left "in progress" for this long. So I've raised the priority to "high". @chrisklus let me know if you need any help finishing this up. |
Thanks for the help @pixelzoom, please review. Since min and max for Range and RangeWithValue are inclusive, I wasn't sure if I should test the cases where, for example, |
Yeah, messages should be "<=" and ">=". I didn't realize the |
Yeah, I'm leaning towards this as well. Might be nice to discuss at dev meeting for general/future reference though, as you said. For now, I've updated the messages and will mark for discussion. |
From 01/10/19 dev meeting. @jonathanolson said:
@samreid said:
I'll go ahead and add in the rest of the "or equal to" cases. |
Boundary condition tests added. @pixelzoom please review. |
👍 I skimmed the commits and verified that the unit tests are passing. Closing. |
From slack:
Chris Klusendorf [4:04 PM]
@jbphet and I are thinking of adding some mutable functions to Range.js, likely
setMin()
,setMax()
, andsetMinMax()
. Any objections?Michael Kauzmann [4:04 PM]
No objections here. I like the idea.
Chris Malley [4:30 PM]
what’s the use case?
Chris Klusendorf [4:40 PM]
I’m refactoring HorizontalSurface (the top and bottom surface of a movable element) in EFAC, which is going to have a position and a range, so we’d like to update that range on drag instead of reallocating
Sam Reid [6:04 PM]
Seems reasonable to me. Vector2 and Bounds2 are mutable, so it seems reasonable for Range to be mutable too.
Chris Malley [6:05 PM]
Don’t forget about subtype RangeWithValue. If you mutate min or max such that defaultValue is out of range, boom.
That’s going to be a tricky assertion to pull off.
If it were me, I’d probably leave Range and RangeWithValue alone, and make HorizontalSurface use
{min:number, max:number}
instead of Range.… unless you need other things that Range provides.
Chris Klusendorf [6:10 PM]
Gotcha, yeah we thought about that but are using some of Range’s methods so were thinking it’d be nice to just change Range. I wasn’t aware of RangeWithValue though, so I will investigate how much it would take to refactor usages of HorizontalSurface with
{min:number, max:number}
.Chris Malley [6:12 PM]
In addition to adding setMin and setMax to Range, you’ll need to override in RangeWithValue, something like:
… and similarly for setMax.
Chris Klusendorf [6:13 PM]
nice, thanks!
Chris Malley [6:14 PM]
Also change fields (in Range) to _min, _max, then define setMin, getMin, setMax, getMax and associated ES5 setters. (edited)
Sam Reid [6:14 PM]
RangeWithValue.equals looks buggy
Can you fix that while you’re in there?
Chris Malley [6:15 PM]
yes, it does. looks like someone missed a
this.defaultValue === other.defaultValue
test.and it should be
other instanceof RangeWidthValue
toString
is also buggy, it prints[Range
…The text was updated successfully, but these errors were encountered: