Skip to content

v2: harden interface, add field integral, parallel time-series, tests/CI - #1

Merged
Interfluo merged 4 commits into
mainfrom
claude/projected-area-analysis-v2-34nho5
Jun 27, 2026
Merged

Interfluo merged 4 commits into
mainfrom
claude/projected-area-analysis-v2-34nho5

Conversation

@Interfluo

Copy link
Copy Markdown
Owner

Overview

A v2 pass focused on the three stated goals — reliable, fast, dependency-free analysis — with most attention on the interface and the time-dependent batch workflow. The math core (projected area, edge-function rasterization, Z-buffer) is unchanged in behavior; everything around it is hardened.

Interface & robustness

  • Implement the long-form flags that were documented in --help but silently ignored (--res, --data, --batch, --out, --view, --threads). Previously --res 0.1 ran at the default resolution.
  • Reject unknown options and malformed/zero view vectors instead of swallowing them.
  • Wrap main in try/catch so bad input produces a clean Error: ... and exit 1, rather than an std::terminate/abort crash (was exit 134 on a missing file).
  • Data-file size mismatches now report the actual vs expected vertex/face counts.

Generic analysis

  • Add the area integral of the field, ∫ f dA = Σ(value · pixel_area), alongside average/min/max. Domain-agnostic: a radiance field gives radiant intensity, pressure gives force, etc.
  • JSON output extended with resolution, width/height, min/max, image, and emits null for non-finite numbers so downstream parsers don't break.

Performance / time-series (1000-timestep goal)

  • Separate the scalar field from the read-only mesh; process batch timesteps across a standard-library thread pool (one renderer per worker, output kept in view order).
  • A fixed -d field loads once and is shared; per-timestep field files stream on demand, so peak memory is O(threads), not O(timesteps). Field parsing switched to strtod.
  • ~1000 changing-view / changing-field timesteps on the 70k-triangle Stanford bunny run in ~1.5 s.
  • Relative batch data-file paths resolve against the batch file's directory, so a case folder is portable across working directories.

Build (dependency-free / airgapped)

  • Add a one-line Makefile and document a single-compiler-invocation build (c++ -std=c++17 -O2 -pthread src/main.cpp -o flatland).
  • Link Threads in CMake (now required by std::thread).

Examples, tests, CI

  • Rewrite generate_field.py to be standard-library only (no numpy/pyvista) and emit a portable time-series case; drop the stale cases.txt that referenced missing data.
  • Commit a small ready-to-run examples/with_fields/timeseries_demo/.
  • Add a dependency-free test suite (bash + awk, 14 checks) covering geometry (cube area = 1, sphere = π), the field integral, and every interface-error path.
  • Add a GitHub Actions workflow building with GCC/Clang on Linux+macOS and via CMake, running the suite on every push.

Validation

  • 14/14 tests pass against both the make and CMake binaries.
  • Committed demo verified to run from any working directory; -o PPM output and double precision exercised.

🤖 Generated with Claude Code


Generated by Claude Code

Interface & robustness:
- Implement the long-form flags that were documented but silently ignored
  (--res, --data, --batch, --out, --view, --threads).
- Reject unknown options and malformed/zero view vectors instead of
  swallowing them; wrap main in try/catch so bad input gives a clean
  "Error: ..." and exit 1 rather than an abort/std::terminate crash.
- Report data-file size mismatches with mesh vertex/face counts.

Generic analysis:
- Add the area integral of the field (sum value*pixel_area) alongside
  average/min/max. This is domain-agnostic: a radiance field yields radiant
  intensity, pressure yields force, etc. Exposed in text and JSON output;
  JSON now also carries resolution, width/height, min/max, image, and emits
  null for non-finite numbers so pipelines don't break.

Performance / time-series:
- Separate the scalar field from the read-only mesh and process batch
  timesteps across a standard-library thread pool (one renderer per worker,
  output kept in view order). A fixed -d field loads once and is shared;
  per-timestep field files stream on demand, so peak memory is O(threads)
  not O(timesteps). Field parsing switched to strtod.
- ~1000 changing-view/changing-field timesteps on the 70k-triangle bunny now
  run in ~1.5s.
- Resolve relative batch data-file paths against the batch file's directory
  so a case folder is portable across working directories.

Build (dependency-free / airgapped):
- Add a one-line Makefile and document a single-compiler-invocation build;
  link Threads in CMake (required by std::thread).

Examples, tests, CI:
- Rewrite generate_field.py to be standard-library only (no numpy/pyvista)
  and emit a portable time-series case; drop the stale cases.txt that
  referenced missing data.
