Skip to content

refactor: break the Python wrapping code in universe/ to different files by shape dimension#704

Merged
yungyuc merged 8 commits intosolvcon:masterfrom
yungyuc:refactor/world-by-shapes
Mar 28, 2026
Merged

refactor: break the Python wrapping code in universe/ to different files by shape dimension#704
yungyuc merged 8 commits intosolvcon:masterfrom
yungyuc:refactor/world-by-shapes

Conversation

@yungyuc
Copy link
Copy Markdown
Member

@yungyuc yungyuc commented Mar 28, 2026

Note

Moving code across files results in the massive size in diff line count in this PR.

  • I used visual diff to compare the code before and after moving (in the different files) and confirmed that it is identical.

Reorganize the Python wrapping code in universe/pymod/ into 5 files:

  1. wrap_shape0d.cpp: Code that are not for shape.
    • Helpers for the Bernstein polynomials.
    • WrapPoint3d, WrapPointPad.
  2. wrap_shape1d.cpp: One-dimensional geometry entities.
    • WrapSegment3d, WrapSegmentPad.
    • WrapBezier3d, WrapCurvePad.
  3. wrap_shape2d.cpp: Two-dimensional geometry entities.
    • WrapTriangle3d, WrapTrianglePad.
    • WrapPolygon, WrapPolygonPad.
    • WrapTrapezoidPad.
    • WrapTrapezoidalDecomposer.
  4. wrap_shape3d.cpp: Three-dimensional geometry entities.
    • WrapBoundBox3d.
  5. wrap_World.cpp: The container World.
    • WrapWorld.

Note

Do not mistaken the spatial dimension of shapes with the dimension of coordinate system (the postfix in Point3d, Segment3d, etc.)

Comments are provided to guide the review.


Tip

The prompts used through clion claude plugin, chronologically, are:

  • Extract WrapPoint3d and WrapPointPad from wrap_World.cpp to a new file wrap_shape0d.cpp
  • Extract WrapSegment3d and WrapSegmentPad from wrap_World.cpp to a new file wrap_shape1d.cpp
  • Extract WrapBezier3d and WrapCurvePad from the file wrap_World.cpp to wrap_shape1d.cpp
  • Extract WrapTriangle3d and WrapTrianglePad from wrap_World.cpp to wrap_polygon.cpp
  • Extract WrapBoundBox3d from wrap_World.cpp to a new file wrap_shape3d.cpp
  • In wrap_polygon.cpp, refactor WrapPolygonPad like WrapTrianglePad

@yungyuc yungyuc self-assigned this Mar 28, 2026
@yungyuc yungyuc added the refactor Change code without changing tests label Mar 28, 2026
yungyuc added 8 commits March 28, 2026 15:19
* Create a new file `wrap_shape0d.cpp` to house wrapping code for 0-D geometry
  entity.
* Move the C++ wrapper classes `WrapPoint3d` and `WrapPointPad` from
  file `wrap_World.cpp` to `wrap_shape0d.cpp`.

Claude code prompt: Extract WrapPoint3d and WrapPointPad from wrap_World.cpp to
a new file wrap_shape0d.cpp
* Create a new file `wrap_shape1d.cpp` to house wrapping code for 1-D geometry
  entity.
* Move the C++ wrapper classes `WrapSegment3d` and `WrapSegmentPad` from file
  `wrap_World.cpp` to `wrap_shape1d.cpp`.

Claude code command:
* Extract `WrapSegment3d` and `WrapSegmentPad` from `wrap_World.cpp` to a new
  file `wrap_shape1d.cpp`
* Move the C++ wrapper classes `WrapBezier3d` and `WrapCurvePad` from file
  `wrap_World.cpp` to `wrap_shape1d.cpp`.

Claude code command:
* Extract `WrapBezier3d` and `WrapCurvePad` from the file `wrap_World.cpp` to
  `wrap_shape1d.cpp`
* Move the C++ wrapper classes `WrapTriangle3d` and `WrapTrianglePad` from file
  `wrap_World.cpp` to `wrap_polygon.cpp`.

