Skip to content

Add standalone Python demo script and complete package exports - #3

Merged
QL-UoHull merged 3 commits into
mainfrom
copilot/implement-code-update-pr
Jul 15, 2026
Merged

QL-UoHull merged 3 commits into
mainfrom
copilot/implement-code-update-pr

Conversation

Copilot AI commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

The repo had a full MATLAB/Python implementation but no standalone Python demo — the examples/ directory was documentation-only.

Changes

  • examples/demo.py — standalone script mirroring matlab/Demo.m: four examples (unit square, equilateral triangle, regular pentagon, irregular pentagon δ-sweep) runnable without Jupyter
  • python/implicit_spline/__init__.py — adds draw_surface and compare_delta to public exports; they existed in visualization.py but were unreachable via top-level import
  • examples/README.md — documents the new script entry point
python examples/demo.py

…d docs

Bug fixes in MATLAB implementation:
- ImpSpline2D.m: replaced undefined 'zz' variable with consistent 'f'
- DrawImpSpline.m: separated computation from visualisation; returns grid
- dataFrGr.m: removed brittle 'temp.dat' IO; fixed mouse-button logic
- Lxy.m: corrected signed-distance formula (dx*(y-y1)-dy*(x-x1)/len)
- Added edge-case guards (zero-length edge warnings, CCW auto-correction)

New files:
- matlab/: H, Lxy, Lxy00, Point_imp, LineSeg_imp, L_corner_inter,
           Square_Angle_inter, U_Angle_inter, ImpSpline2D,
           DrawImpSpline, DrawImpSpline_V1, dataFrGr, Demo, Demo_v1
- python/implicit_spline/: core.py, visualization.py, __init__.py
- notebooks/: 01_basic_polygon.ipynb, 02_data_from_file.ipynb
- data/sample_polygon.txt
- requirements.txt, .gitignore
- Updated README.md, data/README.md, examples/README.md
Copilot AI changed the title [WIP] Update and port MATLAB implementation to Python Add MATLAB reference implementation, Python port, and Jupyter demos for 2D implicit spline Jul 15, 2026
Copilot AI requested a review from QL-UoHull July 15, 2026 12:25
Copilot AI changed the title Add MATLAB reference implementation, Python port, and Jupyter demos for 2D implicit spline Add standalone Python demo script and complete package exports Jul 15, 2026
@QL-UoHull
QL-UoHull marked this pull request as ready for review July 15, 2026 12:44
Copilot AI review requested due to automatic review settings July 15, 2026 12:44
@QL-UoHull
QL-UoHull merged commit 0b20270 into main Jul 15, 2026
3 checks passed
@QL-UoHull
QL-UoHull deleted the copilot/implement-code-update-pr branch July 15, 2026 12:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the repository from a “landing page + notebooks” experience into a more directly runnable reference implementation by adding a standalone Python demo script, making the Python package exports more complete, and updating accompanying documentation/data so users can run demos without Jupyter.

Changes:

  • Add a standalone examples/demo.py script mirroring the MATLAB demo workflow.
  • Expose additional visualization helpers (draw_surface, compare_delta) through the top-level Python package export surface.
  • Refresh README / examples / data documentation and add minimal Python dependencies + ignore rules.

Reviewed changes

