-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
New "smooth" and "orthogonal" drawing tools #198
Conversation
Nice! Will review ASAP, but might take a few days. As usual. Edit: @pascal-niklaus the commit seems empty. |
Yes, that's right. It for the moment is a placeholder because I would like to first agree on the syntax of the tool options. All the code exists and is functional, but the params are currently hardcoded in callback.c. I simply would like to avoid changing parser options several times if that can easily be avoided. |
OK, I'll answer ASAP, currently on the move. |
I pushed the current code for you to get an idea about it and to try it out if you want. To play with the two tools, just change
The code in |
b607e9f
to
4d58439
Compare
4d58439
to
459868b
Compare
Additional feature added: Smoothed and orthogonal curves can now be circular, i.e. the start and end points can "snap" together when they are close enough. The smoothing is then done in a "circular" fashion, and the same is true for the rounded corners. |
I went ahead and made the tools configurable. For example, like this:
Here, For the orthogonal pen, Let me know whether that syntax makes sense... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First review round done!
@pascal-niklaus looks good to me code-wise now, thanks for the good work! One more thing: can you please document the new tools in the README? |
@pascal-niklaus Thanks for the good work again! One more idea: why not add one demo gif to each tool in the README if its not too much work? The ones you created look pretty cool. |
I have implemented two new drawing tools.
smoothing: this tool allows smoothing of the often shaky hand-drawn lines.
orthogonal lines: this tool "snaps" to approximately horizontal and vertical direction and "fixes" the sections in between so that a continuous path results. Straight sections are optionally joined with a curved line with a certain radius. This tool is great to draw e.g. arrows connecting things.
Here is a demo:
Both tools in principle have adjustable parameter:
In both tools, the first step is a path simplification (fewer points) using the Douglas-Peucker algorithm. Here, the degree of "simplification" is set by a parameter indicating how many pixels a point that is removed can be away from the simplified curve.
Smoothing happens with centripetal Catmull-Rom-splines. Here, a parameter indicates how many intermediate points are inserted into the path to create the "curves". I currently have set this to 5, and I don't see much need to vary it.
For the orthogonal pen, an angular tolerance can be set within which the lines "snap" to perfectly horizontal or vertical direction, once a length threshold is exceeded. This guarantees that curves are preserved, even if a short section is H or V. The second option is the radius at which sections are joined. Segments have to be longer than twice this radius, otherwise no arc is inserted to join them to their neighbors.
I think some of the parameter should be settable by the user, because they (1) depend on the screen resolution (e.g. radii), and (2) the desired balance between "simplification" (allowing very fast drawing yet keeping a nice result) and preservation of details.
Before adding the tidied-up code to this PR, I would like to discuss the syntax for the config file. Many options seem possible, for example:
Or something like:
Or even some compact (but unintuitive) form like:
Of course, all other PEN options remain available (arrows at the ends, for example).
Both tools together are about 800 lines of code (including functions for debugging that I will remove), most of which is in an additional file
smooth.c
. There are very few changes inconfig.c
andcallbacks.c
.I really would not like to separate the tools into 2 PRs because this would be a lot of work and a lot of the code is shared.