You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 87a1aa9
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: .github/copilot-instructions.md
+36Lines changed: 36 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,6 +73,42 @@ When implementing or modifying algorithms:
73
73
- Document numerical properties and limitations
74
74
- Keep documentation in sync with code changes
75
75
76
+
## Design Principles
77
+
78
+
These are the most important architectural directives in this codebase. Every new class, function, and CMake target must follow them.
79
+
80
+
### SOLID Principles
81
+
82
+
-**Single Responsibility (SRP)**: Each class and struct owns exactly one concern. Separate configuration into sub-structs by concern (e.g., `WeightsConfig`, `SimulationConfig`, `PlantParameters`) rather than flat mega-structs. Each source file should address a single topic.
83
+
-**Open/Closed (OCP)**: Prefer templates and compile-time polymorphism for extending algorithms to new numeric types (`float`, `Q15`, `Q31`) without modifying existing code.
84
+
-**Liskov Substitution (LSP)**: When using abstract base classes (e.g., `Plant`), all derived classes must be fully substitutable. Override every pure virtual method; do not weaken preconditions or strengthen postconditions.
85
+
-**Interface Segregation (ISP)**: Keep interfaces small and focused. Do not force implementers to depend on methods they do not use.
86
+
-**Dependency Inversion (DIP)**: High-level modules (simulators, controllers) depend on abstractions, not concrete implementations. Use constructor injection for dependencies. Pass interfaces, not concrete types, when multiple implementations exist.
87
+
88
+
### DRY (Don't Repeat Yourself)
89
+
90
+
-**NEVER duplicate logic**. If two functions share more than a few lines of identical code, extract a common helper, template, or base class.
91
+
- Use templates to eliminate per-type or per-size code duplication (e.g., DOF-parameterized dynamics instead of copy-pasted `StepDof2()` / `StepDof3()`).
92
+
- Use `std::numbers::pi_v<float>` consistently — never hardcode `3.14159265f` or similar constants.
93
+
- Share configuration structs across layers instead of re-declaring equivalent types.
94
+
- Reuse existing utility components (e.g., `TimeSeriesChartWidget`, `SignalGenerator`) rather than reimplementing equivalent widgets.
95
+
96
+
### Small Functions
97
+
98
+
-**Every function should do one thing and fit on one screen** (~30 lines max, hard limit ~50 lines).
99
+
- Extract named helpers from long methods — the name acts as self-documentation.
100
+
- Rendering code should delegate to focused `Draw*()` helpers (e.g., `DrawTrack()`, `DrawCart()`, `DrawPole()`).
101
+
- Prefer returning values over mutating shared state — this makes functions easier to test and reason about.
102
+
103
+
### CMake Reuse
104
+
105
+
-**Simulator structure**: Every simulator follows the three-layer pattern: `application/` (logic) → `view/` (Qt GUI) → `Main.cpp` (entry point), each with its own `CMakeLists.txt` and library target.
106
+
-**Shared utilities**: Link against `numerical.simulator.utils` for common widgets (`TimeSeriesChartWidget`, `SignalGenerator`) — do not duplicate them.
107
+
-**Shared abstractions**: Link against `numerical.simulator.controllers.common` for shared controller interfaces (e.g., `Plant`).
-**Library code reuse**: Use `numerical_add_header_library()` and `numerical_add_coverage_sources()` from `cmake/NumericalHeaderLibrary.cmake` for all `numerical/` targets.
110
+
-**Compiler options blocks**: Every simulator target repeats the same MSVC/GCC warning suppression — keep this consistent across all targets.
0 commit comments