Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: measure Path areas #254

Open
blairfrandeen opened this issue Jun 17, 2024 · 1 comment
Open

Feature: measure Path areas #254

blairfrandeen opened this issue Jun 17, 2024 · 1 comment

Comments

@blairfrandeen
Copy link

I propose that Path objects should have an area() function that computes the area enclosed by the path. This would be similar to the area() function in svgpathtools, but would work with paths that are not continuous. The application that I need this for is paths with a "hole" in them (like a donut). svgpathtools is not capable of computing areas for these paths, as it does not implement subpaths. See mathandy/svgpathtools#89 for some context.

I successfully implemented this function in my own project, essentially using svgelements.Path and copying the logic from svgpathtools.area(). I validated my solution against a third measurement method (Inkscape's built-in measure path extension), and I have several distinct test cases.

I'm happy to work on a PR towards this goal, but I wanted to verify that this is of interest / in scope before making the effort. Thanks for maintaining this very useful library!

@derVedro
Copy link

@blairfrandeen not the right place for me to discuss about svgpathtools and that is a XY-problem nobody wants to hear about, but I solved that kind of issue some time ago like that:

import copy
from svgpathtools import Line, Path

def compute_area(path : Path):

    def closed_path(path: Path) -> Path:
        if path.isclosed():
            path = copy.copy(path)
            path.append(Line(start=path.end, end=path.start))
        return path

    return sum(map(lambda p : closed_path(p).area(), path.continuous_subpaths()))

Somehow continuous_subpaths() returns all subpaths regardless of whether they are closed or not closed. May be I just don't understand what continuous means in this context.

I tested that way of computing area of paths consisting of Lines and CubicBezier. It's working fine.

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

No branches or pull requests

2 participants