Copilot reviewed 24 out of 26 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
requirements.txt Adds minimal Python runtime dependencies (numpy, matplotlib).
README.md Updates repo status/structure and adds Python usage instructions/snippets.
python/implicit_spline/core.py Provides the core vectorized implicit-spline math implementation in Python.
python/implicit_spline/visualization.py Adds Matplotlib-based grid evaluation and plotting helpers.
python/implicit_spline/init.py Defines the public Python API surface via top-level exports.
examples/demo.py Standalone runnable Python demo script (non-notebook).
examples/README.md Documents how to run the new demo and where other demos live.
notebooks/01_basic_polygon.ipynb Notebook demo updated/added to match the new Python API helpers.
notebooks/02_data_from_file.ipynb Notebook demo for loading polygon data from data/sample_polygon.txt.
data/sample_polygon.txt Adds a concrete sample polygon file for demos/notebooks.
data/README.md Documents the sample polygon file format and usage.
matlab/H.m MATLAB smooth step function documentation/implementation refinements.
matlab/Lxy.m MATLAB signed-distance helper documentation/robustness updates.
matlab/Lxy00.m Adds/updates unnormalised signed linear helper.
matlab/Point_imp.m Adds/updates squared-distance-to-point helper.
matlab/LineSeg_imp.m Adds/updates finite segment implicit helper.
matlab/L_corner_inter.m Adds/updates corner blending helper.
matlab/Square_Angle_inter.m Adds/updates right-angle corner specialization.
matlab/U_Angle_inter.m Adds/updates obtuse/reflex corner specialization.
matlab/ImpSpline2D.m MATLAB main implicit spline function: validation + bug-note + documentation.
matlab/DrawImpSpline.m MATLAB evaluation/visualization helper that separates compute vs plotting.
matlab/DrawImpSpline_V1.m Retains a legacy visualization helper with deprecation note.
matlab/Demo.m MATLAB demo script (multi-example) aligned with repo narrative.
matlab/Demo_v1.m Legacy MATLAB demo retained for reference.
matlab/dataFrGr.m Interactive MATLAB polygon capture updated for robustness and configurable output.
.gitignore Adds Python/Jupyter/MATLAB common ignores.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +50 to +55
iso_level: float = 0.5,
show_polygon: bool = True,
cmap: str = "viridis",
title: str | None = None,
):
"""Evaluate the implicit spline on a grid and render a contour plot.
Comment on lines +122 to +126
N: int = 100,
ax=None,
cmap: str = "plasma",
title: str | None = None,
):
Comment on lines +9 to +13
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm

from .core import imp_spline_2d
Comment thread examples/demo.py
Comment on lines +55 to +57
fig1, ax1 = plt.subplots(figsize=(6, 5))
fig1.canvas.manager.set_window_title("Demo — Example 1: Square")
draw_imp_spline(P_sq, delta=DELTA, n=N_ORDER, N=N_GRID, ax=ax1,
Comment thread examples/demo.py
Comment on lines +65 to +67
fig2, ax2 = plt.subplots(figsize=(6, 5))
fig2.canvas.manager.set_window_title("Demo — Example 2: Triangle")
draw_imp_spline(P_tri, delta=DELTA, n=N_ORDER, N=N_GRID, ax=ax2,
Comment thread examples/demo.py
Comment on lines +76 to +78
fig3, ax3 = plt.subplots(figsize=(6, 5))
fig3.canvas.manager.set_window_title("Demo — Example 3: Pentagon")
draw_imp_spline(P_pent, delta=DELTA, n=N_ORDER, N=N_GRID, ax=ax3,
Comment thread examples/demo.py
Comment on lines +86 to +88
fig4 = compare_delta(P_irr, deltas=(0.05, 0.15, 0.30), n=N_ORDER, N=N_GRID)
fig4.canvas.manager.set_window_title("Demo — Example 4: delta sweep")

Comment thread data/README.md
A six-vertex irregular hexagon stored as plain text, one vertex per line
(format: `x y` with space separator, comment lines start with `#`).

Used by `notebooks/02_data_from_file.ipynb` and the MATLAB `Demo.m`.
Comment thread README.md
Comment on lines +112 to +116
import numpy as np
from implicit_spline import imp_spline_2d, draw_imp_spline

P = np.array([[0,0],[1,0],[1,1],[0,1]], dtype=float)
draw_imp_spline(P, delta=0.12, n=2, N=300)
Copilot stopped work on behalf of QL-UoHull due to an error July 15, 2026 12:51
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.

3 participants