Skip to content

add support for SFCGAL alpha wrapping - #801

Closed
ptitjano wants to merge 2 commits into
postgis:masterfrom
ptitjano:3d-alpha-wrapping
Closed

ptitjano wants to merge 2 commits into
postgis:masterfrom
ptitjano:3d-alpha-wrapping

Conversation

@ptitjano

@ptitjano ptitjano commented May 7, 2025

Copy link
Copy Markdown
Contributor

This introduces CG_3DAlphaWrapping, a new function for SFCGAL
backend based on sfcgal_geometry_alpha_wrapping_3d.

The documentation and unit tests are updated accordingly.

SFCGAL 2.1 or above is needed.

cc @lbartoletti

@ptitjano
ptitjano force-pushed the 3d-alpha-wrapping branch from 07cc379 to e68b0d6 Compare May 7, 2025 13:53
@coderabbitai

coderabbitai Bot commented May 7, 2025 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

A new 3D alpha wrapping feature has been introduced, including its C implementation, SQL interface, documentation, test cases, and sample WKT data. The function CG_3DAlphaWrapping computes a watertight 3D surface enclosing input points, with parameters for alpha and offset. Associated documentation, regression tests, and image generation support were also added.

Changes

File(s) Change Summary
sfcgal/lwgeom_sfcgal.c, sfcgal/sfcgal.sql.in Added C implementation and SQL function declaration for CG_3DAlphaWrapping, exposing 3D alpha wrapping functionality with parameters for alpha and offset.
doc/reference_sfcgal.xml Added documentation entry for CG_3DAlphaWrapping, detailing usage, parameters, requirements, and examples with images. Minor whitespace correction in another function's example.
sfcgal/regress/alphawrapping.sql, sfcgal/regress/alphawrapping_expected Added new regression SQL test and expected output file for CG_3DAlphaWrapping, testing with various alpha values and verifying output point counts.
sfcgal/regress/tests.mk.in Updated regression test Makefile to conditionally include the new alpha wrapping test for compatible SFCGAL versions.
doc/html/images/Makefile.in Registered two new .wkt files in the list of generated images for documentation purposes.
doc/html/images/wkt/cg_3dalphawrapping01.wkt, doc/html/images/wkt/cg_3dalphawrapping02.wkt Added WKT data files containing 3D multipolygon and multipoint geometries for use in documentation and image generation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SQL
    participant PostGIS
    participant SFCGAL

    User->>SQL: CALL CG_3DAlphaWrapping(geom, alpha, offset)
    SQL->>PostGIS: Invoke sfcgal_alphawrapping_3d()
    PostGIS->>SFCGAL: Convert geometry, call alpha_wrapping_3d()
    SFCGAL-->>PostGIS: Return wrapped geometry
    PostGIS-->>SQL: Return result geometry
    SQL-->>User: Output wrapped geometry
Loading

Poem

In the warren of code, a new path appears,
Alpha-wrapped wonders for 3D frontiers.
Points now enclosed in a surface so tight,
With tests and docs shining bright.
The bunny leaps high, with geometry delight—
Wrapping the world in polygons tonight!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e68b0d6 and 2cd9919.

