-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
progress on dot Util separation, see #4
- Loading branch information
1 parent
d1f7ba7
commit 10dd112
Showing
16 changed files
with
189 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,10 @@ | |
* | ||
* @author Jonathan Olson <[email protected]> | ||
*/ | ||
export default function clamp( value: number, min: number, max: number ): number { | ||
|
||
import dot from '../dot.js'; | ||
|
||
export function clamp( value: number, min: number, max: number ): number { | ||
if ( value < min ) { | ||
return min; | ||
} | ||
|
@@ -16,4 +19,5 @@ export default function clamp( value: number, min: number, max: number ): number | |
else { | ||
return value; | ||
} | ||
} | ||
} | ||
dot.register( 'clamp', clamp ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,12 @@ | |
* | ||
* @author Chris Malley ([email protected]) | ||
*/ | ||
|
||
import dot from '../dot.js'; | ||
|
||
export default function distanceXY( x1: number, y1: number, x2: number, y2: number ): number { | ||
const dx = x1 - x2; | ||
const dy = y1 - y2; | ||
return Math.sqrt( dx * dx + dy * dy ); | ||
} | ||
} | ||
dot.register( 'distanceXY', distanceXY ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
// Copyright 2025, University of Colorado Boulder | ||
// Copyright 2025, University of Colorado Boulder | ||
|
||
/** | ||
* Computes the factorial of a non-negative integer n without using recursion. | ||
* n! = 1 * 2 * ... * ( n - 1 ) * n | ||
* | ||
* @author Chris Malley ([email protected]) | ||
*/ | ||
export default function factorial( n: number ): number { | ||
assert && assert( Number.isInteger( n ) && n >= 0, `n must be a non-negative integer: ${n}` ); | ||
let f = 1; | ||
for ( let i = 2; i <= n; i++ ) { | ||
f *= i; | ||
} | ||
return f; | ||
} | ||
/** | ||
* Computes the factorial of a non-negative integer n without using recursion. | ||
* n! = 1 * 2 * ... * ( n - 1 ) * n | ||
* | ||
* @author Chris Malley ([email protected]) | ||
*/ | ||
|
||
import dot from '../dot.js'; | ||
|
||
export default function factorial( n: number ): number { | ||
assert && assert( Number.isInteger( n ) && n >= 0, `n must be a non-negative integer: ${n}` ); | ||
let f = 1; | ||
for ( let i = 2; i <= n; i++ ) { | ||
f *= i; | ||
} | ||
return f; | ||
} | ||
|
||
dot.register( 'factorial', factorial ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2025, University of Colorado Boulder | ||
|
||
/** | ||
* Returns a number in the range $n\in[\mathrm{min},\mathrm{max})$ with the same equivalence class as the input | ||
* value mod (max-min), i.e. for a value $m$, $m\equiv n\ (\mathrm{mod}\ \mathrm{max}-\mathrm{min})$. | ||
* | ||
* The 'down' indicates that if the value is equal to min or max, the max is returned. | ||
* | ||
* @author Jonathan Olson <[email protected]> | ||
*/ | ||
|
||
import dot from '../dot.js'; | ||
|
||
export function moduloBetweenDown( value: number, min: number, max: number ): number { | ||
assert && assert( max > min, 'max > min required for moduloBetween' ); | ||
|
||
const divisor = max - min; | ||
|
||
// get a partial result of value-min between [0,divisor) | ||
let partial = ( value - min ) % divisor; | ||
if ( partial < 0 ) { | ||
// since if value-min < 0, the remainder will give us a negative number | ||
partial += divisor; | ||
} | ||
|
||
return partial + min; // add back in the minimum value | ||
} | ||
dot.register( 'moduloBetweenDown', moduloBetweenDown ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2025, University of Colorado Boulder | ||
|
||
/** | ||
* Returns a number in the range $n\in(\mathrm{min},\mathrm{max}]$ with the same equivalence class as the input | ||
* value mod (max-min), i.e. for a value $m$, $m\equiv n\ (\mathrm{mod}\ \mathrm{max}-\mathrm{min})$. | ||
* | ||
* The 'up' indicates that if the value is equal to min or max, the min is returned. | ||
* | ||
* @author Jonathan Olson <[email protected]> | ||
*/ | ||
|
||
import { moduloBetweenDown } from './moduloBetweenDown.js'; | ||
import dot from '../dot.js'; | ||
|
||
export function moduloBetweenUp( value: number, min: number, max: number ): number { | ||
return -moduloBetweenDown( -value, -max, -min ); | ||
} | ||
dot.register( 'moduloBetweenUp', moduloBetweenUp ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2025, University of Colorado Boulder | ||
|
||
/** | ||
* Returns an array of integers from A to B (exclusive), e.g. rangeExclusive( 4, 7 ) maps to [ 5, 6 ]. | ||
* | ||
* @author Jonathan Olson <[email protected]> | ||
*/ | ||
|
||
import { rangeInclusive } from './rangeInclusive.js'; | ||
import dot from '../dot.js'; | ||
|
||
export function rangeExclusive( a: number, b: number ): number[] { | ||
return rangeInclusive( a + 1, b - 1 ); | ||
} | ||
dot.register( 'rangeExclusive', rangeExclusive ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2025, University of Colorado Boulder | ||
|
||
/** | ||
* Returns an array of integers from A to B (inclusive), e.g. rangeInclusive( 4, 7 ) maps to [ 4, 5, 6, 7 ]. | ||
* | ||
* @author Jonathan Olson <[email protected]> | ||
*/ | ||
|
||
import dot from '../dot.js'; | ||
|
||
export function rangeInclusive( a: number, b: number ): number[] { | ||
if ( b < a ) { | ||
return []; | ||
} | ||
const result = new Array( b - a + 1 ); | ||
for ( let i = a; i <= b; i++ ) { | ||
result[ i - a ] = i; | ||
} | ||
return result; | ||
} | ||
dot.register( 'rangeInclusive', rangeInclusive ); |
Oops, something went wrong.