From 17dc7d313c29f1532c6c6e9ce3e4f1cda793094f Mon Sep 17 00:00:00 2001 From: Joe Heffernan Date: Thu, 13 Jun 2024 09:51:37 -0700 Subject: [PATCH] Fix/null agent function (#396) * use function to get null agent * use createNullAgent in viewer * nullAgent instead of createNullAgent * unused import --- examples/src/Viewer.tsx | 4 ++-- src/constants.ts | 26 ++++++++++++++------------ src/index.ts | 1 + src/simularium/VisData.ts | 4 ++-- src/visGeometry/index.ts | 4 ++-- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/examples/src/Viewer.tsx b/examples/src/Viewer.tsx index 887891c1..80c8a803 100644 --- a/examples/src/Viewer.tsx +++ b/examples/src/Viewer.tsx @@ -8,7 +8,7 @@ import type { SelectionStateInfo, SelectionEntry, } from "../../type-declarations"; -import { NULL_AGENT, TrajectoryType } from "../../src/constants"; +import { nullAgent, TrajectoryType } from "../../src/constants"; import SimulariumViewer, { SimulariumController, RenderStyle, @@ -175,7 +175,7 @@ const initialState: ViewerState = { trajectoryTitle: "", initialPlay: true, firstFrameTime: 0, - followObjectData: NULL_AGENT, + followObjectData: nullAgent(), }; class Viewer extends React.Component { diff --git a/src/constants.ts b/src/constants.ts index 597d18c3..42c7f026 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -34,16 +34,18 @@ export const enum TrajectoryType { export const DEFAULT_FRAME_RATE = 60; // frames per second -export const NULL_AGENT: AgentData = { - "vis-type": -1, - instanceId: -1, - type: -1, - x: 0, - y: 0, - z: 0, - xrot: 0, - yrot: 0, - zrot: 0, - cr: 0, - subpoints: [], +export const nullAgent = (): AgentData => { + return { + "vis-type": -1, + instanceId: -1, + type: -1, + x: 0, + y: 0, + z: 0, + xrot: 0, + yrot: 0, + zrot: 0, + cr: 0, + subpoints: [], + }; }; diff --git a/src/index.ts b/src/index.ts index fa7a74c5..7625c064 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,5 +28,6 @@ export { } from "./simularium"; export { compareTimes, loadSimulariumFile } from "./util"; export { DEFAULT_CAMERA_SPEC } from "./constants"; +export { AgentData } from "./simularium/types"; export default Viewport; diff --git a/src/simularium/VisData.ts b/src/simularium/VisData.ts index 4f808a13..ea491f2d 100644 --- a/src/simularium/VisData.ts +++ b/src/simularium/VisData.ts @@ -14,7 +14,7 @@ import { import { FrontEndError, ErrorLevel } from "./FrontEndError"; import type { ParsedBundle } from "./VisDataParse"; import { parseVisDataMessage } from "./VisDataParse"; -import { NULL_AGENT } from "../constants"; +import { nullAgent } from "../constants"; class VisData { private frameCache: AgentData[][]; @@ -49,7 +49,7 @@ class VisData { let j = AGENTS_OFFSET; for (let i = 0; i < expectedNumAgents; i++) { //TODO use visType in AgentData and convert from "vis-type" here at parse time - const agentData: AgentData = { ...NULL_AGENT }; + const agentData: AgentData = nullAgent(); for (let k = 0; k < AGENT_OBJECT_KEYS.length; ++k) { agentData[AGENT_OBJECT_KEYS[k]] = floatView[j++]; diff --git a/src/visGeometry/index.ts b/src/visGeometry/index.ts index f9d97c35..fab9cb73 100644 --- a/src/visGeometry/index.ts +++ b/src/visGeometry/index.ts @@ -41,7 +41,7 @@ import { FrontEndError, ErrorLevel } from "../simularium/FrontEndError"; import { DEFAULT_CAMERA_Z_POSITION, DEFAULT_CAMERA_SPEC, - NULL_AGENT, + nullAgent, } from "../constants"; import { AgentData, @@ -653,7 +653,7 @@ class VisGeometry { public getObjectData(id: number): AgentData { const data = this.visAgentInstances.get(id); if (!data) { - return NULL_AGENT; + return nullAgent(); } return data.agentData; }