Skip to content

Conversation

@EdwardAstill
Copy link

@EdwardAstill EdwardAstill commented Feb 28, 2025

Replaced `find_holes` with `filter_polygons` to improve clarity of intent and better reflect the method's purpose. This change enhances code readability and semantic accuracy in the polygon filtering process.

Pull Request Check List

Resolves: #issue-number-here

  • Added a description of your pull request below.
  • Added tests for changed code.
  • Updated documentation for changed code.
  • Run uv run pre-commit run --all-files and uv run pyright to ensure code quality.

Changed method to avoid deprecation warning

@robbievanleeuwen
Copy link
Owner

Hi @EdwardAstill, thanks for the PR.

The test suite is failing because filter_polygons() returns a list of Polygon, whereas find_holes() seems to have returned a Polygon or MultiPolygon (see here).

As a result these lines will need to be updated to suit. Would you like me to fix this or do you want to give it a shot?

@EdwardAstill
Copy link
Author

Hi Robbie,
I'll take a look and see if I can sort it out, I'm not sure how long it will take me. If you want to give it a shot in the meantime I wont stop you.

@robbievanleeuwen
Copy link
Owner

Hi @EdwardAstill I believe I've fixed the issue however am unable to push to your branch. Did you uncheck allowing maintainers to edit your branch? See here for more info.

@EdwardAstill
Copy link
Author

The allow edits by maintainers box is checked. It shouldn't have been unchecked though.

@robbievanleeuwen
Copy link
Owner

Ok strange! For some reason when I try to push it says I'm unauthenticated, haven't had this issue before! I'll make comments on this PR for the changes I've made to make this work if you want to make the commits and keep the contributor credit :) Otherwise I can make a new PR, up to you 👍

new_polygons = c2s.utils.find_holes(polygons)
new_polygons = c2s.utils.filter_polygons(polygons)

if isinstance(new_polygons, MultiPolygon):
Copy link
Owner

Choose a reason for hiding this comment

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

Replace lines 2516 -> 2522 with:

# ensure list length > 0
if len(new_polygons) == 0:
    msg = f"No shapely.Polygon objects found in file: {dxf_filepath}"
    raise RuntimeError(msg)

# ensure only Polygons are generated
for poly in new_polygons:
    if not isinstance(poly, Polygon):  # pyright: ignore [reportUnnecessaryIsInstance]
        msg = f"Not all objects found in file: {dxf_filepath} are Polygons"
        raise RuntimeError(msg)

if len(new_polygons) == 1:
    return Geometry(new_polygons[0])
else:
    return CompoundGeometry(MultiPolygon(new_polygons))

@robbievanleeuwen
Copy link
Owner

Further to get the type checking to work, you will need to change the following files:

typings/cad_to_shapely/__init__.pyi

from .dxf import DxfImporter
from .utils import filter_polygons, find_holes

typings/cad_to_shapely/utils.pyi

from shapely.geometry import Polygon

def find_holes(polygons: list[Polygon]) -> Polygon: ...
def filter_polygons(
    polygons: list[Polygon],
    filter_flag: int = ...,
) -> list[Polygon]: ...

@robbievanleeuwen robbievanleeuwen self-assigned this Mar 7, 2025
@robbievanleeuwen robbievanleeuwen added the dependencies Pull requests that update a dependency file label Mar 7, 2025
@EdwardAstill
Copy link
Author

I'm happy for you to make a new PR seeing as I didn't really change anything. Hopefully I'll make a more meaningful contribution in the future.

EdwardAstill and others added 3 commits March 7, 2025 13:03
    Replaced `find_holes` with `filter_polygons` to improve clarity of intent and better reflect the method's purpose. This change enhances code readability and semantic accuracy in the polygon filtering process.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants