Skip to content

Commit

Permalink
Converting dot Utils usage, see phetsims/dot#4
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Feb 14, 2025
1 parent f6bcabe commit 7129659
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions js/DynamicStringTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*/

import localizedStrings from '../../chipper/js/browser/localizedStrings.js';
import Utils from '../../dot/js/Utils.js';
import joist from './joist.js';
import { toFixedNumber } from '../../dot/js/util/toFixedNumber.js';

const INITIAL_STRING_FACTOR = 1;
const MAX_STRING_FACTOR = 8; // so that the sim and/or browser doesn't lock up when strings get excessively long
Expand Down Expand Up @@ -155,7 +155,7 @@ function applyToString( stringFactor: number, string: string ): string {
const noPlaceholdersString = string.replace( /{{(.+?)}}/g, '' );

// Reduce the length of the string.
const stringLength = Utils.toFixedNumber( noPlaceholdersString.length * stringFactor + 1, 0 );
const stringLength = toFixedNumber( noPlaceholdersString.length * stringFactor + 1, 0 );
const reducedString = noPlaceholdersString.substring( 0, stringLength );

// Append placeholders to the end of the reduced string. This will add nothing if placeholders is empty.
Expand Down
4 changes: 2 additions & 2 deletions js/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import TReadOnlyProperty, { isTReadOnlyProperty } from '../../axon/js/TReadOnlyP
import Bounds2 from '../../dot/js/Bounds2.js';
import Dimension2 from '../../dot/js/Dimension2.js';
import Matrix3 from '../../dot/js/Matrix3.js';
import Utils from '../../dot/js/Utils.js';
import Vector2 from '../../dot/js/Vector2.js';
import Shape from '../../kite/js/Shape.js';
import Enumeration from '../../phet-core/js/Enumeration.js';
Expand Down Expand Up @@ -77,8 +76,9 @@ import joist from './joist.js';
import type ScreenView from './ScreenView.js';
import type Sim from './Sim.js';
import type SimDisplay from './SimDisplay.js';
import { toFixed } from '../../dot/js/util/toFixed.js';

const round = ( n: number, places = 2 ) => Utils.toFixed( n, places );
const round = ( n: number, places = 2 ) => toFixed( n, places );

class PointerAreaType extends EnumerationValue {
public static readonly MOUSE = new PointerAreaType();
Expand Down
4 changes: 2 additions & 2 deletions js/HomeScreenButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import BooleanProperty from '../../axon/js/BooleanProperty.js';
import DerivedProperty from '../../axon/js/DerivedProperty.js';
import Utils from '../../dot/js/Utils.js';
import Shape from '../../kite/js/Shape.js';
import merge from '../../phet-core/js/merge.js';
import optionize from '../../phet-core/js/optionize.js';
Expand All @@ -32,6 +31,7 @@ import Frame from './Frame.js';
import HomeScreenModel from './HomeScreenModel.js';
import joist from './joist.js';
import Screen from './Screen.js';
import { linear } from '../../dot/js/util/linear.js';

// constants
const LARGE_ICON_HEIGHT = 140;
Expand Down Expand Up @@ -71,7 +71,7 @@ class HomeScreenButton extends Voicing( VBox ) {
const isHighlightedProperty = new BooleanProperty( false );

// maps the number of screens to a scale for the small icons. The scale is percentage of LARGE_ICON_HEIGHT.
let smallIconScale = Utils.linear( 2, 4, 0.875, 0.50, homeScreenModel.simScreens.length );
let smallIconScale = linear( 2, 4, 0.875, 0.50, homeScreenModel.simScreens.length );
if ( homeScreenModel.simScreens.length >= 5 ) {
smallIconScale = 0.4;
}
Expand Down
7 changes: 4 additions & 3 deletions js/NavigationBarScreenButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import DerivedProperty from '../../axon/js/DerivedProperty.js';
import Multilink from '../../axon/js/Multilink.js';
import Property from '../../axon/js/Property.js';
import TReadOnlyProperty from '../../axon/js/TReadOnlyProperty.js';
import Utils from '../../dot/js/Utils.js';
import { clamp } from '../../dot/js/util/clamp.js';
import Shape from '../../kite/js/Shape.js';
import optionize from '../../phet-core/js/optionize.js';
import PickRequired from '../../phet-core/js/types/PickRequired.js';
Expand All @@ -29,6 +29,7 @@ import Tandem from '../../tandem/js/Tandem.js';
import HighlightNode from './HighlightNode.js';
import joist from './joist.js';
import { AnyScreen } from './Screen.js';
import { toFixed } from '../../dot/js/util/toFixed.js';

// constants
const HIGHLIGHT_SPACING = 4;
Expand Down Expand Up @@ -203,7 +204,7 @@ class NavigationBarScreenButton extends Voicing( Node ) {
const updateLayout = () => {

// adjust the vertical space between icon and text, see https://github.com/phetsims/joist/issues/143
iconAndText.spacing = Utils.clamp( 12 - text.height, 0, 3 );
iconAndText.spacing = clamp( 12 - text.height, 0, 3 );

// adjust the overlay
overlay.setRectBounds( iconAndText.bounds );
Expand Down Expand Up @@ -236,7 +237,7 @@ class NavigationBarScreenButton extends Voicing( Node ) {
text.maxWidth = this.width;
}

needsIconMaxWidth && assert && assert( Utils.toFixed( this.width, 0 ) === Utils.toFixed( options.maxButtonWidth!, 0 ),
needsIconMaxWidth && assert && assert( toFixed( this.width, 0 ) === toFixed( options.maxButtonWidth!, 0 ),
`this.width ${this.width} !== options.maxButtonWidth ${options.maxButtonWidth}` );

// A custom focus highlight so that the bottom of the highlight does not get cut-off below the navigation bar.
Expand Down
6 changes: 3 additions & 3 deletions js/Profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Utils from '../../dot/js/Utils.js';
import joist from './joist.js';
import type Sim from './Sim.js';
import { roundSymmetric } from '../../dot/js/util/roundSymmetric.js';

// constants
const FIELD_SEPARATOR = ' \u2014 '; // em dash, a long horizontal dash
Expand Down Expand Up @@ -79,11 +79,11 @@ class Profiler {
}

// FPS
const averageFPS = Utils.roundSymmetric( 1000 / ( totalTime / this.allTimes.length ) );
const averageFPS = roundSymmetric( 1000 / ( totalTime / this.allTimes.length ) );
let text = `${averageFPS} FPS`;

// ms/frame
const averageFrameTime = Utils.roundSymmetric( totalTime / this.allTimes.length );
const averageFrameTime = roundSymmetric( totalTime / this.allTimes.length );
text = `${text + FIELD_SEPARATOR + averageFrameTime}ms/frame`;

// histogram
Expand Down
4 changes: 2 additions & 2 deletions js/Sim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import Dimension2 from '../../dot/js/Dimension2.js';
import dotRandom from '../../dot/js/dotRandom.js';
import Permutation from '../../dot/js/Permutation.js';
import Random from '../../dot/js/Random.js';
import DotUtils from '../../dot/js/Utils.js'; // eslint-disable-line phet/default-import-match-filename
import { addAffirmationHook, setAffirmationDebuggerMode } from '../../perennial-alias/js/browser-and-node/affirm.js';
import optionize from '../../phet-core/js/optionize.js';
import platform from '../../phet-core/js/platform.js';
Expand Down Expand Up @@ -84,6 +83,7 @@ import SimInfo from './SimInfo.js';
import LegendsOfLearningSupport from './thirdPartySupport/LegendsOfLearningSupport.js';
import Toolbar from './toolbar/Toolbar.js';
import updateCheck from './updateCheck.js';
import { linear } from '../../dot/js/util/linear.js';

// constants
const PROGRESS_BAR_WIDTH = 273;
Expand Down Expand Up @@ -951,7 +951,7 @@ export default class Sim extends PhetioObject {

// Move the progress ahead by one so we show the full progress bar for a moment before the sim starts up

const progress = DotUtils.linear( 0, workItems.length - 1, 0.25, 1.0, i );
const progress = linear( 0, workItems.length - 1, 0.25, 1.0, i );

// Support iOS Reading Mode, which saves a DOM snapshot after the progressBarForeground has already been
// removed from the document, see https://github.com/phetsims/joist/issues/389
Expand Down
4 changes: 2 additions & 2 deletions js/launchCounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import TinyProperty from '../../axon/js/TinyProperty.js';
import TReadOnlyProperty from '../../axon/js/TReadOnlyProperty.js';
import Utils from '../../dot/js/Utils.js';
import { toFixed } from '../../dot/js/util/toFixed.js';

// Key for storing the launch count in local storage. This is transient and does not need to be maintained or migrated.
// Safe to rename.
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function launchCounter( simNameProperty: TReadOnlyProperty<string

// Attempt to store the updated run count back to local storage
try {
window.localStorage.setItem( LOCAL_STORAGE_KEY, Utils.toFixed( newRunCount, 0 ) );
window.localStorage.setItem( LOCAL_STORAGE_KEY, toFixed( newRunCount, 0 ) );
}
catch( error ) {
console.error( 'Error accessing localStorage:', error );
Expand Down
4 changes: 2 additions & 2 deletions js/preferences/VoicingPanelSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Property from '../../../axon/js/Property.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 { roundToInterval } from '../../../dot/js/util/roundToInterval.js';
import merge from '../../../phet-core/js/merge.js';
import optionize, { combineOptions, EmptySelfOptions } from '../../../phet-core/js/optionize.js';
import NumberControl from '../../../scenery-phet/js/NumberControl.js';
Expand Down Expand Up @@ -501,7 +501,7 @@ class VoicingPitchSlider extends VBox {

// constrain the value to the nearest hundredths place so there is no overlap in described ranges in
// VOICE_PITCH_DESCRIPTION_MAP
constrainValue: value => Utils.roundToInterval( value, 0.01 ),
constrainValue: value => roundToInterval( value, 0.01 ),

// pdom
labelTagName: 'label',
Expand Down

0 comments on commit 7129659

Please sign in to comment.