diff --git a/js/NumberPicker.ts b/js/NumberPicker.ts index 15400eca..ab669191 100644 --- a/js/NumberPicker.ts +++ b/js/NumberPicker.ts @@ -15,7 +15,6 @@ import StringUnionProperty from '../../axon/js/StringUnionProperty.js'; import TReadOnlyProperty from '../../axon/js/TReadOnlyProperty.js'; import Dimension2 from '../../dot/js/Dimension2.js'; import Range from '../../dot/js/Range.js'; -import Utils from '../../dot/js/Utils.js'; import Shape from '../../kite/js/Shape.js'; import InstanceRegistry from '../../phet-core/js/documentation/InstanceRegistry.js'; import optionize, { combineOptions, EmptySelfOptions } from '../../phet-core/js/optionize.js'; @@ -41,6 +40,7 @@ import TSoundPlayer from '../../tambo/js/TSoundPlayer.js'; import PhetioObject from '../../tandem/js/PhetioObject.js'; import Tandem from '../../tandem/js/Tandem.js'; import sun from './sun.js'; +import { toFixed } from '../../dot/js/util/toFixed.js'; const ButtonStateValues = [ 'up', 'down', 'over', 'out' ] as const; type ButtonState = ( typeof ButtonStateValues )[number]; @@ -200,7 +200,7 @@ export default class NumberPicker extends AccessibleNumberSpinner( Node, 0 ) { }, providedOptions ); if ( !options.formatValue ) { - options.formatValue = ( value: number ) => Utils.toFixed( value, options.decimalPlaces ); + options.formatValue = ( value: number ) => toFixed( value, options.decimalPlaces ); } // Color of arrows and top/bottom gradient when pressed diff --git a/js/Slider.ts b/js/Slider.ts index 22d54905..4c624469 100644 --- a/js/Slider.ts +++ b/js/Slider.ts @@ -20,7 +20,7 @@ import TReadOnlyProperty from '../../axon/js/TReadOnlyProperty.js'; import CompletePiecewiseLinearFunction from '../../dot/js/CompletePiecewiseLinearFunction.js'; import Dimension2 from '../../dot/js/Dimension2.js'; import Range from '../../dot/js/Range.js'; -import Utils from '../../dot/js/Utils.js'; +import { clamp } from '../../dot/js/util/clamp.js'; import Vector2 from '../../dot/js/Vector2.js'; import assertMutuallyExclusiveOptions from '../../phet-core/js/assertMutuallyExclusiveOptions.js'; import InstanceRegistry from '../../phet-core/js/documentation/InstanceRegistry.js'; @@ -51,6 +51,7 @@ import SliderTick, { SliderTickOptions } from './SliderTick.js'; import type SliderTrack from './SliderTrack.js'; import sun from './sun.js'; import SunConstants from './SunConstants.js'; +import { linear } from '../../dot/js/util/linear.js'; // constants const DEFAULT_HORIZONTAL_TRACK_SIZE = new Dimension2( 100, 5 ); @@ -473,13 +474,13 @@ export default class Slider extends Sizable( AccessibleSlider( Node, 0 ) ) { if ( this.proposedValue === null ) { // clamp the current value to the enabled range if it changes - valueProperty.set( Utils.clamp( valueProperty.value, enabledRange.min, enabledRange.max ) ); + valueProperty.set( clamp( valueProperty.value, enabledRange.min, enabledRange.max ) ); } else { // The user is holding the thumb, which may be outside the enabledRange. In that case, expanding the range // could accommodate the outer value - const proposedValueInEnabledRange = Utils.clamp( this.proposedValue, enabledRange.min, enabledRange.max ); + const proposedValueInEnabledRange = clamp( this.proposedValue, enabledRange.min, enabledRange.max ); const proposedValueInConstrainedRange = options.constrainValue( proposedValueInEnabledRange ); valueProperty.set( proposedValueInConstrainedRange ); } @@ -691,7 +692,7 @@ class SliderConstraint extends LayoutConstraint { // Takes a tick's value into the [0,1] range. This should be multiplied times the potential INTERIOR track width // in order to get the position the tick should be at. const normalizeTickValue = ( value: number ) => { - return Utils.linear( track.rangeProperty.value.min, track.rangeProperty.value.max, 0, 1, value ); + return linear( track.rangeProperty.value.min, track.rangeProperty.value.max, 0, 1, value ); }; // NOTE: Due to visual overflow, our track's range (including the thumb extension) will actually go from diff --git a/js/ToggleSwitch.ts b/js/ToggleSwitch.ts index f403f4a9..3d6d913a 100644 --- a/js/ToggleSwitch.ts +++ b/js/ToggleSwitch.ts @@ -18,7 +18,6 @@ import Emitter from '../../axon/js/Emitter.js'; import Property from '../../axon/js/Property.js'; import TEmitter from '../../axon/js/TEmitter.js'; import Dimension2 from '../../dot/js/Dimension2.js'; -import Utils from '../../dot/js/Utils.js'; import Vector2 from '../../dot/js/Vector2.js'; import Shape from '../../kite/js/Shape.js'; import optionize from '../../phet-core/js/optionize.js'; @@ -38,6 +37,7 @@ import PhetioObject from '../../tandem/js/PhetioObject.js'; import Tandem from '../../tandem/js/Tandem.js'; import Utterance, { TAlertable } from '../../utterance-queue/js/Utterance.js'; import sun from './sun.js'; +import { clamp } from '../../dot/js/util/clamp.js'; // constants const DEFAULT_SIZE = new Dimension2( 60, 30 ); @@ -307,7 +307,7 @@ export default class ToggleSwitch extends Voicing( Node ) { const viewPoint = listener.getCurrentTarget().globalToLocalPoint( event.pointer.point ); const halfThumbWidth = thumbNode.width / 2; const halfLineWidth = trackNode.lineWidth / 2; - thumbNode.centerX = Utils.clamp( viewPoint.x, halfThumbWidth - halfLineWidth, options.size.width - halfThumbWidth + halfLineWidth ); + thumbNode.centerX = clamp( viewPoint.x, halfThumbWidth - halfLineWidth, options.size.width - halfThumbWidth + halfLineWidth ); rightTrackFillRectangle.rectWidth = thumbNode.right - halfLineWidth; // whether the thumb is dragged outside of the possible range far enough beyond our threshold to potentially diff --git a/js/accessibility/AccessibleValueHandler.ts b/js/accessibility/AccessibleValueHandler.ts index 01d7d4c4..d9a2a86a 100644 --- a/js/accessibility/AccessibleValueHandler.ts +++ b/js/accessibility/AccessibleValueHandler.ts @@ -22,7 +22,7 @@ import Property from '../../../axon/js/Property.js'; import TProperty from '../../../axon/js/TProperty.js'; import TReadOnlyProperty from '../../../axon/js/TReadOnlyProperty.js'; import Range from '../../../dot/js/Range.js'; -import Utils from '../../../dot/js/Utils.js'; +import { clamp } from '../../../dot/js/util/clamp.js'; import assertHasProperties from '../../../phet-core/js/assertHasProperties.js'; import optionize, { combineOptions } from '../../../phet-core/js/optionize.js'; import Orientation from '../../../phet-core/js/Orientation.js'; @@ -45,6 +45,9 @@ import Utterance from '../../../utterance-queue/js/Utterance.js'; import UtteranceQueue from '../../../utterance-queue/js/UtteranceQueue.js'; import sun from '../sun.js'; import AccessibleValueHandlerHotkeyDataCollection from './AccessibleValueHandlerHotkeyDataCollection.js'; +import { numberOfDecimalPlaces } from '../../../dot/js/util/numberOfDecimalPlaces.js'; +import { roundSymmetric } from '../../../dot/js/util/roundSymmetric.js'; +import { equalsEpsilon } from '../../../dot/js/util/equalsEpsilon.js'; // constants const DEFAULT_TAG_NAME = 'input'; @@ -893,7 +896,7 @@ const AccessibleValueHandler = >( Type: Supe } // limit the value to the enabled range - this._valueProperty.set( Utils.clamp( constrainedValue, this._enabledRangeProperty.get().min, this._enabledRangeProperty.get().max ) ); + this._valueProperty.set( clamp( constrainedValue, this._enabledRangeProperty.get().min, this._enabledRangeProperty.get().max ) ); // optional callback after the valueProperty is set (even if set to the same value) so that the listener // can use the new value. @@ -996,7 +999,7 @@ const AccessibleValueHandler = >( Type: Supe } // limit to enabled range - newValue = Utils.clamp( newValue, this._enabledRangeProperty.get().min, this._enabledRangeProperty.get().max ); + newValue = clamp( newValue, this._enabledRangeProperty.get().min, this._enabledRangeProperty.get().max ); // optionally constrain value this._valueProperty.set( this._constrainValue( this._pdomMapValue( newValue, this._valueProperty.get() ) ) ); @@ -1221,7 +1224,7 @@ const AccessibleValueHandler = >( Type: Supe if ( platform.mobileSafari ) { const smallestStep = Math.min( this.keyboardStep, this.shiftKeyboardStep, this.pageKeyboardStep ); - stepValue = Math.pow( 10, -Utils.numberOfDecimalPlaces( smallestStep ) ); + stepValue = Math.pow( 10, -numberOfDecimalPlaces( smallestStep ) ); const mappedMin = this._getMappedValue( this._enabledRangeProperty.get().min ); const mappedMax = this._getMappedValue( this._enabledRangeProperty.get().max ); @@ -1308,7 +1311,7 @@ const roundValue = function( newValue: number, currentValue: number, stepSize: n if ( stepSize !== 0 ) { // round the value to the nearest keyboard step - roundValue = Utils.roundSymmetric( roundValue / stepSize ) * stepSize; + roundValue = roundSymmetric( roundValue / stepSize ) * stepSize; // go back a step if we went too far due to rounding roundValue = correctRounding( roundValue, currentValue, stepSize ); @@ -1329,7 +1332,7 @@ const correctRounding = function( newValue: number, currentValue: number, stepSi // it is possible that proposedStep will be larger than the stepSize but only because of precision // constraints with floating point values, don't correct if that is the cases - const stepsAboutEqual = Utils.equalsEpsilon( proposedStep, stepSize, 1e-14 ); + const stepsAboutEqual = equalsEpsilon( proposedStep, stepSize, 1e-14 ); if ( stepToFar && !stepsAboutEqual ) { correctedValue += ( newValue > currentValue ) ? ( -stepSize ) : stepSize; }