Skip to content

View grid: expose grid_segments from the engine and draw the viewport from it - #10892

Closed
cpmech wants to merge 1 commit into
tangency-labs:mainfrom
cpmech:grid-segments
Closed

cpmech wants to merge 1 commit into
tangency-labs:mainfrom
cpmech:grid-segments

Conversation

@cpmech

@cpmech cpmech commented Nov 1, 2026

Copy link
Copy Markdown

Change

The grid's primitives (grid_plane, grid_step, grid_lines, GridFade, grid_ext, grid_far_reach) are public in solidcraft_engine::view, but the loop that turns GridLineAt and the fade into drawn segments lived in crates/ui-egui/src/viewport.rs. A consumer outside the application — plugin work, or testing an independent feature in an isolated environment — had to link the whole CAD front end or repeat 30–60 lines of plotting.

This extracts the loop into solidcraft_engine::view:

pub struct GridSegment {
    pub a: Vec3,
    pub b: Vec3,
    pub alpha: f32,
    pub major: f32,
}

pub struct GridFrame {
    pub centre: Vec3,
    pub u: Vec3,
    pub v: Vec3,
    pub origin: Vec3,
    pub fade: GridFade,
}

pub fn grid_segments_on(cam: &Camera, frame: &GridFrame, cap: i64) -> Vec<GridSegment>;

pub fn grid_segments(cam: &Camera, far: f64, follows_view: bool, last: &mut GridPlane)
    -> Vec<GridSegment>;
  • grid_segments is the default viewport grid: the plane choice through grid_plane with its existing hysteresis, grid_step, the centre snap, grid_ext, grid_far_reach and GridFade.
  • grid_segments_on is the same loop for an arbitrary frame, used by the viewport's open-sketch grid and by the headless picture.
  • grid_centre moved from the viewport into the engine.

The viewport's ground branch now calls grid_segments and keeps only the colour/width/vertex building; its sketch branch builds a frame and calls grid_segments_on. The headless scene uses grid_segments_on with its existing target-snapped frame and its two-colour emitter.

Deviations from the API sketch in the request:

  • solidcraft-engine cannot depend on egui, so there is no Rect. The grid's extent comes from cam.half_height() and grid_ext, as the loop already did.
  • GridSegment carries major because both callers blend the minor and major colours and widths from line.major.
  • grid_segments takes the picture's far, the follows_view preference and the previous GridPlane; the fade cut and the hysteretic edge-on switch need them.

Related: #10641. This is the grid half of the split's view-math work; the function can move to solidcraft-view-math when that crate lands.

Changes a default: no

Validation

  • cargo test -p solidcraft-engine --profile ci --lib — 3146 passed, 0 failed, 8 ignored (measured on the 58c64ca4 base, before rebasing onto the current main).
  • cargo test -p solidcraft-ui-egui --profile ci --lib -- --test-threads=1 — 4094 passed, 1 failed, 19 ignored (same base). The failure is render_workspace::tests::progressive_image_controls_route_to_the_registered_host (glass media InvalidScene), which reproduces unchanged on a clean checkout of 58c64ca4.
  • After rebasing onto cfc46448a (a single unrelated joints commit), the targeted suites were re-run: engine --lib -- grid 17 passed, engine --lib -- guides 3 passed, ui-egui --lib -- grid 47 passed, including the_picture_and_the_window_draw_the_same_grid_on_a_sketch_plane.
  • cargo fmt --all -- --check; cargo xtask layers (18 crates), lists, ui-containers — all pass.
  • cargo check --workspace --all-targets --profile ci — exit 0.
  • Clippy: the changed code is clean. The local gate stops on two pre-existing manual_option_zip hits (crates/ui-egui/src/agent_chat/settings.rs:223, crates/ui-egui/src/viewport.rs:1543), both present on cfc46448a and untouched here.

Screenshots of the behavior (when observable)

No visible change: the grid is drawn from the same grid_step, grid_lines, GridFade, grid_ext and grid_far_reach, with the same points, alphas, colours and widths, in the same order. The existing grid, fade and headless-picture tests assert it, including the picture/window grid equality on a sketch plane. No screenshot is attached because there is no visible difference to show.

Integration status

Based on upstream main cfc46448a (2026-11-02); the branch has one commit on top. The split in #10641/#10642 (currently an empty draft claim) may move the view functions; this PR is the grid delta and can move with it. PR #6889 (grid units) changes the same engine grid code and viewport grid drawing, and #9843 (grid crossings) changes view.rs; whichever lands first, the other needs a rebase. PR #10873 (the compass) is a separate open PR and does not touch the grid functions; #7731/#10266 touch the navigator in viewport.rs, a different block.

The viewport and the headless picture now build the grid from one public API, grid_segments and grid_segments_on, which return world segments with their fade and major/minor share. The plane choice, the steps, the reach and the hysteresis stay in the engine; the viewport keeps only the vertex building.
@github-actions github-actions Bot added the area:ui desktop/web front end, dialogs, viewport label Nov 1, 2026
@cpmech cpmech closed this Nov 2, 2026
@cpmech
cpmech deleted the grid-segments branch November 24, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ui desktop/web front end, dialogs, viewport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant