Static
Readonly
COMPILE_Date and time when the code was compiled.
This value is set during the esbuild
bundling phase with a --define
option.
Static
Readonly
DEBUGFlag indicates whether to include debug code, must be true for assertions
to work. Must be set as a compiler option, by adding UTIL_DEBUG=true
to
the compile command. For example: make testviewer UTIL_DEBUG=true
.
See the shell script compile_js.sh
and makefile
for details.
See Customizing The Build Process.
Static
Private
Readonly
HEX_A string listing the the hexadecimal digits '0123456789abcdef'
Static
IMAGES_Specifies the relative URL of the directory containing images related to the user interface.
Static
LOCALESpecifies the language to use. The
ISO 639-1 language code
is a two-letter lowercase code. For example, English is en
, and German is de
.
This value is set during the esbuild
bundling phase with a --define
option.
Static
Readonly
MAX_Maximum representable integer. Need to avoid having an index ever reach this value because we can then no longer increment by 1. That is: 2^53 + 1 == 2^53 because of how floating point works.
Static
Readonly
MIN_Minimum representable integer.
Static
Readonly
MODERN_Whether running under a modern browser that supports performance.now()
;
Static
NFThe default number format to use in toString
methods.
The default number format to use in toString
methods.
Static
Readonly
NOT_String used to mark functions that have not been implemented.
Static
Readonly
VERSIONReturns the current version number for the myphysiclab library, using Semantic Versioning.
Given a version number MAJOR.MINOR.PATCH, increment the:
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
Static
Private
Readonly
maxMaximum number of errors to report by setErrorHandler.
Static
Private
numNumber of errors reported by setErrorHandler.
Static
NF0Static
NF18Static
NF1SStatic
NF2Static
NF3Static
NF4Static
NF5Static
NF5EStatic
NF7Static
NF7EStatic
NF9Static
NFEStatic
NFSCIStatic
array2stringConverts an array of numbers to a string, with a separator string between each number.
the array to print
Optional
nf: ((n) => string)number format function to use
Optional
separator: stringthe text to insert between each value; default is
a comma and space ,
the array of numbers converted to a string
Static
arrayConverts an array of booleans to string, with commas between each boolean.
the array to print
Optional
trueString: stringthe string that indicates a true value; default true
Optional
falseString: stringthe string that indicates a false value; default false
the array of booleans converted to a string
Static
assertassert throws an error if the test is not true.
TO DO: The idea of assertions is that they disappear when you turn off the ASSERTS flag. Here they would be disabled with ASSERTS flag false, but the code doesn't disappear.
whether the assertion is true or false
Optional
opt_message: stringoptional message to print to console if assertion is false
Static
colorReturns a CSS3 color string
composed of a #
followed by 3 hex digits corresponding to given red, green, blue
proportions.
proportion of red from 0.0 to 1.0
proportion of green from 0.0 to 1.0
proportion of blue from 0.0 to 1.0
the corresponding CSS3 color string with 3 hex digits
Static
colorReturns a CSS3 color string
composed of a #
followed by 6 hex digits corresponding to given red, green, blue
proportions.
proportion of red from 0.0 to 1.0
proportion of green from 0.0 to 1.0
proportion of blue from 0.0 to 1.0
the corresponding CSS3 color string with 6 hex digits
Static
createCreates an HTMLImageElement
from the given URL.
location of the image as a URL
width of the image in pixels
Optional
opt_height: numberoptional height of image in pixels
an HTMLImageElement
Static
defineStatic
dropStatic
equalsReturns whether the arrays are equal.
true
if arrays are same length and have same elements in each position
Static
forStatic
getStatic
getStatic
hypotStatic
isStatic
isIPhoneStatic
isStatic
limitStatic
maybeStatic
methodsStatic
nameReturns the name of the property with the given value, within the given object.
the object whose values are examined
the value of interest
the name of the property with the given value, within the object; or the empty string if value not found.
Static
newStatic
newStatic
nf5Static
nf7Static
numStatic
numStatic
prettyFormats the toString
represention of an object to be more readable. Adds
newlines and spaces so that each property of an object appears on a separate line, and
is indented according to the "level depth" of objects being formatted.
Assumes that the object's toString
is formatted according to Javascript conventions
like this:
ClassName{property1: value1, property2: value2}
Semi-colons or commas are equivalent for separating properties. Assumes that arrays
are formatted like standard JavaScript as [object1, object2, object3]
.
The level
depth works as follows: Level 1 means that the each property of the
object appears on a separate line preceded a single indent string. For example:
ClassName{
property1: value1,
property2: value2,
}
Level 2 is like level 1, but additionally any object that appears as the value of a level 1 property is also expanded:
ClassName{
property1: ClassName2{
property3: value3,
property4: value4
},
property2: value2,
}
Level 3 adds another level of expansion for objects found at Level 2. And so on for higher levels.
ClassName{
property1: ClassName2{
property3: value3,
property4: ClassName3{
property5: value5,
property6: value6
}
},
property2: value2,
}
The "property detection" is done by looking for commas or semicolons.
A new level is begun whenever an opening brace {
or square bracket [
is seen.
Anything in quotes is ignored. Works for arrays also.
TO DO escaped quotes in strings should be ignored.
the string to reformat. Typically this is the
toString
representation of an object.
Optional
level: numberhow much nesting of the object to pay attention to. Nesting
occurs whenever opening braces {
or brackets [
are seen in the input string.
Default is 2.
Optional
indent: stringString to use for indenting each new level. Default is two spaces.
the input string formatted to be more readable
Static
printPrints array of numbers to console.log
on multiple lines so that each line
is no longer than lineLength
.
the array to print
Optional
lineLength: numbermaximum length of a line, default 80
Optional
format: ((n) => string)formatting function, default is NF5E
Static
printStatic
propertiesReturns list of names of (non-function) properties defined on the given object, and optionally also shows the values of the properties.
the object to examine, or null
Optional
showValues: booleanwhether to show values of the properties (default is false
)
array of names of properties of the object (and possibly their values)
Static
rangeStatic
removeremoves the first occurence of the object from the array.
true if the object was removed
Static
removeremoves all copies of the object from the array.
true if the object was removed
Static
removeStatic
repeatStatic
setStatic
setSpecifies the relative URL of the directory containing images related to the user interface. The value is accessible via IMAGES_DIR.
Optional
images_dir: stringthe relative URL of the images directory;
if undefined IMAGES_DIR
is not changed.
Static
showStatic
systemStatic
takeStatic
testStatic
testStatic
toReturns the language independent form of the given string by changing to uppercase and replacing spaces and dashes with underscores.
the text to convert
the text upper-cased and with spaces and dashes replaced by underscores
Static
uniqueStatic
validEnsures the given text consists of only uppercase letters, numbers and underscore and first character is a letter or underscore. This is required for language independent names.
the text to validate
the validated text
if text does not qualify as a name
Static
veryReturns true
if the numbers are significantly different to a certain tolerance
level, adjusting the tolerance for larger numbers.
For numbers with absolute value smaller than magnitude
the numbers are compared using
a fixed tolerance of magnitude*epsilon
.
For numbers with absolute value larger than magnitude
, the tolerance is
epsilon
times the larger of the absolute values of the numbers being compared.
Unless specified, the default for magnitude
is 1.0 and epsilon
is 1E-14. These
settings return true
if the numbers are significantly different to approximately 14
decimal digits when their magnitude is near 1.0.
The goal is to have a test that is immune to the inaccuracy of double arithmetic. Doubles have 15 to 17 significant decimal digits of accuracy, so comparing 14 significant digits should be fairly safe from the inaccuracy in double arithmetic.
This method takes into account the size of the numbers being compared, so it is safer than code such as
if (Math.abs(a - b) > 1E-16) // do something
Doubles have 15 to 17 significant decimal digits of accuracy. When the numbers being compared are much bigger in magnitude than 1.0, then this test is too strict -- it effectively is comparing to zero, meaning exact equality.
See Comparing Floating Point Numbers, 2012 Edition by Bruce Dawson.
See StackOverflow: How dangerous is it to compare floating point values?
the first number to compare
the second number to compare
Optional
epsilon: numberthe small value used with magnitude
to calculate the tolerance
for deciding when the numbers are different, default is 1E-14.
Optional
magnitude: numberthe approximate magnitude of the numbers being compared, default is 1.0.
true if the doubles are different to 14 significant decimal digits
if magnitude
or epsilon
is negative or zero
Static
zeroGenerated using TypeDoc
Provides generally useful static functions.