Skip to content

TikZ backend: fix path closing artifact for non-filled curves #51

@yueswater

Description

@yueswater

Sub-issue of #50.

Problem

Path.to_polygons() returns closed polygon sequences by default — it
appends the starting vertex to the end so fill operations can use the
vertex list directly. For filled polygons this duplicate edge is hidden
under the fill. For open curves emitted via \draw, the duplicate vertex
produces a visible diagonal segment cutting across the figure (e.g. from
the top-left of an indifference curve back down to its lower-right tail).

Proposed fix

Strip the auto-appended closing vertex when rgbFace is None:

def draw_path(self, gc, path, transform, rgbFace=None):
    for poly in path.to_polygons(transform):
        if rgbFace is None and len(poly) > 2 and np.allclose(poly[0], poly[-1]):
            poly = poly[:-1]
        pts = ' -- '.join(
            f'({x*self.scale:.4f},{y*self.scale:.4f})' for x, y in poly
        )
        self._commands.append(f'{self._cmd(gc, rgbFace)} {pts};')

The np.allclose guard avoids stripping legitimate closed shapes that
arrive with rgbFace set (budget polygons, shaded regions).

Acceptance criteria

  • Indifference curves emitted via \draw contain no spurious closing
    segment.
  • Filled polygons (budget sets) still render as closed shapes.
  • Regression test asserts the emitted TikZ for an indifference-curve
    example has strictly monotonic vertex ordering (no return-to-origin).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions