# ktitaro/pico-physics architecture

> Architecture diagram of the GitHub repository ktitaro/pico-physics, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ktitaro/pico-physics
- Repository: https://github.com/ktitaro/pico-physics

## Overview

##### Main Components
- Library Core (src): This is the heart of the library and can be subdivided further:
- Helpers (src/helpers): Utility modules such as mathematical functions (vec2.lua, math.lua), conversion helpers (conv.lua), and SAT (separating axis theorem) specific methods (sat2.lua). These modules provide the low-level math and conversions needed for physics calculations.
- Physics (src/physics): Contains core physics components including handling of physics "bodies" (body.lua) and possibly the definition of areas or regions affected by physics (area.lua).

- Demo (demo): Provides example code demonstrating how to use the physics library in practice. This includes files for a demo game (demo.p8, game.lua, player.lua, things.lua) that likely instantiate and interact with the physics system.

- Assets (assets): Contains supplementary images (logo.png, demo.gif) that clarify the branding and provide visual confirmation of how the library should look and behave.

##### Relationships and Interactions
- The Toolbox (debug) is used to monitor or update the physics simulation during runtime, perhaps even within the demo environment.
- The Assets give visual cues and identity to the library, reinforcing the branding (e.g., logo and demo animation).

##### Highlighting Architectural Patterns and Design Principles
- Separation of Concerns: The demo code is kept separate from the library code ensuring clarity between using and implementing the physics simulation.
- Reusability: The helpers and toolbox providing cross-cutting functionality suggest utility functions are designed to be reused across various parts of the system.

## Diagram (Mermaid)

```mermaid
graph TD
    D["Demo (Physics simulation examples)"]:::demo
    LC["Library Core"]:::core
    A["Assets (Branding and visuals)"]:::assets

    D -->|"invokes"| LC
    D -->|"displays"| A

    subgraph "Library Core Modules"
        H["Helpers (Math, Vector, Conversion, SAT)"]:::helper
        P["Physics (Body, Area)"]:::physics
        S["Shapes (Base, Oval, Polygon, Rect)"]:::shapes
        T["Toolbox (Debug)"]:::toolbox
    end

    LC -->|"contains"| H
    LC -->|"contains"| P
    LC -->|"contains"| S
    LC -->|"contains"| T

    P -->|"utilizes"| H
    P -->|"defines"| S
    T -->|"debugs"| P

    click LC "https://github.com/ktitaro/pico-physics/tree/master/src"
    click H "https://github.com/ktitaro/pico-physics/tree/master/src/helpers"
    click P "https://github.com/ktitaro/pico-physics/tree/master/src/physics"
    click S "https://github.com/ktitaro/pico-physics/tree/master/src/shapes"
    click T "https://github.com/ktitaro/pico-physics/blob/master/src/toolbox/debug.lua"
    click D "https://github.com/ktitaro/pico-physics/tree/master/demo"
    click A "https://github.com/ktitaro/pico-physics/tree/master/assets"

    classDef core fill:#E8F8F5,stroke:#1ABC9C,stroke-width:2px,color:#000;
    classDef helper fill:#FDF2E9,stroke:#F39C12,stroke-width:2px,color:#000;
    classDef physics fill:#EBF5FB,stroke:#3498DB,stroke-width:2px,color:#000;
    classDef shapes fill:#F9EBEA,stroke:#E74C3C,stroke-width:2px,color:#000;
    classDef toolbox fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px,color:#000;
    classDef demo fill:#FDEDEC,stroke:#C0392B,stroke-width:2px,color:#000;
    classDef assets fill:#ECF0F1,stroke:#95A5A6,stroke-width:2px,color:#000;
```
