From 6d32a9abb496e4ef8fe5d796573e1fa72d484c3a Mon Sep 17 00:00:00 2001 From: Joe Heffernan Date: Mon, 30 Sep 2024 11:36:18 -0700 Subject: [PATCH] define constants for bytes per js number and bytes per agent data --- src/constants.ts | 4 ++++ src/util.ts | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 6ac52ab3..18b11e76 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,5 @@ import { + AGENT_OBJECT_KEYS, AgentData, CameraSpec, PerspectiveCameraSpec, @@ -52,3 +53,6 @@ export const nullAgent = (): AgentData => { // the size of the header before the agent data in the binary file export const AGENT_HEADER_SIZE = 3; // frameNumber, time, agentCount + +export const BYTE_SIZE_64_BIT_NUM = 8; +export const BYTES_PER_AGENT = BYTE_SIZE_64_BIT_NUM * AGENT_OBJECT_KEYS.length; diff --git a/src/util.ts b/src/util.ts index cdbe3400..3e4d3190 100644 --- a/src/util.ts +++ b/src/util.ts @@ -2,7 +2,7 @@ import type { ISimulariumFile } from "./simularium/ISimulariumFile"; import JsonFileReader from "./simularium/JsonFileReader"; import BinaryFileReader from "./simularium/BinaryFileReader"; import { AGENT_OBJECT_KEYS, AgentData, CachedFrame } from "./simularium/types"; -import { nullAgent } from "./constants"; +import { BYTES_PER_AGENT, BYTE_SIZE_64_BIT_NUM, nullAgent } from "./constants"; export const compareTimes = ( time1: number, @@ -83,8 +83,8 @@ export function calculateCachedSize(parsedAgentData: AgentData[]): number { // Calculate the size of parsedAgentDataArray for (let j = 0; j < parsedAgentData.length; ++j) { const agent = parsedAgentData[j]; - totalSize += 8 * 10; // 10 number properties in AgentData (excluding subpoints) - totalSize += agent.subpoints.length * 8; + totalSize += BYTES_PER_AGENT; // 10 number properties in AgentData (excluding subpoints) + totalSize += agent.subpoints.length * BYTE_SIZE_64_BIT_NUM; } return (totalSize += 16); // should always be 16 bytes bceause its just one frame per message with octopus