Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/packages/firebird-core/src/painters/trajectory.painter.spec.ts is written in an unsupported language. File is not indexed.

0001 // trajectory.painter.spec.ts
0002 import { TrajectoryPainter } from './trajectory.painter';
0003 import { PointTrajectoryPiece } from '../model/point-trajectory.piece';
0004 
0005 describe('TrajectoryPainter', () => {
0006     let mockParentNode: any;
0007     let trajectoryPiece: PointTrajectoryPiece;
0008 
0009     beforeEach(() => {
0010         // Create a simple mock parent node
0011         mockParentNode = {
0012             add: vi.fn(),
0013             remove: vi.fn()
0014         };
0015 
0016         // Create a real PointTrajectoryPiece with columnar test data
0017         trajectoryPiece = new PointTrajectoryPiece('TestTrajectories');
0018         trajectoryPiece.pointColumns = ['x', 'y', 'z', 't'];
0019         trajectoryPiece.count = 3;
0020         // trajectory id == index in every column
0021         trajectoryPiece.columns = {
0022             pdg: [11, 22, 2212],      // electron, gamma, proton
0023             charge: [-1, 0, 1],
0024         };
0025         trajectoryPiece.points = [
0026             // Track 1: t=10 to t=20
0027             [[0, 0, 0, 10], [10, 0, 0, 20]],
0028             // Track 2: t=15 to t=35
0029             [[0, 10, 0, 15], [10, 10, 0, 25], [20, 10, 0, 35]],
0030             // Track 3: t=40 to t=50
0031             [[0, 20, 0, 40], [10, 20, 0, 50]],
0032         ];
0033     });
0034 
0035     describe('initLines', () => {
0036         it('should create the correct number of trajectories', () => {
0037 
0038             // Create a test instance
0039             const testPainter = new TrajectoryPainter(mockParentNode, trajectoryPiece);
0040 
0041             // Check if trajectories were created correctly
0042             expect(testPainter.trajectories.length).toBe(3);
0043             expect(mockParentNode.add).toHaveBeenCalled();
0044         });
0045 
0046         it('should attach per-trajectory params read from the columns', () => {
0047             const testPainter = new TrajectoryPainter(mockParentNode, trajectoryPiece);
0048             expect(testPainter.trajectories[0].params['pdg']).toBe(11);
0049             expect(testPainter.trajectories[2].params['charge']).toBe(1);
0050         });
0051     });
0052 
0053     describe('paintNoTime', () => {
0054         it('should make all trajectories fully visible', () => {
0055             // Create a painter instance with real initialization
0056             const testPainter = new TrajectoryPainter(mockParentNode, trajectoryPiece);
0057 
0058             // Reset visibility and instance count for testing
0059             testPainter.trajectories.forEach(track => {
0060                 track.lineObj.visible = false;
0061                 track.lineObj.geometry.instanceCount = 0;
0062             });
0063 
0064             // Call paint with no time
0065             testPainter.paint(null);
0066 
0067             // Verify all trajectories are visible with instanceCount = points.length - 1
0068             testPainter.trajectories.forEach(track => {
0069                 expect(track.lineObj.visible).toBe(true);
0070                 expect(track.lineObj.geometry.instanceCount).toBe(track.points.length - 1);
0071             });
0072         });
0073     });
0074 
0075 
0076     describe('fastPaint', () => {
0077         let painter: TrajectoryPainter;
0078 
0079         beforeEach(() => {
0080             // Create a real painter instance
0081             painter = new TrajectoryPainter(mockParentNode, trajectoryPiece);
0082 
0083             // Verify we have trajectories initialized
0084             expect(painter.trajectories.length).toBeGreaterThan(0);
0085         });
0086 
0087         it('should hide tracks that have not started yet', () => {
0088             painter.paint(5); // Before any track starts
0089 
0090             painter.trajectories.forEach(track => {
0091                 expect(track.lineObj.visible).toBe(false);
0092             });
0093         });
0094 
0095         it('should fully show tracks that have ended', () => {
0096             painter.paint(30); // After track 1 ends
0097 
0098             // Track 1 should be fully visible
0099             expect(painter.trajectories[0].lineObj.visible).toBe(true);
0100             expect(painter.trajectories[0].lineObj.geometry.instanceCount).toBe(painter.trajectories[0].points.length - 1);
0101 
0102             // Track 3 should be hidden (not yet started)
0103             expect(painter.trajectories[2].lineObj.visible).toBe(false);
0104         });
0105 
0106         it('should partially show tracks based on time', () => {
0107             painter.paint(30); // In the middle of track 2
0108 
0109             // Track 2 should be partially visible (2 points)
0110             expect(painter.trajectories[1].lineObj.visible).toBe(true);
0111             expect(painter.trajectories[1].lastPaintIndex).toBe(1);
0112         });
0113 
0114         it('should handle time moving forward correctly', () => {
0115             // First time point
0116             painter.paint(20);
0117             expect(painter.trajectories[1].lastPaintIndex).toBe(0);
0118 
0119             // Move forward
0120             painter.paint(30);
0121             expect(painter.trajectories[1].lastPaintIndex).toBe(1);
0122         });
0123 
0124         it('should handle time moving backward correctly', () => {
0125             // First at later time
0126             painter.paint(40);
0127             expect(painter.trajectories[1].lastPaintIndex).toBe(2);
0128 
0129             // Move backward
0130             painter.paint(20);
0131             expect(painter.trajectories[1].lastPaintIndex).toBe(0);
0132         });
0133 
0134         it('should handle invalid lastPaintIndex', () => {
0135             // Set invalid index
0136             painter.trajectories[1].lastPaintIndex = 999;
0137 
0138             // Should recover gracefully
0139             painter.paint(30);
0140 
0141             // Should have valid index now
0142             expect(painter.trajectories[1].lastPaintIndex).toBeLessThan(painter.trajectories[1].points.length);
0143         });
0144     });
0145 });