mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
`convex_quad` accepts a quad only when it is wound clockwise on screen, so a Perspective Crop box flipped on one axis (an Alt+corner drag past the opposite corner along x only), which is convex but wound counter-clockwise, was drawn red and refused by `image.perspectiveCrop` and `quad_to_rect`. The reference application commits it mirrored, each corner mapped as it lies. Add `convex_quad_any_winding` (the same angle and area limits, either winding; self-crossing, degenerate and non-finite quads stay invalid) and use it for Perspective Crop only: the `corners` check and its error text, `quad_to_rect`, and the overlay's validity check. The homography already maps each corner onto its own rectangle corner, so the crop comes out mirrored. Perspective Warp steps keep the clockwise-only `convex_quad`; clicked corners are still sorted clockwise and commit upright; a box turned 180 degrees still commits upside down. Tests: algo (a counter-clockwise quad maps corner to corner; bow ties, collinear, sliver and non-finite quads stay refused), and the new perspective_crop_mirrored_tests.rs (the measured Alt-drag case commits mirrored and is drawn valid, the command takes counter-clockwise corners, clicks commit upright, 180 degrees upside down, invalid quads stay red). The mirrored cases fail without the fix. Fixes #12489