Polygon_closest_distance_line()'s fallback loop (used whenever the
query line does not cross the polygon) iterated i=0..N-2 and never
tested the closing edge V[N-1]->V[0]. Every other polygon helper in
this file (Polygon_outside, Polygon_intersects) and the sibling
Polygon_closest_distance_point() already wrap around to include this
edge; this function was the one left behind.
The only caller, AP_OABendyRuler::calc_margin_from_inclusion_and_exclusion_polygons(),
passes in AC_Fence polygons in their raw unclosed form (no duplicated
closing vertex), so in real fences this is a genuine edge that was
silently skipped, causing the reported clearance/margin to the fence
boundary to be overestimated near that edge.
Fix mirrors the existing wrap-around pattern from Polygon_intersects()
a few lines above in the same file. Added a regression test using a
simple square fence to confirm the closing edge is now considered and
that behaviour near unaffected edges is unchanged.
Assisted-by: Claude:claude-sonnet-5