Skip to content

Commit

Permalink
Fix/null agent function (#396)
Browse files Browse the repository at this point in the history
* use function to get null agent

* use createNullAgent in viewer

* nullAgent instead of createNullAgent

* unused import
  • Loading branch information
interim17 authored Jun 13, 2024
1 parent b817c4f commit 17dc7d3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions examples/src/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -175,7 +175,7 @@ const initialState: ViewerState = {
trajectoryTitle: "",
initialPlay: true,
firstFrameTime: 0,
followObjectData: NULL_AGENT,
followObjectData: nullAgent(),
};

class Viewer extends React.Component<InputParams, ViewerState> {
Expand Down
26 changes: 14 additions & 12 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
};
};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 2 additions & 2 deletions src/simularium/VisData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[][];
Expand Down Expand Up @@ -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++];
Expand Down
4 changes: 2 additions & 2 deletions src/visGeometry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 17dc7d3

Please sign in to comment.