-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3174 from manuelmeister/improve/picasso
Improve picasso & avatars
- Loading branch information
Showing
28 changed files
with
1,018 additions
and
369 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { lerp, clamp, invlerp, range } from '../interpolation.js' | ||
|
||
describe('lerp', () => { | ||
it.each([ | ||
[[0, 50, 0.5], 25], | ||
[[1, 3, 0.5], 2], | ||
[[0, 5, 0.2], 1], | ||
[[2, 7, 1], 7], | ||
[[8, 4, 0.5], 6], | ||
[[5, 4, 1], 4], | ||
[[3, 7, 2], 11], | ||
[[2, 3, 3], 5], | ||
[[-8, -4, 0.5], -6], | ||
[[-2, -4, 0.25], -2.5], | ||
[[0, 10, 0.1], 1], | ||
[[10, 50, 1], 50], | ||
])('maps %p to %p', (input, expected) => { | ||
expect(lerp(...input)).toEqual(expected) | ||
}) | ||
}) | ||
|
||
describe('clamp', () => { | ||
it.each([ | ||
[[0.5, 0, 50], 0.5], | ||
[[3, 0, 5], 3], | ||
[[2, -5, 10], 2], | ||
[[8, 1, 3], 3], | ||
[[5, -1, 2], 2], | ||
[[3, 5, 10], 5], | ||
[[1, 2, 3], 2], | ||
[[11, 0, 10], 10], | ||
[[1, 10, 50], 10], | ||
])('maps %p to %p', (input, expected) => { | ||
expect(clamp(...input)).toEqual(expected) | ||
}) | ||
}) | ||
|
||
describe('invlerp', () => { | ||
it.each([ | ||
[[0, 2, 1], 0.5], | ||
[[-10, 0, -5], 0.5], | ||
[[-10, 10, 8], 0.9], | ||
[[3, 7, 5], 0.5], | ||
[[-1, 1, 10], 1], | ||
[[99, 101, 42], 0], | ||
[[-100, 100, -100], 0], | ||
])('maps %p to %p', (input, expected) => { | ||
expect(invlerp(...input)).toEqual(expected) | ||
}) | ||
}) | ||
|
||
describe('range', () => { | ||
it.each([ | ||
[[0, 1, 10, 20, 0.5], 15], | ||
[[10, 0, 20, 40, 7.5], 25], | ||
[[-10, 10, 8, 96, 5], 74], | ||
[[16, 32, 8, 14, 24], 11], | ||
[[-100, 100, 0, 100, 0], 50], | ||
[[-100, 100, 0, 100, 50], 75], | ||
[[42, 42, 0, 100, 42], NaN], | ||
[[1337, 50, 0, 100, 42], 100], | ||
])('maps %p to %p', (input, expected) => { | ||
expect(range(...input)).toEqual(expected) | ||
}) | ||
}) |
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,39 @@ | ||
/** | ||
* Curve fitting | ||
* @param x | ||
* @param y | ||
* @param a | ||
* @returns {number} | ||
*/ | ||
export const lerp = (x, y, a) => x * (1 - a) + y * a | ||
|
||
/** | ||
* Clamps value between min and max | ||
* @param a | ||
* @param min | ||
* @param max | ||
* @returns {number} | ||
*/ | ||
export const clamp = (a, min = 0, max = 1) => Math.min(max, Math.max(min, a)) | ||
|
||
/** | ||
* Inverse curve fitting function | ||
* @param x | ||
* @param y | ||
* @param a | ||
* @returns {number} | ||
*/ | ||
export const invlerp = (x, y, a) => clamp((a - x) / (y - x)) | ||
|
||
/** | ||
* Maps input to output range | ||
* @param inputStart | ||
* @param inputEnd | ||
* @param outputStart | ||
* @param outputEnd | ||
* @param input | ||
* @returns number | ||
*/ | ||
export function range(inputStart, inputEnd, outputStart, outputEnd, input) { | ||
return lerp(outputStart, outputEnd, invlerp(inputStart, inputEnd, input)) | ||
} |
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
Oops, something went wrong.