Skip to content

Trim raytracing_app.py: dead code, element-drawer dispatch, results data spec - #502

Merged
dccote merged 4 commits into
masterfrom
cleanup-raytracing-app
Apr 15, 2026
Merged

Trim raytracing_app.py: dead code, element-drawer dispatch, results data spec#502
dccote merged 4 commits into
masterfrom
cleanup-raytracing-app

Conversation

@dccote

@dccote dccote commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Cuts raytracing_app.py from 1176 → 994 lines (-182) across three reviewable commits, no behavior change.

  1. Remove dead code — unused time / tkinter.DoubleVar imports, commented-out add_aperture_button widget block, commented-out aperture seed record (referenced fields not in the schema), unreachable add_aperture_button branch in click_table_buttons.
  2. Extract element drawerscreate_optical_path had four near-identical if/elif type(element) is X branches that each redrew the aperture top/bottom marks inline. Pull marks into _draw_aperture_marks, give each element type its own _draw_* helper, dispatch through a small dict. ThickLens and DielectricSlab share _draw_thick_element parameterised by body shape (Oval vs Rectangle). Adding a new element type now means one entry + one helper.
  3. Results table as a data speccalculate_imaging_path_results had 13 metrics each written as ~10 lines of paired has-stop / no-stop append_record calls. Pull them into class-level RESULT_ROWS = [(label, lambda p: ...), ...] and let the method walk the spec. Each lambda is self-contained, including its 'Inexistent' / 'Infinite [no FS]' fallback. Verified all 15 rows render correctly against paths with and without aperture/field stops.

Not done in this PR (separate readability decision, no line savings):

  • Splitting create_window_widgets into per-section build helpers.

Test plan

  • Launch python -m raytracing -a, confirm default Lens scene renders identically.
  • Add a ThickLens and a DielectricSlab via the table, confirm both draw with body + aperture marks.
  • Build a path with no aperture stop and one with no field stop, confirm the results table shows the right 'Inexistent' fallbacks.

🤖 Generated with Claude Code

dccote and others added 4 commits April 15, 2026 00:46
- Drop unused `time` and `tkinter.DoubleVar` imports
- Drop the commented-out `add_aperture_button` widget block
- Drop the commented-out aperture seed record (it referenced
  fields that aren't in the table schema)
- Drop the unreachable `add_aperture_button` branch in
  click_table_buttons (the button widget doesn't exist; the elif
  would have AttributeError'd if reached)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
create_optical_path had four near-identical branches (Lens, Aperture,
ThickLens, DielectricSlab) that each redrew the aperture top/bottom
marks inline. Pull the marks into _draw_aperture_marks, give each
element type its own _draw_* helper, and dispatch through a small
dict in create_optical_path. ThickLens and DielectricSlab share
_draw_thick_element parameterised by the body shape (Oval vs
Rectangle).

Adding a new element type now means: write one helper, add one entry.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The 13 metrics displayed in the results table each had ~10 lines of
inline data_source.append_record() calls with their own has-stop /
no-stop branch. Pull them into RESULT_ROWS — a class-level list of
(label, getter) tuples — and let calculate_imaging_path_results just
walk the spec.

Each getter is a self-contained lambda returning the final string,
including the 'Inexistent' / 'Infinite [no FS]' fallback for the
case where the metric doesn't apply. Adding a metric is now one line.

Verified all 15 rows produce the expected output for paths with and
without aperture/field stops.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
create_window_widgets used to be ~260 lines of widget construction,
property bindings, and observer registration in one method. Split it
into a table-of-contents top-level method that calls six helpers:
_build_element_table, _build_results_table, _build_controls_panel,
_build_canvas, _wire_bindings, _register_observers.

Other tidying done in the same pass:
- Drop the dead `optics_basis = ...` local that was never used.
- Promote `radio_principal` to `self.radio_principal` so the bindings
  helper can find it.
- Collapse the five repeated `is_disabled` bindings into a `for`
  loop, and the seven `add_observer` calls into another.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dccote
dccote merged commit fc15667 into master Apr 15, 2026
@dccote
dccote deleted the cleanup-raytracing-app branch April 15, 2026 04:54
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.

1 participant