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

Path fixup methods #136

Closed
wants to merge 1 commit into from
Closed

Conversation

Sophist-UK
Copy link
Contributor

  1. A method to close almost closed subpaths.
  2. (TBA) A method to join coincident subpaths e.g. if they could be a single subpath but instead are separate.
  3. (TBA) A method to convert long-thin closed subpaths (that look like strokes) to PathSegments.

In addition, the following additional functionality has been added to Subpath to support the fixup methods:

  • first_point and current_point
  • __lt__ function for sorting subpath objects

1. An method to close almost closed paths.

2. Add similar properties to Subpath as Path for `first_point` and `current_point` and a `__lt__` function for sorting subpath objects.
@Sophist-UK Sophist-UK marked this pull request as draft September 16, 2021 21:17
@tatarize
Copy link
Member

How is a subpath less than another subpath? Occurring earlier in the backing path? Fewer segments? Smaller area?

Modifying subpaths invalidates them. They are intended to be temporary windows into the path. It seems like these bits of functionality should be done on the Path object itself. Likely placed near the function direct_close() which has some limited utility to modify a path in a minor way to ensure some required constraints. There'd be some ability to add things like line_merge (https://vpype.readthedocs.io/en/stable/reference.html#linemerge) within certain tolerances or linesimplify (https://vpype.readthedocs.io/en/stable/reference.html#linesimplify), or even a linesort function directly into the code (minimize distance between subpaths). There are places where functions that alter the Path as a whole go, is typically in the Path code like approximate_arcs_with_cubics(). Though there are other things like #129 or #118 which seem a bit more interesting changes and somehow directly relevant. After all #118 would allow meerk40t/meerk40t#1 to be done.

@Sophist-UK
Copy link
Contributor Author

Sophist-UK commented Sep 17, 2021

A subpath is less than another subpath if it is an earlier subpath. This seemed to me to be intuitive because you can get a subpath by index, but apparently it isn't so intuitive. But if you don't like this I can code the sort key another way.

Closing almost closed subpaths is a Path method rather than a Subpath method. It does operate on the Path object - but it is the subpaths that need to be closed so it uses the Subpath objects because that is what they are for. I do appreciate that Subpaths get invalidated (unless you update them as you update Path). And you are right that my current code does not keep Subpaths in step (but there is no reason why I can't do that). It might be useful to have an invalidation flag - so you have an internal counter for segment changes on the Path object, and you store that counter against a Subpath object when it is created, and you can then check whether the Subpath is invalid or not. Alternatively, we could maintain a list of Subpaths that exist for a Path and update them whenever a Segment change is made so that Subpath's automatically stay in step (which might be rather neat).

I will take a look at vpype linemerge and see how I can reuse this (and improve if possible). I will also use the terminology for the close almost closed code.

vpype linesimplify is akin to Inkscape's Path Simplify. I don't see the relevance to MK, and is not on my list to code.

@Sophist-UK Sophist-UK closed this Jan 13, 2022
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