Skip to content

Add pilot canvas support for conic and cubic Bezier sample drawing#683

Open
tigercosmos wants to merge 1 commit intosolvcon:masterfrom
tigercosmos:pilot_gui_0227
Open

Add pilot canvas support for conic and cubic Bezier sample drawing#683
tigercosmos wants to merge 1 commit intosolvcon:masterfrom
tigercosmos:pilot_gui_0227

Conversation

@tigercosmos
Copy link
Collaborator

@tigercosmos tigercosmos commented Feb 26, 2026

Summary

Add pilot canvas support for conic and cubic Bezier sample drawing, and cover the new functionality with unit tests.

What changed

  • Added modmesh.pilot._canvas:
    • Canvas + CanvasMenu integration for pilot sample windows
    • conic primitives and samplers:
      • Ellipse / EllipseSampler
      • Parabola / ParabolaSampler
      • Hyperbola / HyperbolaSampler
    • generic piecewise cubic Bezier approximation helper for sampled points
    • BezierSample presets (s_curve, arch, loop)
    • BezierSampler with control polygon and control-point rendering
  • Wired _canvas imports in pilot package/gui initialization so canvas menu
    items are available in the GUI.
  • Added tests/test_pilot_canvas.py covering:
    • point generation behavior (npoint, closure, extrema/vertex, branch checks)
    • sampler construction, populate/draw paths, and error paths
    • Bezier preset data and draw path execution

Validation

  • Intended command: python3 -m pytest tests/test_pilot_canvas.py

Demo

Screenshot 2026-02-27 at 12 40 14 AM

AI Usage

  • Claude Code with Opus 4.6 for the first implementation
  • GitHub Copilot with Claude Sonnet 4.6 for fine-tuning

Related to #682

@tigercosmos tigercosmos marked this pull request as draft February 26, 2026 15:44
@yungyuc yungyuc added the pilot GUI and visualization label Feb 27, 2026
@yungyuc
Copy link
Member

yungyuc commented Feb 27, 2026

It makes more sense to reuse modmesh.pilot._canvas and then use a separate refactoring PR to make it a subpackage modmesh.pilot.canvas.

modmesh.pilot.curve is not a good module name. Straight line segments and polygons are special cases of curves, but it will be counter-intuitive to see straight line segment code under "curve".

It may be tempting to refactor the existing modmesh.pilot._canvas first, but it will make the history less clear, because at the moment, before new code is added, there is not much (code and tests) to refactor.

@yungyuc
Copy link
Member

yungyuc commented Feb 27, 2026

And I am interested in a new work flow: use a PR to discuss complex design like this without any git history rewriting. Once the review is done, create a new PR to clean up the git history (using a new branch), add summarizing commit logs and review annotations, and close the discussion PR.

This is more logistics but will keep the development course clearer. It's hard to gauge the pros and cons before trying. We may or may not need to do it right now. Let me know what do you think.

@tigercosmos
Copy link
Collaborator Author

@yungyuc I think it’s more efficient to refactor the code while adding new features, since the refactoring is then driven by real needs and we avoid leaving additional technical debt for the future.

Regarding your proposed workflow, it sounds similar to keeping the full git history within the PR and then squashing the commits into a single, meaningful summary commit when merging. When using the “Squash and merge” option, we can provide a well-structured commit message (typically prepared by the PR author) to summarize the changes clearly.

@yungyuc
Copy link
Member

yungyuc commented Feb 28, 2026

@yungyuc I think it’s more efficient to refactor the code while adding new features, since the refactoring is then driven by real needs and we avoid leaving additional technical debt for the future.

Refactoring and logical/data-structural changes should be separate. Mixing refactoring with other activities makes maintenance more difficult.

Regarding your proposed workflow, it sounds similar to keeping the full git history within the PR and then squashing the commits into a single, meaningful summary commit when merging. When using the “Squash and merge” option, we can provide a well-structured commit message (typically prepared by the PR author) to summarize the changes clearly.

We can keep discussing the github workflow while moving forward the development. I agree the two-PR idea is similar to the single-PR-with-final-squash. I dislike "Squash and merge" which does not allow multiple commits with distinct, tailored commit logs.

@tigercosmos tigercosmos force-pushed the pilot_gui_0227 branch 5 times, most recently from 2d91fee to 27b5ae9 Compare March 2, 2026 18:40
@tigercosmos tigercosmos changed the title Add pilot curves sub-package with conic and Bezier curve drawing Add pilot canvas support for conic and cubic Bezier sample drawing Mar 2, 2026
@tigercosmos tigercosmos force-pushed the pilot_gui_0227 branch 2 times, most recently from 8350b07 to 5857897 Compare March 2, 2026 20:01
@tigercosmos tigercosmos marked this pull request as ready for review March 3, 2026 12:37
@tigercosmos tigercosmos marked this pull request as draft March 3, 2026 12:41
func=self.mesh_iccad_2013,
)

tip = "Draw a sample S-shaped cubic Bezier curve with control points"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

New samples are under "Canvas" menu.


def __init__(self):
self.world = core.WorldFp64()
def _populate_sampler_points(curve, npoint=100, fac=1.0, off_x=0.0,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Shared by new samples.



class CanvasMenu(PilotFeature):
class Canvas(PilotFeature):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thnk it make more senses to keep just Canvas.

func=self.mesh_iccad_2013,
)

tip = "Draw a sample S-shaped cubic Bezier curve with control points"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

New items for the followings.

)

@staticmethod
def _draw_layer(world, layer):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

only for mesh_iccad_2013.

widget.updateWorld(world)
widget.showMark()

def _bezier_s_curve(self):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The drawer of the new sample.

Comment on lines +250 to +276
class Ellipse(object):
def __init__(self, a=2.0, b=1.0):
self.a = a
self.b = b

def calc_points(self, npoint):
t_array = np.linspace(0.0, 2.0 * np.pi, npoint + 1, dtype='float64')
point_pad = core.PointPadFp64(ndim=2, nelem=npoint + 1)
for index, t_value in enumerate(t_array):
x_value = self.a * np.cos(t_value)
y_value = self.b * np.sin(t_value)
point_pad.set_at(index, x_value, y_value)
return point_pad


class EllipseSampler(object):
def __init__(self, world, ellipse):
self.world = world
self.ellipse = ellipse
self.points = None

def populate_points(self, npoint=100, fac=1.0, off_x=0.0, off_y=0.0):
self.points = _populate_sampler_points(
self.ellipse, npoint=npoint, fac=fac, off_x=off_x, off_y=off_y)

def draw_cbc(self, spacing=0.01):
_draw_piecewise_bezier(self.world, self.points, spacing=spacing)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same pattern from Naca4Sampler.

Add pilot canvas drawing utilities for conic curves and cubic Bezier examples,
and expose them through the GUI sample menu.

- add `modmesh.pilot._canvas` with `Canvas`/`CanvasMenu`
- implement `Ellipse`, `Parabola`, and `Hyperbola` samplers
- add shared piecewise cubic Bezier rendering with input validation
- add `BezierSample` presets and `BezierSampler` with control overlays
- wire `_canvas` imports in pilot initialization
- add `tests/test_pilot_canvas.py` for geometry generation, draw paths, and
  expected error cases
@@ -0,0 +1,212 @@
# Copyright (c) 2026, Anchi Liu <phy.tiger@gmail.com>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All cases are AI genereated with manual checks and fine-tuning.

@tigercosmos tigercosmos marked this pull request as ready for review March 3, 2026 13:35
@tigercosmos
Copy link
Collaborator Author

@yungyuc Could you please help review the PR? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pilot GUI and visualization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants