Skip to content

Commit 5ea51d4

Browse files
(feat) PDF and Projection POC (#5)
1 parent 225cb22 commit 5ea51d4

38 files changed

Lines changed: 4692 additions & 1940 deletions

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ dist
2929
settings.json
3030

3131
# Copilot
32-
.github/*.md
32+
.github/*.md
33+
34+
# CAD export artifacts
35+
*.pdf
36+
*.dxf

AGENTS.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# AGENTS.md
2+
3+
Repository-level standards for Codex, Copilot, and other AI coding agents.
4+
5+
This file defines how agents must operate to produce production-ready code.
6+
If a subdirectory has stricter instructions, follow both; if they conflict, use the more restrictive rule.
7+
8+
## Core Outcome
9+
10+
All agent work must be:
11+
12+
- Correct and behaviorally safe
13+
- Testable and reproducible
14+
- Secure by default
15+
- Backward-compatible unless explicitly approved
16+
- Reviewable through small, clear diffs
17+
18+
## Documentation Location Policy (Mandatory)
19+
20+
- All AI-generated docs must be placed under `AI-DOCs/`.
21+
- Do not add AI-generated docs under app/code directories such as `main/`, `src/`, `test/`, or package folders.
22+
- If a task needs documentation, create or update files in `AI-DOCs/` unless the user explicitly asks otherwise.
23+
24+
## Documentation Naming Rules
25+
26+
- Use `kebab-case` file names.
27+
- Prefix date when useful: `YYYY-MM-DD-topic.md`.
28+
- Keep one concern per file (design note, runbook, handoff, postmortem, etc.).
29+
30+
## Engineering Standards
31+
32+
### 1) Scope Discipline
33+
34+
- Only change what is necessary for the request.
35+
- Do not refactor unrelated modules unless explicitly requested.
36+
- Keep each change atomic and explainable.
37+
38+
### 2) API and Compatibility
39+
40+
- Preserve public API behavior by default.
41+
- If a breaking change is required, document it clearly and provide migration guidance.
42+
- Avoid hidden behavioral changes in existing call paths.
43+
44+
### 3) Security and Safety
45+
46+
- Never hardcode secrets, keys, tokens, or credentials.
47+
- Validate and sanitize all external/user-controlled inputs.
48+
- Prefer fail-safe behavior on invalid state or malformed input.
49+
- Minimize attack surface: least privilege, least data exposure, least capability.
50+
51+
### 4) Reliability and Error Handling
52+
53+
- Avoid panics for recoverable runtime conditions.
54+
- Return structured errors with actionable context.
55+
- Do not silently swallow failures.
56+
- Keep retries bounded and deterministic.
57+
58+
### 5) Performance and Scalability
59+
60+
- Avoid obviously unbounded algorithms in hot paths.
61+
- Reuse existing components and avoid duplicate data transformations.
62+
- Consider memory overhead and serialization costs for large scenes/data.
63+
64+
### 6) Readability and Maintainability
65+
66+
- Prefer simple, explicit code over clever shortcuts.
67+
- Keep functions focused and names descriptive.
68+
- Add concise comments only where intent is not obvious from code.
69+
70+
## Testing and Validation Standards (Mandatory)
71+
72+
Before finalizing a change, run relevant checks for touched areas:
73+
74+
- Formatting
75+
- Static/build checks
76+
- Tests
77+
- Example/integration command for user-facing features
78+
79+
Minimum expectations:
80+
81+
- Run project-standard commands where available (for example `cargo fmt`, `cargo check`, `cargo test`).
82+
- If full validation cannot run, report exactly:
83+
- which command failed or was skipped
84+
- why
85+
- residual risk
86+
87+
## Change Management
88+
89+
- Prefer incremental commits with focused intent.
90+
- Do not commit generated binaries or transient artifacts.
91+
- Keep diffs review-friendly and avoid noisy unrelated formatting churn.
92+
93+
## Pull Request / Handoff Standard
94+
95+
For significant changes, add/update a short handoff note in `AI-DOCs/` including:
96+
97+
- What changed
98+
- Why it changed
99+
- How to test locally
100+
- Backward-compatibility notes
101+
- Known caveats and follow-ups
102+
103+
## Definition of Done
104+
105+
A task is done only when all are true:
106+
107+
- Requested functionality is implemented end-to-end.
108+
- Quality gates have been run or limitations are explicitly documented.
109+
- Documentation and examples are updated when behavior/API changed.
110+
- No unintended artifacts are introduced into version control.
111+
- Result is ready for production review without hidden assumptions.

AI-DOCs/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# AI-DOCs
2+
3+
Central location for documentation generated by AI agents (Codex, Copilot, etc.).
4+
5+
## What goes here
6+
7+
- design notes
8+
- implementation logs
9+
- testing/runbooks
10+
- migration notes
11+
- handoff summaries
12+
13+
## What does not go here
14+
15+
- source code
16+
- compiled output/binaries
17+
- user-facing product docs that belong elsewhere by explicit request
18+
19+
## Conventions
20+
21+
- Use `kebab-case` file names.
22+
- Prefer focused docs over one large catch-all file.
23+
- Include runnable commands and expected outputs when relevant.
24+
25+
## Recommended starter files
26+
27+
- `codex-repo-playbook.md`
28+
- `local-testing-checklist.md`
29+
- date-stamped implementation notes as needed
30+

AI-DOCs/codex-repo-playbook.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Codex Repo Playbook
2+
3+
This playbook defines practical defaults for Codex work in this repository.
4+
5+
## 1) Before changing code
6+
7+
- Read relevant files first.
8+
- Confirm scope and avoid unrelated edits.
9+
- Prefer deterministic commands and explicit outputs.
10+
11+
## 2) During implementation
12+
13+
- Keep patches small and understandable.
14+
- Reuse existing modules/functions before adding new abstractions.
15+
- Add examples for new user-facing capabilities.
16+
17+
## 3) Validation
18+
19+
Run, at minimum, relevant checks for touched areas:
20+
21+
```bash
22+
# example baseline commands
23+
cargo fmt --check
24+
cargo check
25+
cargo test
26+
```
27+
28+
If full validation cannot run, document exactly why and what was run instead.
29+
30+
## 4) Commit hygiene
31+
32+
- Keep commit messages clear and specific.
33+
- Do not include generated binaries.
34+
- Include doc updates in `AI-DOCs/` for significant work.
35+
36+
## 5) Handoff checklist
37+
38+
- Summary of changes
39+
- Local verification commands
40+
- Expected artifacts/outputs
41+
- Known caveats
42+

AI-DOCs/local-testing-checklist.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Local Testing Checklist
2+
3+
Use this checklist before finalizing AI-generated changes.
4+
5+
## Quick checklist
6+
7+
- [ ] Formatting passed
8+
- [ ] Build/check passed
9+
- [ ] Tests passed (or limitation documented)
10+
- [ ] Example commands run for new features
11+
- [ ] No binary artifacts staged
12+
- [ ] Notes updated in `AI-DOCs/` if needed
13+
14+
## Output checks
15+
16+
- Verify expected files are generated in intended output directories.
17+
- Confirm no generated files are accidentally tracked in git.
18+
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# OpenGeometry Local Testing Guide
2+
3+
This file documents how to locally validate the camera projection + scenegraph pipeline implemented in this branch.
4+
5+
## 1) Run from the Rust crate root
6+
7+
```bash
8+
cd main/opengeometry
9+
```
10+
11+
## 2) Build and test
12+
13+
```bash
14+
cargo fmt --check
15+
cargo check --examples
16+
cargo test -q
17+
```
18+
19+
Expected: build succeeds and unit tests pass.
20+
21+
## 3) Generate projection PDFs
22+
23+
Create an output folder:
24+
25+
```bash
26+
mkdir -p ./out
27+
```
28+
29+
### Perspective camera projection
30+
31+
```bash
32+
cargo run --example pdf_camera_projection -- ./out/pdf_camera_projection.pdf
33+
```
34+
35+
### Orthographic HLR on/off comparison
36+
37+
```bash
38+
cargo run --example pdf_camera_projection_views -- ./out/pdf_camera_projection_views
39+
```
40+
41+
Expected output files:
42+
- `./out/pdf_camera_projection_views_hlr_on.pdf`
43+
- `./out/pdf_camera_projection_views_hlr_off.pdf`
44+
45+
### All supported primitives
46+
47+
```bash
48+
cargo run --example pdf_primitives_all -- ./out/pdf_primitives
49+
```
50+
51+
Expected output files:
52+
- `./out/pdf_primitives_line.pdf`
53+
- `./out/pdf_primitives_polyline.pdf`
54+
- `./out/pdf_primitives_arc.pdf`
55+
- `./out/pdf_primitives_rectangle.pdf`
56+
- `./out/pdf_primitives_polygon.pdf`
57+
- `./out/pdf_primitives_cuboid.pdf`
58+
- `./out/pdf_primitives_cylinder.pdf`
59+
60+
### Scenegraph projection (shared projectTo2DCamera + PDF path)
61+
62+
```bash
63+
cargo run --example scenegraph_projection -- ./out/scenegraph_projection.pdf
64+
```
65+
66+
Expected output file:
67+
- `./out/scenegraph_projection.pdf`
68+
69+
### Inspect projectTo2DCamera JSON payloads
70+
71+
```bash
72+
cargo run --example scenegraph_projection_dump_json -- ./out/projection_dump
73+
```
74+
75+
Expected output files:
76+
- `./out/projection_dump_scene2d.json` (raw `Scene2D` shape from `projectTo2DCamera`)
77+
- `./out/projection_dump_lines2d.json` (normalized `Scene2DLines` payload from `projectTo2DLines`)
78+
79+
Optional pretty inspection with `jq`:
80+
81+
```bash
82+
jq . ./out/projection_dump_scene2d.json
83+
jq . ./out/projection_dump_lines2d.json
84+
```
85+
86+
## 4) Verify files were created
87+
88+
```bash
89+
ls -1 ./out/*.pdf
90+
```
91+
92+
## 5) Frontend / WASM note
93+
94+
- `projectTo2DCamera` is designed for frontend usage (returns serialized 2D scene data).
95+
- `projectToPDF` is native-only in this crate build (`not(target_arch = "wasm32")`).
96+
- In browser builds, use `projectTo2DCamera` and render lines in Three.js.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# projectTo2D Data Format
2+
3+
This document describes how to inspect and consume scene projection data from `OGSceneManager`.
4+
5+
## API methods
6+
7+
- `projectTo2DCamera(sceneId, cameraJson, hlrJson?)` -> `Scene2D` JSON string
8+
- `projectTo2DCameraPretty(sceneId, cameraJson, hlrJson?)` -> pretty `Scene2D` JSON string
9+
- `projectTo2DLines(sceneId, cameraJson, hlrJson?)` -> normalized `Scene2DLines` JSON string
10+
- `projectTo2DLinesPretty(sceneId, cameraJson, hlrJson?)` -> pretty normalized JSON string
11+
- `projectCurrentTo2DCamera(...)` / `projectCurrentTo2DLines(...)` use current scene
12+
13+
## `Scene2D` shape
14+
15+
```json
16+
{
17+
"name": "Main Scene",
18+
"paths": [
19+
{
20+
"segments": [
21+
{
22+
"Line": {
23+
"start": { "x": -0.2, "y": 0.1 },
24+
"end": { "x": 0.3, "y": 0.4 }
25+
}
26+
}
27+
],
28+
"stroke_width": null,
29+
"stroke_color": null
30+
}
31+
]
32+
}
33+
```
34+
35+
## `Scene2DLines` normalized shape (recommended for frontend rendering)
36+
37+
```json
38+
{
39+
"name": "Main Scene",
40+
"lines": [
41+
{
42+
"start": { "x": -0.2, "y": 0.1 },
43+
"end": { "x": 0.3, "y": 0.4 },
44+
"stroke_width": null,
45+
"stroke_color": null
46+
}
47+
]
48+
}
49+
```
50+
51+
## Frontend usage (Three.js lines)
52+
53+
```ts
54+
const scene2dLinesJson = manager.projectTo2DLines(
55+
sceneId,
56+
JSON.stringify(camera),
57+
JSON.stringify({ hide_hidden_edges: true })
58+
);
59+
const scene2dLines = JSON.parse(scene2dLinesJson);
60+
61+
for (const line of scene2dLines.lines) {
62+
// line.start.x, line.start.y, line.end.x, line.end.y
63+
// map to your viewport scale and build Three.js LineSegments geometry
64+
}
65+
```
66+
67+
## Local inspection
68+
69+
```bash
70+
cd main/opengeometry
71+
cargo run --example scenegraph_projection_dump_json -- ./out/projection_dump
72+
jq . ./out/projection_dump_scene2d.json
73+
jq . ./out/projection_dump_lines2d.json
74+
```

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ Documentation is available at [OpenGeometry Documentation](https://docs.opengeom
2323
- Extrusion
2424
- Offset
2525
- Boolean Operations (In Progress)
26+
27+
## AI Agent Docs Policy
28+
29+
- Repository-level AI agent instructions are in [AGENTS.md](./AGENTS.md).
30+
- All AI-generated documentation must live under [`AI-DOCs/`](./AI-DOCs/).
31+
- AI-generated docs should not be added under app/code folders unless explicitly requested.

0 commit comments

Comments
 (0)