mirror of
https://github.com/nasa/openmct.git
synced 2024-12-18 20:57:53 +00:00
test(visual): Stabilize compass per timestamp (#7866)
* feat: add function to generate a seeded random value * fix: produce the same compass orientation per timestamp - helps for consistent visual tests --------- Co-authored-by: John Hill <john.c.hill@nasa.gov>
This commit is contained in:
parent
4415fe7952
commit
f4cf9c756b
@ -20,6 +20,8 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
import { seededRandom } from 'utils/random.js';
|
||||
|
||||
const DEFAULT_IMAGE_SAMPLES = [
|
||||
'https://www.nasa.gov/wp-content/uploads/static/history/alsj/a16/AS16-117-18731.jpg',
|
||||
'https://www.nasa.gov/wp-content/uploads/static/history/alsj/a16/AS16-117-18732.jpg',
|
||||
@ -162,8 +164,8 @@ export default function () {
|
||||
};
|
||||
}
|
||||
|
||||
function getCompassValues(min, max) {
|
||||
return min + Math.random() * (max - min);
|
||||
function getCompassValues(min, max, timestamp) {
|
||||
return min + seededRandom(timestamp) * (max - min);
|
||||
}
|
||||
|
||||
function getImageSamples(configuration) {
|
||||
@ -283,9 +285,9 @@ function pointForTimestamp(timestamp, name, imageSamples, delay) {
|
||||
utc: Math.floor(timestamp / delay) * delay,
|
||||
local: Math.floor(timestamp / delay) * delay,
|
||||
url,
|
||||
sunOrientation: getCompassValues(0, 360),
|
||||
cameraAzimuth: getCompassValues(0, 360),
|
||||
heading: getCompassValues(0, 360),
|
||||
sunOrientation: getCompassValues(0, 360, timestamp),
|
||||
cameraAzimuth: getCompassValues(0, 360, timestamp),
|
||||
heading: getCompassValues(0, 360, timestamp),
|
||||
transformations: navCamTransformations,
|
||||
imageDownloadName
|
||||
};
|
||||
|
12
src/utils/random.js
Normal file
12
src/utils/random.js
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Generates a pseudo-random number based on a seed.
|
||||
*
|
||||
* @param {number} seed - The seed value to generate the random number.
|
||||
* @returns {number} A pseudo-random number between 0 (inclusive) and 1 (exclusive).
|
||||
*/
|
||||
function seededRandom(seed = Date.now()) {
|
||||
const x = Math.sin(seed) * 10000;
|
||||
return x - Math.floor(x);
|
||||
}
|
||||
|
||||
export { seededRandom };
|
Loading…
Reference in New Issue
Block a user