Claude code command:
* Extract `WrapTriangle3d` and `WrapTrianglePad` from `wrap_World.cpp` to
  `wrap_polygon.cpp`
* Create a new file `wrap_shape3d.cpp` to house wrapping code for 3-D geometry
  entity.
* Move the C++ wrapper class `WrapBoundBox3d` from file `wrap_World.cpp` to
  `wrap_shapd3d.cpp`.

Claude code command:
* Extract `WrapBoundBox3d` from `wrap_World.cpp` to a new file
  `wrap_shape3d.cpp`
Add 3 member functions to `WrapPolygonPad`: `wrap_management()`,
`wrap_accessor()`, `wrap_search()`.

Claude code prompt:
* In `wrap_polygon.cpp`, refactor `WrapPolygonPad` like `WrapTrianglePad`
* Move wrappers for the functions `calc_bernstein_polynomial()` and
  `interpolate_bernstein()` from `wrap_bernstein.cpp` to `wrap_shape0d.cpp`
@yungyuc yungyuc force-pushed the refactor/world-by-shapes branch from c95c59d to c27f9f7 Compare March 28, 2026 07:20
@yungyuc yungyuc marked this pull request as ready for review March 28, 2026 07:50
WrapBezier3d<double>::commit(mod, "Bezier3dFp64", "Bezier3dFp64");
WrapCurvePad<float>::commit(mod, "CurvePadFp32", "CurvePadFp32");
WrapCurvePad<double>::commit(mod, "CurvePadFp64", "CurvePadFp64");
WrapWorld<float>::commit(mod, "WorldFp32", "WorldFp32");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Leave only WrapWorld in this file wrap_World.cpp.

namespace python
{

template <typename T>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  • WrapPoint3d, WrapPointPad are moved to wrap_shape0d.cpp
  • WrapSegment3d, WrapSegmentPad, WrapBezier3d, WrapCurvePad are moved to wrap_shape1d.cpp
  • WrapTriangle3d, WrapTrianglePad are moved to wrap_shape2d.cpp
  • WrapBoundBox3d is moved to wrap_shape3d.cpp

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In this file wrap_shape0d.cpp:

  • WrapPoint3d, WrapPointPad are moved from wrap_World.cpp
  • "calc_bernstein_polynomial", "interpolate_bernstein" are moved from wrap_berstein.cpp`

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In this file wrap_shape1d.cpp, WrapSegment3d, WrapSegmentPad, WrapBezier3d, WrapCurvePad are moved from wrap_World.cpp

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This file wrap_shape2d.cpp is renamed from wrap_polygon.cpp.

  • WrapPolygon, WrapPolygonPad, TrapezoidPad, WrapTrapezoidalDecomposer remain.
  • WrapTriangle3d, WrapTrianglePad are moved from wrap_World.cpp.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In this file wrap_shape3d.cpp, WrapBoundBox3d is moved from wrap_World.cpp

@yungyuc yungyuc requested a review from tigercosmos March 28, 2026 07:52
@yungyuc
Copy link
Copy Markdown
Member Author

yungyuc commented Mar 28, 2026

@tigercosmos @c1ydehhx please take a look. I may merge later soon since this simple renaming is clearly what I want. If there are points to be addressed I may use this PR or a future one.

@yungyuc yungyuc merged commit d4d18dd into solvcon:master Mar 28, 2026
14 checks passed
@yungyuc yungyuc deleted the refactor/world-by-shapes branch March 28, 2026 08:29
@yungyuc yungyuc added the pilot GUI and visualization label Mar 28, 2026
@yungyuc yungyuc added geometry Geometry entities and manipulation and removed pilot GUI and visualization labels Mar 28, 2026
@yungyuc yungyuc linked an issue Mar 28, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

geometry Geometry entities and manipulation refactor Change code without changing tests

Projects

Development

Successfully merging this pull request may close these issues.

Make a prototype for drawing 2D graphics

1 participant