Skip to content

add_line(snap_to_polygons=...) is accepted, documented, and ignored #15

Description

@rhugman

ConceptualMesh.add_line accepts a snap_to_polygons parameter and documents it:

def add_line(self, geometry, line_id, resolution, snap_to_polygons=True, is_barrier=False, ...):
    """
    snap_to_polygons (bool): If True, the line's endpoints will be snapped to
        nearby polygon boundaries to ensure connectivity.
    """

The value is never stored. The dict appended to self.raw_lines has no snap_to_polygons key, so nothing downstream can read it:

self.raw_lines.append({
    'geometry': geometry,
    'line_id': line_id,
    'lc': resolution,
    'is_barrier': is_barrier,
    'dist_min': dist_min,
    'dist_max': dist_max,
    'straddle_width': straddle_width
})

_enforce_connectivity then snaps every line unconditionally:

for i, line_data in enumerate(self.raw_lines):
    original_line = line_data['geometry']
    snapped_line = snap(original_line, poly_boundaries, tolerance)
    self.raw_lines[i]['geometry'] = snapped_line

So snap_to_polygons=False silently does nothing — the line is snapped anyway. A user who deliberately wants a line left un-snapped (for instance a line intentionally ending just short of a zone edge) gets the opposite of what they asked for, with no warning.

Options

  1. Implement it — store the flag and skip those lines in _enforce_connectivity. This is what the docstring already promises.
  2. Remove it — drop the parameter and the docstring entry, and document that all lines are snapped with connectivity_tolerance.

Option 1 is probably worth it: connectivity_tolerance is global, so per-feature opt-out is the only way to exempt a single line today.

Pre-existing on develop — not introduced by #12, though #12 adds connectivity_tolerance as a generate() override, which makes the missing per-feature control more noticeable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions