Summary
The current Vectors, Matrix, and MatrixDict data structures are clunky to use, difficult to attach metadata to, and don't support OOP paradigms very well. This limits scalability, especially when more matrix transformations options exist in the future.
The Number type (float | int) is also unnecessary and will be replaced with a simple float.
Context
This structure was set up a long time ago and wasn't designed with future features (like projections, eigenvectors, or serialization) in mind. As a result:
- The animation logic is messier than it should be.
- Repeated code for unpacking coordinates and colors is fragile.
- It will be difficult to scale or maintain as features expand.
Also, not having a clear structure makes it harder to debug or extend, especially as the UI and animation logic grow more complex.
Implementation Plan
Refactor the existing Vectors, Matrix, and MatrixDict types into proper @dataclasses or similar objects with clearly named fields.
The new structure should be easier to work with and help clean up the logic for creating figures, applying matrices, and possibly future use-cases such as showcasing eigenvectors and projections.
Steps:
- Create a new
Vector class or dataclass that holds .coords and .color, same with Matrix and MatrixDict. Matrix and MatrixDict in particular should have methods that clean up code. For example, it's currently common to do np.array(list(stored_matrices.values())[-1]), which could be abstracted to stored_matrices.get_np_matrix(index=-1).
- Update all functions that use the old structure to use the new class (e.g., in
create_figure, apply_matrix_to_vectors, add_matrix, etc).
- Verify everything still runs; calculations and logic, animations, etc. No unit tests currently exist, so rely on manual testing.
- Make sure future use-cases like projections, labels, or animation states are actually easier to support with this structure.
Impact
Benefits
- Improves readability and developer experience
- Easier to scale with future vector and matrix properties
- Removes confusing and clunky data-access (like
vectors[name][0][1] and list(stored_matrices.keys())), and replaces them with more readable code.
Challenges
- May introduce temporary bugs due to the tight coupling between logic and data format
- All downstream functions must be updated to use the new structure
Mitigation
- Tightly scope changes
- Refactor incrementally
Summary
The current
Vectors,Matrix, andMatrixDictdata structures are clunky to use, difficult to attach metadata to, and don't support OOP paradigms very well. This limits scalability, especially when more matrix transformations options exist in the future.The
Numbertype (float | int) is also unnecessary and will be replaced with a simplefloat.Context
This structure was set up a long time ago and wasn't designed with future features (like projections, eigenvectors, or serialization) in mind. As a result:
Also, not having a clear structure makes it harder to debug or extend, especially as the UI and animation logic grow more complex.
Implementation Plan
Refactor the existing
Vectors,Matrix, andMatrixDicttypes into proper@dataclasses or similar objects with clearly named fields.The new structure should be easier to work with and help clean up the logic for creating figures, applying matrices, and possibly future use-cases such as showcasing eigenvectors and projections.
Steps:
Vectorclass or dataclass that holds.coordsand.color, same withMatrixandMatrixDict.MatrixandMatrixDictin particular should have methods that clean up code. For example, it's currently common to donp.array(list(stored_matrices.values())[-1]), which could be abstracted tostored_matrices.get_np_matrix(index=-1).create_figure,apply_matrix_to_vectors,add_matrix, etc).Impact
Benefits
vectors[name][0][1]andlist(stored_matrices.keys())), and replaces them with more readable code.Challenges
Mitigation