⛔ Files ignored due to path filters (1)
  • doc/html/images/cg_3dalphawrapping03.png is excluded by !**/*.png
📒 Files selected for processing (9)
  • doc/html/images/Makefile.in (1 hunks)
  • doc/html/images/wkt/cg_3dalphawrapping01.wkt (1 hunks)
  • doc/html/images/wkt/cg_3dalphawrapping02.wkt (1 hunks)
  • doc/reference_sfcgal.xml (1 hunks)
  • sfcgal/lwgeom_sfcgal.c (1 hunks)
  • sfcgal/regress/alphawrapping.sql (1 hunks)
  • sfcgal/regress/alphawrapping_expected (1 hunks)
  • sfcgal/regress/tests.mk.in (1 hunks)
  • sfcgal/sfcgal.sql.in (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • doc/html/images/wkt/cg_3dalphawrapping01.wkt
  • doc/html/images/Makefile.in
🚧 Files skipped from review as they are similar to previous changes (6)
  • sfcgal/regress/tests.mk.in
  • sfcgal/sfcgal.sql.in
  • doc/html/images/wkt/cg_3dalphawrapping02.wkt
  • sfcgal/regress/alphawrapping.sql
  • doc/reference_sfcgal.xml
  • sfcgal/lwgeom_sfcgal.c
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: macOS
  • GitHub Check: 14.2-RELEASE
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: CI (pg14-geos39-gdal33-proj71, tests)
  • GitHub Check: CI (pg13-geos38-gdal31-proj71, tests)
  • GitHub Check: CI (pg12-geos38-gdal30-proj611, tests)
  • GitHub Check: CI (latest, tests)
  • GitHub Check: CI (pg15-clang-geos311-gdal35-proj90, usan_clang)
  • GitHub Check: CI (pg13-clang-geos39-gdal31-proj71, usan_clang)
  • GitHub Check: CI (pg15-geos311-gdal35-proj90, coverage)
  • GitHub Check: CI (pg16-geos312-gdal37-proj921, coverage)
  • GitHub Check: CI (pg17-geosmain-gdal39-proj94, coverage)
🔇 Additional comments (1)
sfcgal/regress/alphawrapping_expected (1)

1-2: Appropriate expected output file for the regression test.

This file correctly provides the expected output for the new CG_3DAlphaWrapping function's regression test. The format follows PostGIS's standard pattern for regression test expected outputs, with the function name followed by a pipe character and the expected result (t for true/success).

While the test is minimal (only checking that the function exists and works), this is an appropriate starting point for regression testing. Consider expanding the test coverage in the future to validate different parameter combinations and edge cases.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 1

🧹 Nitpick comments (3)
sfcgal/sfcgal.sql.in (1)

599-599: Consider adding parameter validation or documentation comment

While the function signature itself looks good, it might be helpful to add inline SQL documentation about what the relative_alpha and relative_offset parameters represent, or add parameter validation to ensure they fall within appropriate ranges.

doc/reference_sfcgal.xml (2)

3588-3593: Fix duplicated word
The sentence “It can can have values from 0 to infinity.” has a duplicated “can”.

Replace with:

<para>
    The <varname>relative_alpha</varname> parameter controls which features will appear in the output.
    It can have values from 0 to infinity.
    Smaller <varname>relative_alpha</varname> values result in simpler outputs, but they are less accurate representations of the original input.
</para>

3588-3598: Use <xref> for internal references
Local cross-references should use <xref> instead of <link> with linkend to be consistent with other entries.

Modify:

-       <para>Computes the <link xlink:href="https://doc.cgal.org/latest/Alpha_wrap_3/index.html">3D Alpha Wrapping</link> of the points in a geometry. An alpha wrapping is a watertight and orientable surface mesh that strictly encloses the input. It can be seen as an extension or refinement of an <link linkend="CG_AlphaShape">alpha-shape</link>.</para>
+       <para>Computes the <link xlink:href="https://doc.cgal.org/latest/Alpha_wrap_3/index.html">3D Alpha Wrapping</link> of the points in a geometry. An alpha wrapping is a watertight and orientable surface mesh that strictly encloses the input. It can be seen as an extension or refinement of an <xref linkend="CG_AlphaShape">alpha-shape</xref>.</para>
🛑 Comments failed to post (1)
doc/reference_sfcgal.xml (1)

3579-3583: 🛠️ Refactor suggestion

Use floating-point parameters and mark offset as optional
The relative_alpha and relative_offset parameters should allow fractional values (not just integers), matching other CGAL-based functions (e.g. CG_AlphaShape). Since relative_offset = 0 triggers auto-computation, mark it as optional with a default.

Proposed diff:

-               <paramdef><type>integer</type> <parameter>relative_alpha</parameter></paramdef>
-               <paramdef><type>integer</type> <parameter>relative_offset</parameter></paramdef>
+               <paramdef><type>float</type> <parameter>relative_alpha</parameter></paramdef>
+               <paramdef choice="opt"><type>float</type> <parameter>relative_offset = 0</parameter></paramdef>
🤖 Prompt for AI Agents (early access)
In doc/reference_sfcgal.xml around lines 3579 to 3583, update the parameter
types for relative_alpha and relative_offset from integer to floating-point to
allow fractional values. Additionally, mark relative_offset as optional by
specifying a default value of 0 to indicate auto-computation, aligning with
other CGAL-based functions.

ptitjano and others added 2 commits May 15, 2025 09:06
This introduces `CG_3DAlphaWrapping`, a new function for SFCGAL
backend based on `sfcgal_geometry_alpha_wrapping_3d`.

The documentation and unit tests are updated accordingly.

SFCGAL 2.1 or above is needed.
@lbartoletti

Copy link
Copy Markdown
Contributor

Merged

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.

2 participants