Add standalone Python demo script and complete package exports - #3
Merged
Merged
Conversation
…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
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
marked this pull request as ready for review
July 15, 2026 12:44
Contributor
There was a problem hiding this comment.
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.pyscript 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 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 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 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 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") | ||
|
|
| 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 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 mirroringmatlab/Demo.m: four examples (unit square, equilateral triangle, regular pentagon, irregular pentagon δ-sweep) runnable without Jupyterpython/implicit_spline/__init__.py— addsdraw_surfaceandcompare_deltato public exports; they existed invisualization.pybut were unreachable via top-level importexamples/README.md— documents the new script entry point