Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(visual): Stabilize compass per timestamp #7866

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions example/imagery/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
};
Expand Down
12 changes: 12 additions & 0 deletions src/utils/random.js
Original file line number Diff line number Diff line change
@@ -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