Skip to content

Parametric Construction Points - #65

Open
TheJoeFin wants to merge 11 commits into
devfrom
magic-points
Open

Parametric Construction Points#65
TheJoeFin wants to merge 11 commits into
devfrom
magic-points

Conversation

@TheJoeFin

Copy link
Copy Markdown
Owner

PR Classification

New feature and UI enhancement for interactive parametric construction geometry in image measurement.

PR Summary

Introduces a full construction geometry system with interactive editing, edge detection, and integration into measurement and transform workflows. Adds robust serialization, undo/redo, and improved file handling.

  • ConstructionGeometry, ConstructionOverlayControl, and related DTOs: Implements point/line/circle graph model, overlay control, and serialization logic.
  • BoundaryProbeAnalyzer, ImageSampleBuffer: Adds color-aware edge detection for precise point placement.
  • MainWindow and tool logic: Integrates construction tools, manages overlay lifecycle, tool state, and UI synchronization.
  • GeometryMathHelper: Adds robust circumcircle solver for three points.
  • File helpers: Improves image file writing with correct format and extension handling.

TheJoeFin and others added 7 commits August 2, 2026 10:55
Detected quadrilaterals are named "Quad: N" and described by their contour
confidence. A quadrilateral that did not come from contour detection has no
meaningful confidence, so add an optional Label that overrides both.

Also guard the preview scaling against a zero-width or zero-height quad, which
divided by zero and produced NaN preview points.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Geometry for a construction the user builds out of points rather than corners:
points along an object's edges, lines through those points, and circles through
triples of them. Corners are never stored — ConstructionSolver derives them by
intersecting the lines, which is what lets a corner sit outside the image.

Points are either free, or derived from the geometry that produced them: the
crossing of two lines, or the centre of a circle. A derived point re-fits from
its parents on every refresh, and is released into an ordinary point if they are
deleted, so keeping one never leaves a dangling reference.

Entities reference each other by id rather than index so removing one cannot
silently repoint another. The DTOs mirror this for project persistence, and the
new fields default such that projects saved before constructions existed still
load.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Puts the construction model on screen. One control owns the whole graph rather
than one per entity, because a derived corner is a function of all the lines and
the solve needs a single owner.

Interaction is selection-first: a point must be selected before it can be
dragged, so aiming at one to pick it no longer nudges it out of place. Two
selected points offer a faint line, three offer the circle through them, and
clicking the offer builds it. Line crossings and circle centres appear as faint
rings that follow their parents and vanish with them unless clicked to keep.
Selecting a line or circle and pressing Delete removes it without its points.

Every committed edit becomes one undo step, published by the overlay as
before/after snapshots of the whole graph — the graph is small and every corner
depends on all of it, so a snapshot is both cheaper to reason about and
impossible to desync. A drag is one step rather than one per mouse move, and the
gesture brackets are idempotent because this codebase ends drags on the next
mouse move, which may never arrive.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Added `BoundaryProbeAnalyzer` for sub-pixel, color-based edge detection along user probe lines using a 1D derivative-of-Gaussian algorithm. Introduced `ImageSampleBuffer` for fast, bilinear RGB sampling from images with robust file handling. Both classes are optimized for interactive measurement tools and have no WPF dependencies.
Introduced a "Boundary" construction tool for probing image edges by dragging a line; analyzes pixels to find boundaries and previews the landing point. Added a live preview marker in ConstructionOverlayControl, with visual cues for weak detections. MainWindow now manages the probe gesture lifecycle, including async image sampling via ImageSampleBuffer for efficient analysis. Updated UI state, undo/redo, and hint system to support the new tool. Extended enums and tool state sync for the Boundary tool and drag mode.
Centralize MagickImage temp file writing with extension/encoder logic, updating all usages to ensure correct format. Add ConstructionBoundaryToggle and ProgressRing controls for "Find Edge Point" tool in both tabs, with tooltips/icons. Sync tool toggle state across tabs, handling Unchecked events. Improve pixel zoom and coordinate conversion for edge probing. Refactor for clarity and update comments/tooltips.
The construction tool usage TextBlock and the "Construction (Parametric)" GroupBox are now hidden by default. The "Use for Transform" button style was changed from Primary to Secondary for visual consistency.
@TheJoeFin

Copy link
Copy Markdown
Owner Author

I found several correctness regressions that should be addressed before merging:

  1. Valid quadrilaterals can become self-crossing (ConstructionOverlayControl.xaml.cs:343-366). NormalizeWinding produces a valid ring, but DetectedQuadrilateral reorders it using coordinate extrema. A valid trapezoid such as (0,0), (3,0), (1,1), (0,1) becomes a bow-tie, causing transform/un-warp markers to target the wrong corners.
  2. Unrelated points can invalidate solved geometry (ConstructionSolver.cs:170-182). Boundary half-planes are oriented using the centroid of every construction point, including unattached and circle points. A stray point outside the polygon can flip those half-planes and change a valid construction to NoUsableCorners.
  3. Edge dragging permits duplicate and self-loop lines (MainWindow.Construction.cs:408-413). Snapping the loose end does not perform the invariant checks used by the two-click and ghost-line paths, so it can reconnect to its starting point or create a second edge between an existing pair.
  4. Point-drag undo is not finalized on mouse-up (MainWindow.xaml.cs:559-563, 2166-2200). EndDrag() only runs if a later mouse-move observes released buttons. Pressing Undo immediately after release can therefore target the previous operation.
  5. Capture loss leaves construction gestures active (MainWindow.xaml.cs:342-350). The lost-capture handler only resets panning. Alt-tabbing during edge creation or boundary probing leaves temporary geometry and transaction state active.
  6. Construction editing handles appear in exports (MainWindow.xaml.cs:1383-1433). Construction overlays are rendered with measurements, but their IsDragGizmoVisible state is not disabled like markup controls, allowing handles, candidates, and ghost lines into the output.
  7. Undo can restore overlays from a previous image (UndoRedo.cs:674-684, MainWindow.xaml.cs:1689-1694). Opening another image removes construction controls without clearing the undo stack, so an old ConstructionOverlaysRemovedItem can reattach controls to the new image.
  8. Boundary probing ignores alpha-only edges (ImageSampleBuffer.cs:22-23, 63-67). RGB sampling cannot distinguish transparent and opaque pixels with the same RGB values, including transparent borders produced by rotation.

Each line and circle now has a ShowMeasurement property, persisted in DTOs and project files, allowing users to toggle measurement labels via context menu. Added global ShowShapeMeasurement toggle for derived shape readout, with UI and persistence. Updated rendering and event handlers to respect these toggles. Serialization logic ensures backward compatibility with older projects.
Introduced a "Face" selection tool allowing users to select and merge bounded regions formed by construction lines. Added `ConstructionFaceSolver` to compute and merge faces, and a `ConstructionFace` record to represent each cell. Updated `ConstructionOverlayControl` to manage face states, hit-testing, and visual feedback. Enhanced `MainWindow` with UI for selecting shapes and merging faces into polygons, including button state logic. Updated XAML to support the new tool and help text.
Added MagickCrop.Tests (.NET 10.0, MSTest, Moq, WPF) to solution with UndoRedo, GeometryMathHelper, and MeasurementFormattingHelper tests. Enabled parallel test execution. Updated solution and settings for test integration.
Added "Change Color" context menu to all measurement, markup, and construction controls, enabling per-instance color selection via a new ColorPickerDialog and ColorSwatchPicker control. Colors are now serialized in project DTOs and restored on load, with backward compatibility for older files. Refactored guide lines to use the new picker. Centralized swatch colors in ColorPalette helper. Visuals update immediately on color change.
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