- Commit a small ready-to-run timeseries_demo and add a dependency-free
  test suite (bash+awk) covering geometry, the integral, and interface
  errors, plus a GitHub Actions workflow building with GCC/Clang and CMake.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tp1jQ6ZJCz1QXTASbyVhE7

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors FlatLand into a multi-threaded C++17 utility for projected-area and scalar field analysis of 3D meshes, introducing parallel batch processing, area integral calculations, and a dependency-free test suite. Feedback on these changes suggests validating vertex indices in the OBJ loader to prevent potential out-of-bounds memory access, and including to ensure portable floating-point parsing across different system locales.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/main.cpp
Comment on lines +209 to +210
if (mesh.vertices.empty()) throw std::runtime_error("mesh '" + filename + "' contains no vertices");
if (mesh.faces.empty()) throw std::runtime_error("mesh '" + filename + "' contains no faces");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The OBJ loader does not validate that vertex indices in the face definitions are within the bounds of the loaded vertices. If an OBJ file contains invalid or out-of-bounds indices, it will lead to undefined behavior or crashes during rendering. Adding a validation check here prevents out-of-bounds memory access.

    if (mesh.vertices.empty()) throw std::runtime_error("mesh '" + filename + "' contains no vertices");
    if (mesh.faces.empty())    throw std::runtime_error("mesh '" + filename + "' contains no faces");
    for (const auto& f : mesh.faces) {
        if (f.v0_idx < 0 || f.v0_idx >= (int)mesh.vertices.size() ||
            f.v1_idx < 0 || f.v1_idx >= (int)mesh.vertices.size() ||
            f.v2_idx < 0 || f.v2_idx >= (int)mesh.vertices.size()) {
            throw std::runtime_error("mesh '" + filename + "' contains out-of-bounds vertex index");
        }
    }

Comment thread src/main.cpp
Comment on lines +35 to +36
#include <cstdlib>
#include <stdexcept>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Include <clocale> to support setting the locale, which is necessary to ensure portable floating-point parsing across different system locales.

#include <cstdlib>
#include <stdexcept>
#include <clocale>

claude added 3 commits June 27, 2026 14:57
Address review feedback on PR #1:
- Validate that every face references an in-range vertex index when loading an
  OBJ, throwing a clear error instead of letting process_view read out of
  bounds on a malformed file.
- Call setlocale(LC_ALL, "C") at startup so strtod/sscanf always treat '.' as
  the decimal separator regardless of the environment locale.
- Add a test covering rejection of an out-of-bounds vertex index.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tp1jQ6ZJCz1QXTASbyVhE7
A batch line of the form "<nx> <ny> <nz> <data_file>" (data file with the
default resolution) previously dropped the data file: the parser only read a
data file after a numeric resolution token, so a non-numeric token failed the
numeric extraction and was ignored. Sniff each trailing token instead -- a pure
number is a resolution, anything else is a data-file path -- so resolution and
data file may appear independently. Add a regression test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tp1jQ6ZJCz1QXTASbyVhE7
Reduce input clunk across all three surfaces, backward-compatibly:

Meshes:
- Add STL support (binary + ASCII), auto-detected by extension with a robust
  size-based binary/ASCII discriminator. Unified load_mesh dispatches OBJ/STL
  and runs the shared empty/index validation.

Field files:
- Treat a field file as a matrix: one row per entity, one column per timestep,
  so an entire time series fits in a single file. A data token may select a
  column via a trailing '@<col>' (default 0). One-value-per-line files remain
  the single-column case. Node-vs-face is inferred from the row count, with a
  new --field-mode node|face|auto to force it.
- Load each distinct field file once into a shared, read-only cache; workers
  extract their column concurrently, so a shared matrix is parsed once rather
  than once per thread.

Views:
- Accept azimuth/elevation angles via -a/--angle and an 'a <az> <el>' batch
  line form, alongside raw direction vectors.

Batch parsing:
- Fix silent data-file drop: resolution and data file are now order-independent
  (a pure number is a resolution, anything else a path), so a view can attach
  data without restating the resolution.

Examples & tests:
- Regenerate the committed demo as a single matrix file + angle batch (two
  files instead of 24); rewrite generate_field.py to match.
- Extend the suite to 25 checks (STL ASCII/binary, matrix column select and
  out-of-range, angle views, field-mode override and mismatch). Update README
  and help text.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Tp1jQ6ZJCz1QXTASbyVhE7
@Interfluo
Interfluo merged commit 23ae26f into main Jun 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants