agentjs-core
Version:
A comprehensive agent-based modeling framework with built-in p5.js visualization
108 lines (106 loc) • 2.72 kB
TypeScript
import { Agent } from '../core/agents/Agent';
import { Camera } from '../visualization/Camera';
/**
* Viewport bounds for culling calculations
*/
export interface ViewportBounds {
left: number;
right: number;
top: number;
bottom: number;
width: number;
height: number;
}
/**
* Culling result information
*/
export interface CullingResult {
visibleAgents: Agent[];
culledAgents: Agent[];
totalAgents: number;
visibleCount: number;
culledCount: number;
cullRatio: number;
}
/**
* Level of detail settings
*/
export interface LODSettings {
enabled: boolean;
nearDistance: number;
midDistance: number;
farDistance: number;
nearDetail: 'full' | 'medium' | 'low';
midDetail: 'full' | 'medium' | 'low';
farDetail: 'full' | 'medium' | 'low';
}
/**
* Viewport culling system for performance optimization
*/
export declare class ViewportCuller {
private spatialGrid;
private lodSettings;
private lastCullingResult;
private performanceStats;
constructor(cellSize?: number, lodSettings?: Partial<LODSettings>);
/**
* Update spatial index with current agents
*/
updateSpatialIndex(agents: Agent[]): void;
/**
* Perform viewport culling
*/
cullAgents(agents: Agent[], camera: Camera): CullingResult;
/**
* Get viewport bounds in world coordinates
*/
private getViewportBounds;
/**
* Check if position is within viewport bounds
*/
private isInViewport;
/**
* Get agent position
*/
private getAgentPosition;
/**
* Calculate distance from position to camera
*/
private getDistanceToCamera;
/**
* Get LOD level based on distance
*/
private getLODLevel;
/**
* Update LOD settings
*/
updateLODSettings(settings: Partial<LODSettings>): void;
/**
* Get LOD settings
*/
getLODSettings(): Readonly<LODSettings>;
/**
* Get last culling result
*/
getLastCullingResult(): CullingResult | null;
/**
* Get performance statistics
*/
getPerformanceStats(): Readonly<typeof this.performanceStats>;
/**
* Check if an agent should be rendered based on LOD
*/
shouldRenderAgent(agent: Agent, renderLevel?: 'full' | 'medium' | 'low'): boolean;
/**
* Get visible agents by LOD level
*/
getVisibleAgentsByLOD(lodLevel: 'full' | 'medium' | 'low'): Agent[];
/**
* Reset performance statistics
*/
resetPerformanceStats(): void;
}
/**
* Factory function for creating viewport cullers
*/
export declare function createViewportCuller(cellSize?: number, lodSettings?: Partial<LODSettings>): ViewportCuller;