simple-circuit-engine 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +13 -7
- package/CLAUDE.md +16 -103
- package/README.md +8 -5
- package/dist/core/index.d.ts +2 -23
- package/dist/core/index.js +75 -2000
- package/dist/core/setup.d.ts +17 -0
- package/dist/core/simulation/CircuitRunner.d.ts +176 -0
- package/dist/core/simulation/DirtyTracker.d.ts +87 -0
- package/dist/core/simulation/EventQueue.d.ts +68 -0
- package/dist/core/simulation/StateManager.d.ts +100 -0
- package/dist/core/simulation/behaviors/BehaviorRegistry.d.ts +70 -0
- package/dist/core/simulation/behaviors/ComponentBehavior.d.ts +53 -0
- package/dist/core/simulation/behaviors/basic/BatteryBehavior.d.ts +14 -0
- package/dist/core/simulation/behaviors/basic/ClockBehavior.d.ts +24 -0
- package/dist/core/simulation/behaviors/basic/DoubleThrowSwitchBehavior.d.ts +33 -0
- package/dist/core/simulation/behaviors/basic/LightbulbBehavior.d.ts +23 -0
- package/dist/core/simulation/behaviors/basic/RectangleLEDBehavior.d.ts +24 -0
- package/dist/core/simulation/behaviors/basic/RelayBehavior.d.ts +33 -0
- package/dist/core/simulation/behaviors/basic/SmallLEDBehavior.d.ts +24 -0
- package/dist/core/simulation/behaviors/basic/SwitchBehavior.d.ts +33 -0
- package/dist/core/simulation/behaviors/basic/index.d.ts +20 -0
- package/dist/core/simulation/behaviors/gates/InverterBehavior.d.ts +29 -0
- package/dist/core/simulation/behaviors/gates/Nand4GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/Nand8GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/NandGateBehavior.d.ts +28 -0
- package/dist/core/simulation/behaviors/gates/Nor4GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/Nor8GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/NorGateBehavior.d.ts +22 -0
- package/dist/core/simulation/behaviors/gates/Xor4GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/Xor8GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/XorGateBehavior.d.ts +22 -0
- package/dist/core/simulation/behaviors/gates/index.d.ts +34 -0
- package/dist/core/simulation/behaviors/index.d.ts +24 -0
- package/dist/core/simulation/behaviors/types.d.ts +101 -0
- package/dist/core/simulation/index.d.ts +18 -0
- package/dist/core/simulation/states/ComponentState.d.ts +57 -0
- package/dist/core/simulation/states/SimulationState.d.ts +46 -0
- package/dist/core/simulation/states/basic/BatteryState.d.ts +16 -0
- package/dist/core/simulation/states/basic/ClockState.d.ts +16 -0
- package/dist/core/simulation/states/basic/DoubleThrowSwitchState.d.ts +21 -0
- package/dist/core/simulation/states/basic/LightbulbState.d.ts +21 -0
- package/dist/core/simulation/states/basic/RectangleLEDState.d.ts +9 -0
- package/dist/core/simulation/states/basic/RelayState.d.ts +25 -0
- package/dist/core/simulation/states/basic/SmallLEDState.d.ts +21 -0
- package/dist/core/simulation/states/basic/SwitchState.d.ts +25 -0
- package/dist/core/simulation/states/gates/InverterState.d.ts +17 -0
- package/dist/core/simulation/states/gates/Nand4GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/Nand8GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/NandGateState.d.ts +16 -0
- package/dist/core/simulation/states/gates/Nor4GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/Nor8GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/NorGateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/Xor4GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/Xor8GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/XorGateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/index.d.ts +25 -0
- package/dist/core/simulation/states/index.d.ts +26 -0
- package/dist/core/simulation/states/types.d.ts +32 -0
- package/dist/core/simulation/types.d.ts +155 -0
- package/dist/core/topology/Circuit.d.ts +420 -0
- package/dist/core/topology/CircuitMetadata.d.ts +24 -0
- package/dist/core/topology/CircuitOptions.d.ts +14 -0
- package/dist/core/topology/Component.d.ts +152 -0
- package/dist/core/topology/ENode.d.ts +200 -0
- package/dist/core/topology/Wire.d.ts +130 -0
- package/dist/core/topology/delays.d.ts +52 -0
- package/dist/core/topology/index.d.ts +14 -0
- package/dist/core/topology/types.d.ts +175 -0
- package/dist/core/utils/CameraOptions.d.ts +83 -0
- package/dist/core/utils/MemoizeDecorator.d.ts +9 -0
- package/dist/core/utils/Position.d.ts +166 -0
- package/dist/core/utils/Position3D.d.ts +77 -0
- package/dist/core/utils/Rotation.d.ts +82 -0
- package/dist/core/utils/index.d.ts +24 -0
- package/dist/core/utils/types.d.ts +35 -0
- package/dist/core-Bjta9Y7_.js +2707 -0
- package/dist/core-Bjta9Y7_.js.map +1 -0
- package/dist/index.d.ts +13 -6286
- package/dist/index.js +120 -100
- package/dist/scene/CircuitEngine.d.ts +270 -0
- package/dist/scene/index.d.ts +1 -2
- package/dist/scene/index.js +44 -38
- package/dist/scene/setup.d.ts +18 -0
- package/dist/scene/shared/AbstractCircuitController.d.ts +211 -0
- package/dist/scene/shared/BranchingPointVisualFactory.d.ts +70 -0
- package/dist/scene/shared/EventEmitter.d.ts +92 -0
- package/dist/scene/shared/HoverManager.d.ts +151 -0
- package/dist/scene/shared/SelectionManager.d.ts +159 -0
- package/dist/scene/shared/WireVisualManager.d.ts +242 -0
- package/dist/scene/shared/components/ComponentVisualFactory.d.ts +438 -0
- package/dist/scene/shared/components/DefaultVisualFactory.d.ts +51 -0
- package/dist/scene/shared/components/FactoryRegistry.d.ts +84 -0
- package/dist/scene/shared/components/GroupedFactoryRegistry.d.ts +153 -0
- package/dist/scene/shared/components/basic/BatteryVisualFactory.d.ts +13 -0
- package/dist/scene/shared/components/basic/ClockVisualFactory.d.ts +79 -0
- package/dist/scene/shared/components/basic/DoubleThrowSwitchVisualFactory.d.ts +87 -0
- package/dist/scene/shared/components/basic/LabelVisualFactory.d.ts +148 -0
- package/dist/scene/shared/components/basic/LightbulbVisualFactory.d.ts +72 -0
- package/dist/scene/shared/components/basic/RectangleLEDVisualFactory.d.ts +86 -0
- package/dist/scene/shared/components/basic/RelayVisualFactory.d.ts +92 -0
- package/dist/scene/shared/components/basic/SmallLEDVisualFactory.d.ts +86 -0
- package/dist/scene/shared/components/basic/SwitchVisualFactory.d.ts +85 -0
- package/dist/scene/shared/components/gates/InverterVisualFactory.d.ts +104 -0
- package/dist/scene/shared/components/gates/Nand4GateVisualFactory.d.ts +27 -0
- package/dist/scene/shared/components/gates/Nand8GateVisualFactory.d.ts +27 -0
- package/dist/scene/shared/components/gates/NandGateVisualFactory.d.ts +101 -0
- package/dist/scene/shared/components/gates/Nor4GateVisualFactory.d.ts +27 -0
- package/dist/scene/shared/components/gates/Nor8GateVisualFactory.d.ts +27 -0
- package/dist/scene/shared/components/gates/NorGateVisualFactory.d.ts +101 -0
- package/dist/scene/shared/components/gates/Xor4GateVisualFactory.d.ts +29 -0
- package/dist/scene/shared/components/gates/Xor8GateVisualFactory.d.ts +29 -0
- package/dist/scene/shared/components/gates/XorGateVisualFactory.d.ts +103 -0
- package/dist/scene/shared/components/index.d.ts +29 -0
- package/dist/scene/shared/components/types.d.ts +43 -0
- package/dist/scene/shared/types.d.ts +476 -0
- package/dist/scene/shared/utils/CameraUtils.d.ts +23 -0
- package/dist/scene/shared/utils/ColorUtils.d.ts +26 -0
- package/dist/scene/shared/utils/ControlsUtils.d.ts +8 -0
- package/dist/scene/shared/utils/GeometryUtils.d.ts +261 -0
- package/dist/scene/shared/utils/LayerConstants.d.ts +40 -0
- package/dist/scene/shared/utils/LightingUtils.d.ts +31 -0
- package/dist/scene/shared/utils/MaterialUtils.d.ts +73 -0
- package/dist/scene/shared/utils/Options.d.ts +16 -0
- package/dist/scene/simulation/CircuitRunnerController.d.ts +227 -0
- package/dist/scene/static/CircuitController.d.ts +227 -0
- package/dist/scene/static/CircuitWriter.d.ts +146 -0
- package/dist/scene/static/PinTooltipWidget.d.ts +26 -0
- package/dist/scene/static/tools/BuildTool.d.ts +286 -0
- package/dist/scene/static/tools/ComponentPickerWidget.d.ts +82 -0
- package/dist/scene/static/tools/ConfigPanelWidget.d.ts +93 -0
- package/dist/scene/static/tools/MultiSelectTool.d.ts +265 -0
- package/dist/scene-CVsDdySt.js +7357 -0
- package/dist/scene-CVsDdySt.js.map +1 -0
- package/package.json +24 -25
- package/dist/CircuitRunner-DEb7JdNf.js +0 -1809
- package/dist/CircuitRunner-DEb7JdNf.js.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/scene/index.js.map +0 -1
- package/dist/setup-AB1vFiis.js +0 -9918
- package/dist/setup-AB1vFiis.js.map +0 -1
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Position Type for 2D Discrete Grid
|
|
3
|
+
*
|
|
4
|
+
* Represents a position on a 2D discrete (integer) grid. Used for:
|
|
5
|
+
* - Component placement
|
|
6
|
+
* - Branching point ENode positions
|
|
7
|
+
* - Wire intermediate waypoints
|
|
8
|
+
*
|
|
9
|
+
* @module core/utils
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Position on a 2D discrete grid with integer coordinates.
|
|
13
|
+
*
|
|
14
|
+
* Enforces integer constraint at construction time to ensure all positions
|
|
15
|
+
* align with the discrete grid model. Positions are immutable once created.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const pos = new Position(10, 20);
|
|
20
|
+
* console.log(pos.x); // 10
|
|
21
|
+
* console.log(pos.y); // 20
|
|
22
|
+
*
|
|
23
|
+
* // Invalid: non-integer coordinates
|
|
24
|
+
* const invalid = new Position(10.5, 20); // TypeError
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class Position {
|
|
28
|
+
readonly x: number;
|
|
29
|
+
readonly y: number;
|
|
30
|
+
/**
|
|
31
|
+
* Create a new position on the discrete grid.
|
|
32
|
+
*
|
|
33
|
+
* @param x - X coordinate (must be integer)
|
|
34
|
+
* @param y - Y coordinate (must be integer)
|
|
35
|
+
* @throws {TypeError} If x or y are not integers
|
|
36
|
+
*/
|
|
37
|
+
constructor(x: number, y: number);
|
|
38
|
+
/**
|
|
39
|
+
* Check if this position equals another position.
|
|
40
|
+
*
|
|
41
|
+
* @param other - Position to compare with
|
|
42
|
+
* @returns true if both x and y coordinates are equal
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const p1 = new Position(10, 20);
|
|
47
|
+
* const p2 = new Position(10, 20);
|
|
48
|
+
* const p3 = new Position(15, 20);
|
|
49
|
+
*
|
|
50
|
+
* console.log(p1.equals(p2)); // true
|
|
51
|
+
* console.log(p1.equals(p3)); // false
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
equals(other: Position): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Serialize position to JSON.
|
|
57
|
+
*
|
|
58
|
+
* @returns Plain object with x and y properties
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const pos = new Position(10, 20);
|
|
63
|
+
* const json = pos.toJSON();
|
|
64
|
+
* console.log(json); // { x: 10, y: 20 }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
toJSON(): {
|
|
68
|
+
x: number;
|
|
69
|
+
y: number;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Deserialize position from JSON.
|
|
73
|
+
*
|
|
74
|
+
* @param json - Plain object with x and y properties
|
|
75
|
+
* @returns Position instance
|
|
76
|
+
* @throws {TypeError} If coordinates are not integers
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const json = { x: 10, y: 20 };
|
|
81
|
+
* const pos = Position.fromJSON(json);
|
|
82
|
+
* console.log(pos.x); // 10
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
static fromJSON(json: {
|
|
86
|
+
x: number;
|
|
87
|
+
y: number;
|
|
88
|
+
}): Position;
|
|
89
|
+
/**
|
|
90
|
+
* String representation for debugging.
|
|
91
|
+
*
|
|
92
|
+
* @returns String in format "Position(x, y)"
|
|
93
|
+
*/
|
|
94
|
+
toString(): string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Given a path defined by an array of 2D positions, find the best index to insert
|
|
98
|
+
* a target position so that the path shape is preserved as much as possible.
|
|
99
|
+
*
|
|
100
|
+
* This is used when splitting a wire at a position: we need to determine which
|
|
101
|
+
* segment of the path the target falls on, and return the insertion index.
|
|
102
|
+
*
|
|
103
|
+
* Algorithm:
|
|
104
|
+
* 1. For each consecutive pair of positions (segment), calculate the perpendicular
|
|
105
|
+
* distance from target to that segment
|
|
106
|
+
* 2. Return the index after the start of the closest segment
|
|
107
|
+
*
|
|
108
|
+
* @param positions - Array of positions defining the path (typically includes
|
|
109
|
+
* start endpoint, intermediate positions, and end endpoint)
|
|
110
|
+
* @param target - Position to insert
|
|
111
|
+
* @param minDistance - Optional maximum distance to consider (default: Infinity)
|
|
112
|
+
* @returns Index where target should be inserted (0 to positions.length)
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* // Path: (0,0) -> (10,0) -> (10,10) -> (20,10)
|
|
117
|
+
* const path = [
|
|
118
|
+
* new Position(0, 0),
|
|
119
|
+
* new Position(10, 0),
|
|
120
|
+
* new Position(10, 10),
|
|
121
|
+
* new Position(20, 10)
|
|
122
|
+
* ];
|
|
123
|
+
* // Target at (5, 0) - on first segment
|
|
124
|
+
* findPositionBestIndex(path, new Position(5, 0)); // Returns 1
|
|
125
|
+
* // Target at (10, 5) - on second segment
|
|
126
|
+
* findPositionBestIndex(path, new Position(10, 5)); // Returns 2
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare function findPositionBestIndex(positions: Position[], target: Position, minDistance?: number): number;
|
|
130
|
+
/**
|
|
131
|
+
* Simplify a path by removing collinear intermediate positions.
|
|
132
|
+
*
|
|
133
|
+
* Given an ordered array of positions representing a line path, this function
|
|
134
|
+
* removes positions that lie on the same line as their neighbors (collinear points).
|
|
135
|
+
* The resulting path is visually identical but with fewer redundant points.
|
|
136
|
+
*
|
|
137
|
+
* Three points A, B, C are collinear if B lies on the line from A to C.
|
|
138
|
+
* When collinear, B is redundant and can be removed without changing the path shape.
|
|
139
|
+
*
|
|
140
|
+
* @param positions - Ordered array of positions representing the path
|
|
141
|
+
* @param tolerance - Optional tolerance for collinearity check (default: 5)
|
|
142
|
+
* @returns Simplified array with collinear intermediate points removed
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* // Horizontal line with redundant middle points
|
|
147
|
+
* const path = [
|
|
148
|
+
* new Position(0, 0),
|
|
149
|
+
* new Position(5, 0), // collinear - will be removed
|
|
150
|
+
* new Position(10, 0), // collinear - will be removed
|
|
151
|
+
* new Position(15, 0)
|
|
152
|
+
* ];
|
|
153
|
+
* simplifyPositions(path);
|
|
154
|
+
* // Returns: [Position(0, 0), Position(15, 0)]
|
|
155
|
+
*
|
|
156
|
+
* // L-shaped path - corner point is NOT collinear
|
|
157
|
+
* const lPath = [
|
|
158
|
+
* new Position(0, 0),
|
|
159
|
+
* new Position(10, 0), // corner - kept
|
|
160
|
+
* new Position(10, 10)
|
|
161
|
+
* ];
|
|
162
|
+
* simplifyPositions(lPath);
|
|
163
|
+
* // Returns: [Position(0, 0), Position(10, 0), Position(10, 10)]
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export declare function simplifyPositions(positions: Position[], tolerance?: number): Position[];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { IPosition3D } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 3D position.
|
|
4
|
+
* Positions are immutable once created.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const pos3 = new Position3D(10, 20, 40);
|
|
9
|
+
* console.log(pos.x); // 10
|
|
10
|
+
* console.log(pos.y); // 20
|
|
11
|
+
* console.log(pos.y); // 40
|
|
12
|
+
*
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare class Position3D {
|
|
16
|
+
readonly x: number;
|
|
17
|
+
readonly y: number;
|
|
18
|
+
readonly z: number;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new 3D position.
|
|
21
|
+
*
|
|
22
|
+
* @param x - X coordinate
|
|
23
|
+
* @param y - Y coordinate
|
|
24
|
+
* @param z - Z coordinate
|
|
25
|
+
*/
|
|
26
|
+
constructor(x: number, y: number, z: number);
|
|
27
|
+
/**
|
|
28
|
+
* Check if this position equals another position.
|
|
29
|
+
*
|
|
30
|
+
* @param other - Position to compare with
|
|
31
|
+
* @returns true if x,y and z coordinates are equal
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const p1 = new Position(10, 20, 40);
|
|
36
|
+
* const p2 = new Position(10, 20, 40);
|
|
37
|
+
* const p3 = new Position(15, 20, 40);
|
|
38
|
+
*
|
|
39
|
+
* console.log(p1.equals(p2)); // true
|
|
40
|
+
* console.log(p1.equals(p3)); // false
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
equals(other: Position3D): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Serialize position to JSON.
|
|
46
|
+
*
|
|
47
|
+
* @returns Plain object with x, y and z properties
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const pos = new Position(10, 20, 40);
|
|
52
|
+
* const json = pos.toJSON();
|
|
53
|
+
* console.log(json); // { x: 10, y: 20, z: 40 }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
toJSON(): IPosition3D;
|
|
57
|
+
/**
|
|
58
|
+
* Deserialize position from JSON.
|
|
59
|
+
*
|
|
60
|
+
* @param json - Plain object with x, y and z properties
|
|
61
|
+
* @returns Position instance
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const json = { x: 10, y: 20, z: 40 };
|
|
66
|
+
* const pos = Position.fromJSON(json);
|
|
67
|
+
* console.log(pos.x); // 10
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
static fromJSON(json: IPosition3D): Position3D;
|
|
71
|
+
/**
|
|
72
|
+
* String representation for debugging.
|
|
73
|
+
*
|
|
74
|
+
* @returns String in format "Position(x, y, z)"
|
|
75
|
+
*/
|
|
76
|
+
toString(): string;
|
|
77
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rotation Type for Component Orientation
|
|
3
|
+
* Represents orientation angle for components on the 2D grid.
|
|
4
|
+
* Uses integer degrees for discrete rotation values.
|
|
5
|
+
* @module core/utils
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Rotation angle for component orientation.
|
|
9
|
+
*
|
|
10
|
+
* Enforces integer constraint at construction time. Typically used with
|
|
11
|
+
* values like 0, 90, 180, 270 degrees, but any integer is valid.
|
|
12
|
+
* Rotations are immutable once created.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const rotation = new Rotation(90);
|
|
17
|
+
* console.log(rotation.angle); // 90
|
|
18
|
+
*
|
|
19
|
+
* // Invalid: non-integer angle
|
|
20
|
+
* const invalid = new Rotation(45.5); // TypeError
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class Rotation {
|
|
24
|
+
readonly angle: number;
|
|
25
|
+
/**
|
|
26
|
+
* Create a new rotation with the specified angle.
|
|
27
|
+
*
|
|
28
|
+
* @param angle - Rotation angle in degrees (must be integer)
|
|
29
|
+
* @throws {TypeError} If angle is not an integer
|
|
30
|
+
*/
|
|
31
|
+
constructor(angle: number);
|
|
32
|
+
/**
|
|
33
|
+
* Serialize rotation to JSON.
|
|
34
|
+
*
|
|
35
|
+
* @returns The angle value as a number
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const rotation = new Rotation(90);
|
|
40
|
+
* const json = rotation.toJSON();
|
|
41
|
+
* console.log(json); // 90
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
toJSON(): number;
|
|
45
|
+
/**
|
|
46
|
+
* Deserialize rotation from JSON.
|
|
47
|
+
*
|
|
48
|
+
* @param angle - Angle value
|
|
49
|
+
* @returns Rotation instance
|
|
50
|
+
* @throws {TypeError} If angle is not an integer
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const rotation = Rotation.fromJSON(90);
|
|
55
|
+
* console.log(rotation.angle); // 90
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
static fromJSON(angle: number): Rotation;
|
|
59
|
+
/**
|
|
60
|
+
* Check if this rotation equals another rotation.
|
|
61
|
+
*
|
|
62
|
+
* @param other - Rotation to compare with
|
|
63
|
+
* @returns true if angles are equal
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const r1 = new Rotation(90);
|
|
68
|
+
* const r2 = new Rotation(90);
|
|
69
|
+
* const r3 = new Rotation(180);
|
|
70
|
+
*
|
|
71
|
+
* console.log(r1.equals(r2)); // true
|
|
72
|
+
* console.log(r1.equals(r3)); // false
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
equals(other: Rotation): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* String representation for debugging.
|
|
78
|
+
*
|
|
79
|
+
* @returns String in format "Rotation(angle°)"
|
|
80
|
+
*/
|
|
81
|
+
toString(): string;
|
|
82
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { UUID } from './types';
|
|
2
|
+
export type { UUID, IPosition, IPosition3D, ICameraOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Generate a new RFC 4122 UUID v4 identifier.
|
|
5
|
+
*
|
|
6
|
+
* Uses the native `crypto.randomUUID()` API when available (ES2022+ browsers,
|
|
7
|
+
* Node 19+). For older Node.js environments in testing, falls back to a
|
|
8
|
+
* polyfill implementation.
|
|
9
|
+
*
|
|
10
|
+
* @returns A newly generated UUID string
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const componentId = generateUUID();
|
|
15
|
+
* const wireId = generateUUID();
|
|
16
|
+
* console.log(componentId !== wireId); // true (collision probability: ~10^-36)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function generateUUID(): UUID;
|
|
20
|
+
export { Memoize, MemoizeExpiring } from './MemoizeDecorator.js';
|
|
21
|
+
export { CameraOptions } from './CameraOptions';
|
|
22
|
+
export { Position, simplifyPositions, findPositionBestIndex } from './Position';
|
|
23
|
+
export { Position3D } from './Position3D';
|
|
24
|
+
export { Rotation } from './Rotation';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* core utilities types definitions
|
|
3
|
+
* @module core/utils
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Universally Unique Identifier (RFC 4122 UUID v4).
|
|
7
|
+
*/
|
|
8
|
+
export type UUID = string;
|
|
9
|
+
/**
|
|
10
|
+
* 2D Position Type
|
|
11
|
+
* Represents a 2D position on the circuit grid
|
|
12
|
+
*/
|
|
13
|
+
export type IPosition = {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 3D Position Type
|
|
19
|
+
* Represents a 3D position. Used for Camera placement
|
|
20
|
+
*/
|
|
21
|
+
export type IPosition3D = {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
z: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Circuit camera options (used to position camera at startup)
|
|
28
|
+
*/
|
|
29
|
+
export type ICameraOptions = {
|
|
30
|
+
position: IPosition3D;
|
|
31
|
+
lookAtPosition: IPosition3D;
|
|
32
|
+
fov: number;
|
|
33
|
+
near: number;
|
|
34
|
+
far: number;
|
|
35
|
+
};
|