From a3ebdcdbc38226daf2adb049bd4eb214397a0215 Mon Sep 17 00:00:00 2001 From: Jesse Mazzella Date: Thu, 3 Oct 2024 13:29:21 -0700 Subject: [PATCH 1/2] feat: add function to generate a seeded random value --- src/utils/random.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/utils/random.js diff --git a/src/utils/random.js b/src/utils/random.js new file mode 100644 index 00000000000..f8d82a9a056 --- /dev/null +++ b/src/utils/random.js @@ -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 }; From 51b0526955f9465ff49b118f18aac434a969ed6e Mon Sep 17 00:00:00 2001 From: Jesse Mazzella Date: Thu, 3 Oct 2024 13:30:08 -0700 Subject: [PATCH 2/2] fix: produce the same compass orientation per timestamp - helps for consistent visual tests --- example/imagery/plugin.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/example/imagery/plugin.js b/example/imagery/plugin.js index 9d37bbc925a..7194e4724e6 100644 --- a/example/imagery/plugin.js +++ b/example/imagery/plugin.js @@ -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 };